diff options
Diffstat (limited to 'models/User.js')
-rw-r--r-- | models/User.js | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/models/User.js b/models/User.js index 63f2d4a..b3a3f1e 100644 --- a/models/User.js +++ b/models/User.js @@ -21,7 +21,7 @@ var mongoose = require('mongoose') var UserSchema = new Schema({ name: String, - email: String, + email: { type: String, unique: true }, username: String, provider: String, hashed_password: String, @@ -59,7 +59,7 @@ var validatePrecenceOf = function (value) { UserSchema.path('name').validate(function(name) { // if you're authenticated by any of the oauth strategies (facebook, twitter), don't validate - if(authTypes.indexOf(this.provider) !== -1) return true; + if(authTypes.indexOf(this.provider) !== -1 || this.status === 1) return true; return name.length; }, 'Name cannot be blank'); @@ -69,12 +69,12 @@ UserSchema.path('email').validate(function(email) { }, 'Email cannot be blank'); UserSchema.path('username').validate(function(username) { - if(authTypes.indexOf(this.provider) !== -1) return true; + if(authTypes.indexOf(this.provider) !== -1 || this.status === 1) return true; return username.length; }, 'Username cannot be blank'); UserSchema.path('hashed_password').validate(function(hashed_password) { - if(authTypes.indexOf(this.provider) !== -1) return true; + if(authTypes.indexOf(this.provider) !== -1 || this.status === 1) return true; return hashed_password.length; }, 'Password cannot be blank'); @@ -84,7 +84,7 @@ UserSchema.path('hashed_password').validate(function(hashed_password) { */ UserSchema.pre('save', function(next) { - if (!this.isNew) return next(); + if (!this.isNew || this.status === 1) return next(); if(!validatePrecenceOf(this.password) && authTypes.indexOf(this.provider) === -1) |