Skip to content

Commit

Permalink
Fix how we access needs_hashing prop in password field, fixes #4020
Browse files Browse the repository at this point in the history
  • Loading branch information
JedWatson committed Feb 23, 2017
1 parent 70c66e9 commit 9d235c2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions fields/types/password/PasswordType.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ password.prototype.addToSchema = function (schema) {
schema.path(this.path, _.defaults({
type: String,
set: function (newValue) {
this.set(needs_hashing, true);
this[needs_hashing] = true;
return newValue;
},
}, this.options));

schema.virtual(this.paths.hash).set(function (newValue) {
this.set(field.path, newValue);
this.set(needs_hashing, false);
this[needs_hashing] = false;
});

schema.pre('save', function (next) {
if (!this.isModified(field.path) || !this.get(needs_hashing)) {
if (!this.isModified(field.path) || !this[needs_hashing]) {
return next();
}
if (!this.get(field.path)) {
this.set(field.path, undefined);
this.set(needs_hashing, false);
this[needs_hashing] = false;
return next();
}
var item = this;
Expand All @@ -100,7 +100,7 @@ password.prototype.addToSchema = function (schema) {
item.set(field.path, hash);
// reset [needs_hashing] so that new values can't be hashed more than once
// (inherited models double up on pre save handlers for password fields)
item.set(needs_hashing, false);
item[needs_hashing] = false;
next();
});
});
Expand Down

0 comments on commit 9d235c2

Please sign in to comment.