Fix admin/user login issues

This commit is contained in:
John Lyon-Smith
2018-05-25 10:16:28 -07:00
parent a33ca57d58
commit 587052a509
22 changed files with 255 additions and 92 deletions

View File

@@ -22,6 +22,7 @@
maxPasswordTokenAgeInHours: 3,
sendEmailDelayInSeconds: 3,
supportEmail: 'support@kss.us.com',
sendEmail: true
sendEmail: true,
appName: "Deighton AR Test",
}
}

View File

@@ -22,6 +22,7 @@
maxPasswordTokenAgeInHours: 3,
sendEmailDelayInSeconds: 3,
supportEmail: 'support@kss.us.com',
sendEmail: true
sendEmail: true,
appName: "Deighton AR",
}
}

View File

@@ -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),

View File

@@ -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({})

View File

@@ -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
View 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
}