Solves User model validation bug

This solves the issue of the User model's pre('validate') method,
attempting to validate against a password that was not modified.

Adds the this.isModified('password') check to the condition.
This commit is contained in:
mleanos
2015-10-05 16:41:14 -07:00
parent 7a9ee53357
commit 288f0b4e63

View File

@@ -116,7 +116,7 @@ UserSchema.pre('save', function (next) {
* Hook a pre validate method to test the local password
*/
UserSchema.pre('validate', function (next) {
if (this.provider === 'local' && this.password) {
if (this.provider === 'local' && this.password && this.isModified('password')) {
var result = owasp.test(this.password);
if (result.errors.length) {
var error = result.errors.join(' ');