Files
PetitTeton/models/user.js
Wynne Crisman 0a7cff6672 Merged PetitTeton webapp with the inventory tracking app; Moved the database configuration out of git and added an example configuration; Added migrations to the mix so that we can easily update the production database and roll back changes to the database (from the command line install migrations [may not be necessary?]:
npm install -g sequelize-cli

To update the database after updating the app from git (on the command line in the webapp base directory):
sequelize db:migrate

To undo the last migrations:
sequelize db:migrate:undo
2016-06-13 11:54:12 -07:00

39 lines
912 B
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', {
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.",
instanceMethods: {
generateHash: function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
},
validPassword: function(password) {
return bcrypt.compareSync(password, this.password);
}
}
});
};