From 3d7c43356070ba228b2cfc195ab0c71af7c27fcb Mon Sep 17 00:00:00 2001 From: Natallie M'bayo <66847588+NatallieMbayo@users.noreply.github.com> Date: Fri, 20 Nov 2020 23:04:53 -0500 Subject: [PATCH] Add files via upload --- post_model.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/post_model.js b/post_model.js index 793c2b1..d7cf6ab 100644 --- a/post_model.js +++ b/post_model.js @@ -1,4 +1,5 @@ -import { Sequelize } from '/index.js' +import { Sequelize } from '/index.js'; +const bcrypt = require('bcryptjs') //this should set up the user table module.exports = function (sequelize, DataTypes) { @@ -10,26 +11,31 @@ module.exports = function (sequelize, DataTypes) { primaryKey: true, autoIncrement: true }, - username: { + email: { type: sequelize.STRING, allowNull: false, unique: true, + validate: { + isEmail: true + } }, hashedPassword: { type: Sequelize.STRING(64), allowNull: false } }); - User.beforeCreate(user, options) => { - const salt = bcrypt.createSaltSync(); - user.password = bcrypt.hashSync(user.password, salt); - }; + User.addHook('beforeCreate', function (user) { + user.password = bcrypt.hashSync(user.password, bcrypt.genSaltSync(10), null) + }) + return User + } User.prototype.validPassword = function(password){ return bcrypt.compareSync(password, this.password) } // create all defined tables sequelize.sync() - .then(() => console.log('User table has been created')) - .catch(error => console.log('Error Ocurred', error)); + .then(() => console.log('User table has been created')) + .catch(error => console.log('Error Ocurred', error)); + }