Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. var mongoose = require('mongoose');
  2. var bcrypt = require('bcrypt-nodejs');
  3.  
  4. var userSchema = mongoose.Schema({
  5. local: {
  6. name: String,
  7. email: String,
  8. password: String,
  9. },
  10. facebook: {
  11. id: String,
  12. token: String,
  13. email: String,
  14. name: String,
  15. username: String,
  16. },
  17. twitter: {
  18. id: String,
  19. token: String,
  20. displayName: String,
  21. username: String,
  22. },
  23. google: {
  24. id: String,
  25. token: String,
  26. email: String,
  27. name: String,
  28. },
  29. });
  30.  
  31. userSchema.methods.generateHash = function(password) {
  32. return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
  33. };
  34.  
  35. userSchema.methods.validPassword = function(password) {
  36. return bcrypt.compareSync(password, this.local.password);
  37. };
  38.  
  39. module.exports = mongoose.model('User', userSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement