From 874235eb0f730101196245afaba609726bd0936f Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 4 Jun 2018 15:08:29 -0400 Subject: [PATCH] User model cleanup --- server/models/User.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/models/User.js b/server/models/User.js index 117b33405..96bd49e8a 100644 --- a/server/models/User.js +++ b/server/models/User.js @@ -7,7 +7,7 @@ import { DataTypes, sequelize, encryptedFields } from '../sequelize'; import { publicS3Endpoint, uploadToS3FromUrl } from '../utils/s3'; import { sendEmail } from '../mailer'; -const BCRYPT_COST = process.env.NODE_ENV !== 'production' ? 4 : 12; +const BCRYPT_COST = process.env.NODE_ENV === 'production' ? 12 : 4; const User = sequelize.define( 'user', @@ -24,8 +24,7 @@ const User = sequelize.define( password: DataTypes.VIRTUAL, passwordDigest: DataTypes.STRING, isAdmin: DataTypes.BOOLEAN, - slackAccessToken: encryptedFields.vault('slackAccessToken'), - service: { type: DataTypes.STRING, allowNull: true, unique: true }, + service: { type: DataTypes.STRING, allowNull: true }, serviceId: { type: DataTypes.STRING, allowNull: true, unique: true }, slackData: DataTypes.JSONB, jwtSecret: encryptedFields.vault('jwtSecret'), @@ -91,6 +90,7 @@ const uploadAvatar = async model => { const setRandomJwtSecret = model => { model.jwtSecret = crypto.randomBytes(64).toString('hex'); }; + const hashPassword = model => { if (!model.password) { return null; @@ -108,6 +108,7 @@ const hashPassword = model => { }); }); }; + User.beforeCreate(hashPassword); User.beforeUpdate(hashPassword); User.beforeSave(uploadAvatar);