diff options
author | Dennis Eriksen <dennis.se@gmail.com> | 2013-05-15 10:18:35 +0200 |
---|---|---|
committer | Dennis Eriksen <dennis.se@gmail.com> | 2013-05-15 10:18:35 +0200 |
commit | d2c168d5b029f09026752e9fe7cc8499ba44ee9c (patch) | |
tree | 08a7b347565e0a9be550958e0cd572869038da1a | |
parent | added method for retrieving user based on email (diff) | |
download | Divid-d2c168d5b029f09026752e9fe7cc8499ba44ee9c.tar.gz |
we don't want to require name field and such when the user is invited
-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) |