Guest User

Untitled

a guest
Feb 6th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import mongoose, { Schema } from 'mongoose';
  2. import bcrypt from 'bcrypt';
  3.  
  4. const UserSchema = new mongoose.Schema({
  5. name: {type:String, required:true},
  6. email: {type: String, required:true},
  7. username: { type: String, required: true, unique: true },
  8. password: { type: String, required: true },
  9. profileimage: {type:Buffer, contentType: String },
  10. admin: {type:Boolean, default:false},
  11. Date_Created:{type: Date },
  12. is_active: { type: Boolean, default: false }
  13. });
  14.  
  15.  
  16. UserSchema.methods.generateHash = function(password) {
  17. return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
  18. };
  19.  
  20. // checking if password is valid
  21. UserSchema.methods.validPassword = function(password) {
  22. return bcrypt.compareSync(password, this.password);
  23. };
  24.  
  25.  
  26.  
  27.  
  28. module.exports = mongoose.model('User', UserSchema);
Add Comment
Please, Sign In to add comment