aboutsummaryrefslogtreecommitdiff
path: root/src/server/authentication/models/user_model.ts
diff options
context:
space:
mode:
authorlaurawilsonri <laura_wilson@brown.edu>2019-04-15 20:20:46 -0400
committerlaurawilsonri <laura_wilson@brown.edu>2019-04-15 20:20:46 -0400
commitb7a766aa5d53686e032b34d7213ad543108f12c3 (patch)
treed71854e091fa24997a30856d9ac9c937a6cd45d2 /src/server/authentication/models/user_model.ts
parent8b1026d357dd40fc4a00010739d99ffc9db08641 (diff)
parentff6ba4107aa33e021803399180b0d2844fc19d84 (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into richTextEditor
Diffstat (limited to 'src/server/authentication/models/user_model.ts')
-rw-r--r--src/server/authentication/models/user_model.ts21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/server/authentication/models/user_model.ts b/src/server/authentication/models/user_model.ts
index 1c6926517..d5c84c311 100644
--- a/src/server/authentication/models/user_model.ts
+++ b/src/server/authentication/models/user_model.ts
@@ -18,8 +18,8 @@ mongoose.connection.on('disconnected', function () {
export type DashUserModel = mongoose.Document & {
email: string,
password: string,
- passwordResetToken: string | undefined,
- passwordResetExpires: Date | undefined,
+ passwordResetToken?: string,
+ passwordResetExpires?: Date,
userDocumentId: string;
@@ -67,11 +67,17 @@ const userSchema = new mongoose.Schema({
*/
userSchema.pre("save", function save(next) {
const user = this as DashUserModel;
- if (!user.isModified("password")) { return next(); }
+ if (!user.isModified("password")) {
+ return next();
+ }
bcrypt.genSalt(10, (err, salt) => {
- if (err) { return next(err); }
+ if (err) {
+ return next(err);
+ }
bcrypt.hash(user.password, salt, () => void {}, (err: mongoose.Error, hash) => {
- if (err) { return next(err); }
+ if (err) {
+ return next(err);
+ }
user.password = hash;
next();
});
@@ -79,9 +85,8 @@ userSchema.pre("save", function save(next) {
});
const comparePassword: comparePasswordFunction = function (this: DashUserModel, candidatePassword, cb) {
- bcrypt.compare(candidatePassword, this.password, (err: mongoose.Error, isMatch: boolean) => {
- cb(err, isMatch);
- });
+ bcrypt.compare(candidatePassword, this.password, (err: mongoose.Error, isMatch: boolean) =>
+ cb(err, isMatch));
};
userSchema.methods.comparePassword = comparePassword;