diff --git a/server/config/default-test.json5 b/server/config/default-test.json5 index 0b16943..3f44ead 100644 --- a/server/config/default-test.json5 +++ b/server/config/default-test.json5 @@ -22,6 +22,7 @@ maxPasswordTokenAgeInHours: 3, sendEmailDelayInSeconds: 3, supportEmail: 'support@kss.us.com', - sendEmail: true + sendEmail: true, + appName: "Deighton AR Test", } } diff --git a/server/config/default.json5 b/server/config/default.json5 index 88eeb72..a099a37 100644 --- a/server/config/default.json5 +++ b/server/config/default.json5 @@ -22,6 +22,7 @@ maxPasswordTokenAgeInHours: 3, sendEmailDelayInSeconds: 3, supportEmail: 'support@kss.us.com', - sendEmail: true + sendEmail: true, + appName: "Deighton AR", } } diff --git a/server/src/api/routes/AssetRoutes.js b/server/src/api/routes/AssetRoutes.js index c58ef6e..d31dde7 100644 --- a/server/src/api/routes/AssetRoutes.js +++ b/server/src/api/routes/AssetRoutes.js @@ -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), diff --git a/server/src/api/routes/AuthRoutes.js b/server/src/api/routes/AuthRoutes.js index b082b37..a76f378 100644 --- a/server/src/api/routes/AuthRoutes.js +++ b/server/src/api/routes/AuthRoutes.js @@ -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({}) diff --git a/server/src/api/routes/UserRoutes.js b/server/src/api/routes/UserRoutes.js index 5f7101d..6328342 100644 --- a/server/src/api/routes/UserRoutes.js +++ b/server/src/api/routes/UserRoutes.js @@ -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) } } } diff --git a/server/src/util.js b/server/src/util.js new file mode 100644 index 0000000..834cb39 --- /dev/null +++ b/server/src/util.js @@ -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 +} diff --git a/website/src/API.js b/website/src/API.js index c34ba85..56d463a 100644 --- a/website/src/API.js +++ b/website/src/API.js @@ -52,12 +52,12 @@ class API extends EventEmitter { localStorage.removeItem(authTokenKeyName) sessionStorage.removeItem(authTokenKeyName) this._token = null - this._user = {} + this._user = { loggedOut: true } this.socket = null this.emit("logout") }) } else { - this._user = {} + this._user = { loggedOut: true } } } @@ -229,7 +229,7 @@ class API extends EventEmitter { localStorage.removeItem(authTokenKeyName) sessionStorage.removeItem(authTokenKeyName) this._token = null - this._user = {} + this._user = { loggedOut: true } this.disconnectSocket() this.emit("logout") } diff --git a/website/src/App.js b/website/src/App.js index caafb26..1f8c9f7 100644 --- a/website/src/App.js +++ b/website/src/App.js @@ -2,6 +2,7 @@ import React, { Component } from "react" import { Login, Logout, + Parking, ResetPassword, ForgotPassword, ConfirmEmail, @@ -29,18 +30,38 @@ export class App extends Component { (
+ + )} + /> + ( + +
@@ -50,18 +71,30 @@ export class App extends Component { + - - - - - - + + + + + + + (