aboutsummaryrefslogtreecommitdiff
path: root/src/server/authentication/models/user_model.ts
diff options
context:
space:
mode:
authorab <abdullah_ahmed@brown.edu>2019-04-19 17:06:56 -0400
committerab <abdullah_ahmed@brown.edu>2019-04-19 17:06:56 -0400
commitd77951f2f29b5b7b4869128116c3627d77e2c73b (patch)
tree81a0a02dc59af308ec322920a2060ac1b53d15f2 /src/server/authentication/models/user_model.ts
parentbe1976fb0ba33064978ee973993b3a2316cdf43c (diff)
parentecae4ae106be3e07471208cb93ec0965548d2d12 (diff)
Merge commit 'ecae4ae' into new_search
Diffstat (limited to 'src/server/authentication/models/user_model.ts')
-rw-r--r--src/server/authentication/models/user_model.ts20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/server/authentication/models/user_model.ts b/src/server/authentication/models/user_model.ts
index 1c6926517..ee85e1c05 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,7 @@ 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, cb);
};
userSchema.methods.comparePassword = comparePassword;