"use strict";
const {
Model
} = require("sequelize");
module.exports = (sequelize, DataTypes) => {
class User extends Model {
static associate(models) {
User.belongsTo(models.Department);
User.hasMany(models.Order);
}
checkPassword(password) {
return require("crypto")
.createHash("sha256")
.update(this.username + password)
.digest("base64") === this.passwordHash
User.init({
username: {
type: DataTypes.STRING,
primaryKey: true
},
email: {
allowNull: false,
validate: {
isEmail: true
unique: true
emailVerified : {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false
emailToken: {
firstName: {
unique: "userFullName"
lastName: {
passwordHash: {
set(value) {
if (value)
this.setDataValue("passwordHash",
require("crypto").
createHash("sha256").
update(this.username + value).
digest("base64"));
passwordToken: {
passwordTokenDate: {
type: DataTypes.DATE
permissions: { // 1 = sandwich page, 2 = order page, 3 = admin
type: DataTypes.INTEGER,
defaultValue: 0,
}, {
sequelize,
modelName: "User",
});
return User;
};