User model cleanup
This commit is contained in:
@ -7,7 +7,7 @@ import { DataTypes, sequelize, encryptedFields } from '../sequelize';
|
|||||||
import { publicS3Endpoint, uploadToS3FromUrl } from '../utils/s3';
|
import { publicS3Endpoint, uploadToS3FromUrl } from '../utils/s3';
|
||||||
import { sendEmail } from '../mailer';
|
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(
|
const User = sequelize.define(
|
||||||
'user',
|
'user',
|
||||||
@ -24,8 +24,7 @@ const User = sequelize.define(
|
|||||||
password: DataTypes.VIRTUAL,
|
password: DataTypes.VIRTUAL,
|
||||||
passwordDigest: DataTypes.STRING,
|
passwordDigest: DataTypes.STRING,
|
||||||
isAdmin: DataTypes.BOOLEAN,
|
isAdmin: DataTypes.BOOLEAN,
|
||||||
slackAccessToken: encryptedFields.vault('slackAccessToken'),
|
service: { type: DataTypes.STRING, allowNull: true },
|
||||||
service: { type: DataTypes.STRING, allowNull: true, unique: true },
|
|
||||||
serviceId: { type: DataTypes.STRING, allowNull: true, unique: true },
|
serviceId: { type: DataTypes.STRING, allowNull: true, unique: true },
|
||||||
slackData: DataTypes.JSONB,
|
slackData: DataTypes.JSONB,
|
||||||
jwtSecret: encryptedFields.vault('jwtSecret'),
|
jwtSecret: encryptedFields.vault('jwtSecret'),
|
||||||
@ -91,6 +90,7 @@ const uploadAvatar = async model => {
|
|||||||
const setRandomJwtSecret = model => {
|
const setRandomJwtSecret = model => {
|
||||||
model.jwtSecret = crypto.randomBytes(64).toString('hex');
|
model.jwtSecret = crypto.randomBytes(64).toString('hex');
|
||||||
};
|
};
|
||||||
|
|
||||||
const hashPassword = model => {
|
const hashPassword = model => {
|
||||||
if (!model.password) {
|
if (!model.password) {
|
||||||
return null;
|
return null;
|
||||||
@ -108,6 +108,7 @@ const hashPassword = model => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
User.beforeCreate(hashPassword);
|
User.beforeCreate(hashPassword);
|
||||||
User.beforeUpdate(hashPassword);
|
User.beforeUpdate(hashPassword);
|
||||||
User.beforeSave(uploadAvatar);
|
User.beforeSave(uploadAvatar);
|
||||||
|
Reference in New Issue
Block a user