Advertisement
Guest User

user.js

a guest
Oct 24th, 2016
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var mongoose = require('mongoose'),
  3.     bcrypt   = require('bcrypt-nodejs');
  4.  
  5. var userSchema = new mongoose.Schema({
  6.     username: { type: String, required: true, unique: true },
  7.     password: { type: String, required: true },
  8.     email:  String,
  9.     created_at: Date,
  10.     updated_at: Date,
  11.     admin: Boolean
  12. });
  13.  
  14. userSchema.methods.generateHash = function(password){
  15.     return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
  16. };
  17.  
  18. userSchema.methods.validPassword = function(password){
  19.     return bcrypt.compareSync(password, this.password);
  20. };
  21.  
  22. module.exports = mongoose.model('User', userSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement