Advertisement
Guest User

Untitled

a guest
Aug 27th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. const passwordValidators = [
  2. {
  3. validator: passwordLengthChecker,
  4. message: 'Password must be at least 5 characters but no more than 40'
  5. },
  6. {
  7. validator:validPassword,
  8. message: 'Must have at least one uppercase, lowercase, special character, and number'
  9. }
  10. ];
  11.  
  12.  
  13. /* ========
  14. Schema for user
  15. ========= */
  16. const userSchema=new Schema({
  17. email: { type: String, required: true, unique: true, lowercase: true, validate: emailValidators},
  18. username: { type: String, required: true, unique: true, lowercase: true, validate: usernameValidators},
  19. password: { type: String, required: true,validate: passwordValidators},
  20. bio: { type:String,default:null},
  21. location: {type:String, default:null},
  22. gender: {type:String,default:null},
  23. birthday: { type:Date,default:null},
  24. img: { type:String, default:null}
  25. });
  26.  
  27.  
  28. // Middleware that encrypt password
  29. userSchema.pre('save',function(next){
  30. if(!this.isModified('password'))
  31. return next();
  32.  
  33. bcrypt.hash(this.password, null, null, (err,hash)=>{
  34. if(err) return next(err);
  35. this.password=hash;
  36. next();
  37. });
  38. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement