Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. // load the things we need
  2. var mongoose = require('mongoose');
  3. var bcrypt = require('bcrypt');
  4.  
  5. // define the schema for our user model
  6. var userSchema = mongoose.Schema({
  7.  
  8. local: {
  9. email: String,
  10. password: String,
  11. },
  12. facebook: {
  13. id: String,
  14. token: String,
  15. email: String,
  16. name: String
  17. },
  18. twitter: {
  19. id: String,
  20. token: String,
  21. displayName: String,
  22. username: String
  23. },
  24. google: {
  25. id: String,
  26. token: String,
  27. email: String,
  28. name: String
  29. }
  30.  
  31. });
  32.  
  33. // methods ======================
  34. // generating a hash
  35. userSchema.methods.generateHash = function (password) {
  36. return bcrypt.hashSync(password, bcrypt.genSaltSync(8));
  37. };
  38.  
  39. // checking if password is valid
  40. userSchema.methods.validPassword = function (password) {
  41. return bcrypt.compareSync(password, this.local.password);
  42. };
  43.  
  44. // create the model for users and expose it to our app
  45. module.exports = mongoose.model('User', userSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement