Advertisement
Guest User

Untitled

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