Files
PetitTeton/models/user.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

"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', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true
},
login: {
type: DataTypes.STRING
},
password: {
type: DataTypes.STRING
},
admin: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
}
}, {
indexes: [
{
unique: true,
fields: ['login']
}
],
freezeTableName: true, // Model tableName will be the same as the model name
//paranoid: true, //Keep deleted data but flag it as deleted
comment: "A system user authorized to access and manipulate the application data.",
classMethods: {
generateHash: function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
}
},
instanceMethods: {
generateHash: function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
},
validPassword: function(password) {
return bcrypt.compareSync(password, this.password);
}
}
});
};