Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
SOD/models/user.js

81 lines
2.1 KiB
JavaScript
Raw Normal View History

"use strict";
const {
Model
} = require("sequelize");
module.exports = (sequelize, DataTypes) => {
class User extends Model {
static associate(models) {
User.belongsTo(models.Department);
2020-08-18 17:54:00 +02:00
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: {
type: DataTypes.STRING,
allowNull: false,
validate: {
isEmail: true
2020-08-20 14:50:59 +02:00
},
unique: true
},
2020-08-25 15:40:06 +02:00
emailVerified : {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false
},
emailToken: {
type: DataTypes.STRING,
unique: true
},
firstName: {
type: DataTypes.STRING,
allowNull: false,
unique: "userFullName"
},
lastName: {
type: DataTypes.STRING,
allowNull: false,
unique: "userFullName"
},
passwordHash: {
type: DataTypes.STRING,
allowNull: false,
set(value) {
if (value)
this.setDataValue("passwordHash",
require("crypto").
createHash("sha256").
update(this.username + value).
digest("base64"));
}
},
2020-08-25 16:46:02 +02:00
passwordToken: {
type: DataTypes.STRING,
unique: true
},
passwordTokenDate: {
type: DataTypes.DATE
},
permissions: { // 1 = sandwich page, 2 = order page, 3 = admin
type: DataTypes.INTEGER,
defaultValue: 0,
allowNull: false
}
}, {
sequelize,
modelName: "User",
});
return User;
};