Fix admin/user login issues
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
maxPasswordTokenAgeInHours: 3,
|
||||
sendEmailDelayInSeconds: 3,
|
||||
supportEmail: 'support@kss.us.com',
|
||||
sendEmail: true
|
||||
sendEmail: true,
|
||||
appName: "Deighton AR Test",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
maxPasswordTokenAgeInHours: 3,
|
||||
sendEmailDelayInSeconds: 3,
|
||||
supportEmail: 'support@kss.us.com',
|
||||
sendEmail: true
|
||||
sendEmail: true,
|
||||
appName: "Deighton AR",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,22 +8,7 @@ import config from "config"
|
||||
import autobind from "autobind-decorator"
|
||||
import { PassThrough } from "stream"
|
||||
import { catchAll } from "."
|
||||
|
||||
function pipeToGridFS(readable, writeable) {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
readable.on("error", (error) => {
|
||||
reject(error)
|
||||
})
|
||||
writeable.on("error", (error) => {
|
||||
reject(error)
|
||||
})
|
||||
writeable.on("finish", (file) => {
|
||||
resolve(file)
|
||||
})
|
||||
})
|
||||
readable.pipe(writeable)
|
||||
return promise
|
||||
}
|
||||
import { pipeToPromise } from "../../util"
|
||||
|
||||
@autobind
|
||||
export class AssetRoutes {
|
||||
@@ -109,7 +94,7 @@ export class AssetRoutes {
|
||||
}
|
||||
|
||||
async beginAssetUpload(req, res, next) {
|
||||
const uploadId = this.db.newObjectId()
|
||||
const uploadId = this.db.newObjectId().toString()
|
||||
let {
|
||||
fileName,
|
||||
uploadSize,
|
||||
@@ -224,12 +209,12 @@ export class AssetRoutes {
|
||||
if (uploadedChunks >= uploadData.numberOfChunks) {
|
||||
let readable = redisReadStream(this.rs.client, uploadDataId)
|
||||
let writeable = this.db.gridfs.openUploadStreamWithId(
|
||||
uploadId,
|
||||
this.db.newObjectId(uploadId),
|
||||
uploadData.fileName,
|
||||
{ contentType: uploadData.contentType }
|
||||
)
|
||||
|
||||
const file = await pipeToGridFS(readable, writeable)
|
||||
const file = await pipeToPromise(readable, writeable)
|
||||
|
||||
await Promise.all([
|
||||
this.rs.del(uploadId),
|
||||
|
||||
@@ -25,6 +25,8 @@ export class AuthRoutes {
|
||||
this.sendEmailDelayInSeconds = config.get("email.sendEmailDelayInSeconds")
|
||||
this.supportEmail = config.get("email.supportEmail")
|
||||
this.sendEmail = config.get("email.sendEmail")
|
||||
this.appName = config.get("email.appName")
|
||||
this.emailServiceName = config.get("serviceName.email")
|
||||
app
|
||||
.route("/auth/login")
|
||||
// Used to login. Email must be confirmed.
|
||||
@@ -208,11 +210,12 @@ export class AuthRoutes {
|
||||
siteUrl.host
|
||||
}/confirm-email?email-token%3D${savedUser.emailToken.value}`,
|
||||
supportEmail: this.supportEmail,
|
||||
appName: this.appName,
|
||||
},
|
||||
})
|
||||
|
||||
if (this.sendEmail) {
|
||||
await this.mq.request("dar-email", "sendEmail", msgs)
|
||||
await this.mq.request(this.emailServiceName, "sendEmail", msgs)
|
||||
}
|
||||
|
||||
res.json({})
|
||||
@@ -393,10 +396,11 @@ export class AuthRoutes {
|
||||
siteUrl.host
|
||||
}/reset-password?password-token%3D${savedUser.passwordToken.value}`,
|
||||
supportEmail: this.supportEmail,
|
||||
appName: this.appName,
|
||||
},
|
||||
}
|
||||
if (this.sendEmail) {
|
||||
await this.mq.request("dar-email", "sendEmail", msg)
|
||||
await this.mq.request(this.emailServiceName, "sendEmail", msg)
|
||||
}
|
||||
|
||||
res.json({})
|
||||
|
||||
@@ -19,6 +19,8 @@ export class UserRoutes {
|
||||
this.ws = container.ws
|
||||
this.maxEmailTokenAgeInHours = config.get("email.maxEmailTokenAgeInHours")
|
||||
this.sendEmail = config.get("email.sendEmail")
|
||||
this.emailServiceName = config.get("serviceName.email")
|
||||
|
||||
app
|
||||
.route("/users")
|
||||
.get(
|
||||
@@ -164,7 +166,7 @@ export class UserRoutes {
|
||||
res.json(savedUser.toClient())
|
||||
|
||||
if (this.sendEmail) {
|
||||
await this.mq.request("dar-email", "sendEmail", msg)
|
||||
await this.mq.request(this.emailServiceName, "sendEmail", msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,7 +246,7 @@ export class UserRoutes {
|
||||
res.json({})
|
||||
|
||||
if (this.sendEmail) {
|
||||
await this.mq.request("dar-email", "sendEmail", msg)
|
||||
await this.mq.request(this.emailServiceName, "sendEmail", msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
39
server/src/util.js
Normal file
39
server/src/util.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import stream from "stream"
|
||||
|
||||
export function streamToBuffer(readable) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var chunks = []
|
||||
var writeable = new stream.Writable()
|
||||
|
||||
writeable._write = function(chunk, enc, done) {
|
||||
chunks.push(chunk)
|
||||
done()
|
||||
}
|
||||
|
||||
readable.on("end", function() {
|
||||
resolve(Buffer.concat(chunks))
|
||||
})
|
||||
|
||||
readable.on("error", (err) => {
|
||||
reject(err)
|
||||
})
|
||||
|
||||
readable.pipe(writeable)
|
||||
})
|
||||
}
|
||||
|
||||
export function pipeToPromise(readable, writeable) {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
readable.on("error", (error) => {
|
||||
reject(error)
|
||||
})
|
||||
writeable.on("error", (error) => {
|
||||
reject(error)
|
||||
})
|
||||
writeable.on("finish", (file) => {
|
||||
resolve(file)
|
||||
})
|
||||
})
|
||||
readable.pipe(writeable)
|
||||
return promise
|
||||
}
|
||||
Reference in New Issue
Block a user