Guest User

Untitled

a guest
Sep 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. // 1: The model schema.
  2. var modelDefinition = {
  3. username: {
  4. type: Sequelize.STRING,
  5. unique: true,
  6. allowNull: false
  7. },
  8.  
  9. password: {
  10. type: Sequelize.STRING,
  11. allowNull: false
  12. }
  13. };
  14.  
  15. // 2: The model options.
  16. var modelOptions = {
  17. instanceMethods: {
  18. comparePasswords: comparePasswords
  19. },
  20. hooks: {
  21. beforeValidate: hashPassword
  22. }
  23. };
  24.  
  25. // 3: Define the User model.
  26. var UserModel = db.define('user', modelDefinition, modelOptions);
  27.  
  28. // Compares two passwords. Will be available on an instance when retrieved.
  29. function comparePasswords(password, callback) {
  30. // TODO: Password comparison logic.
  31. }
  32.  
  33. // Hashes the password for a user object. Handled before the INSERT
  34. function hashPassword(user) {
  35. // TODO: Password hashing logic.
  36. }
Add Comment
Please, Sign In to add comment