Files
PetitTeton/models/user.js
Wynne Crisman e82078174b Updated site to scale better on small screens; Added clearfix css; Updated shadow feature to use css shadows instead of js/images.
Added code to the admin part of the site - still non-functional.  Need to fix JSON streaming over HTTP such that native types (boolean, Date, int) are preserved for the DB;  Need to finish the restore functionality & the hide/show of the edit, delete, and restore buttons on each editor page.
2016-10-26 14:48:11 -07:00

53 lines
1.2 KiB
JavaScript

"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,
set: function(val) {
this.setDataValue('password', sequelize.models.User.generateHash(val));
}
},
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);
}
}
});
};