2016-05-31 14:37:42 -07:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var bcrypt = require('bcrypt-nodejs');
|
|
|
|
|
|
|
|
|
|
module.exports = function(sequelize, DataTypes) {
|
|
|
|
|
//The id field is auto added and made primary key.
|
|
|
|
|
return sequelize.define('User', {
|
|
|
|
|
login: {
|
|
|
|
|
type: DataTypes.STRING
|
|
|
|
|
},
|
|
|
|
|
password: {
|
|
|
|
|
type: DataTypes.STRING
|
2016-06-13 11:54:12 -07:00
|
|
|
},
|
|
|
|
|
admin: {
|
|
|
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
|
allowNull: false,
|
|
|
|
|
defaultValue: true
|
|
|
|
|
},
|
|
|
|
|
indexes: [
|
|
|
|
|
{
|
|
|
|
|
unique: true,
|
|
|
|
|
fields: ['login']
|
|
|
|
|
}
|
|
|
|
|
]
|
2016-05-31 14:37:42 -07:00
|
|
|
}, {
|
|
|
|
|
freezeTableName: true, // Model tableName will be the same as the model name
|
2016-06-13 11:54:12 -07:00
|
|
|
//paranoid: true, //Keep deleted data but flag it as deleted
|
|
|
|
|
comment: "A system user authorized to access and manipulate the application data.",
|
2016-05-31 14:37:42 -07:00
|
|
|
instanceMethods: {
|
|
|
|
|
generateHash: function(password) {
|
|
|
|
|
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
|
|
|
|
|
},
|
|
|
|
|
validPassword: function(password) {
|
|
|
|
|
return bcrypt.compareSync(password, this.password);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|