Guest User

Untitled

a guest
Dec 18th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. module.exports = function(sequelize, DataTypes) {
  2. var User = sequelize.define("User", {
  3.  
  4. email: {
  5. type: DataTypes.STRING,
  6. allowNull: false,
  7. unique: true,
  8. validate: {
  9. isEmail: true
  10. }
  11. },
  12. username: {
  13. type: DataTypes.STRING,
  14. allowNull: false,
  15. unique: true
  16. },
  17. password: {
  18. type: DataTypes.STRING,
  19. allowNull: false
  20. },
  21. profileImg: {
  22. type: DataTypes.STRING,
  23. defaultValue: "default.png"
  24. }
  25. });
  26.  
  27. User.associate = function(models) {
  28. User.hasMany(models.Post, {
  29. onDelete: "cascade"
  30. });
  31. };
  32.  
  33. User.prototype.validPassword = function(password) {
  34. return bcrypt.compareSync(password, this.password);
  35. };
  36.  
  37. User.hook("beforeCreate", function(user) {
  38. user.password = bcrypt.hashSync(user.password, bcrypt.genSaltSync(10), null);
  39. });
  40. return User;
  41. };
Add Comment
Please, Sign In to add comment