Skip to content

Instantly share code, notes, and snippets.

@coderberry
Created July 29, 2014 14:44
Show Gist options
  • Select an option

  • Save coderberry/e7d1f9208ef55acddddd to your computer and use it in GitHub Desktop.

Select an option

Save coderberry/e7d1f9208ef55acddddd to your computer and use it in GitHub Desktop.
/**
* User.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
"use strict";
var bcrypt = require('bcrypt');
module.exports = {
schema: true,
attributes: {
firstName: { type: 'string', required: true },
lastName: { type: 'string', required: true },
email: { type: 'string', unique: true, required: true },
encryptedPassword: { type: 'string', required: true },
role: { type: 'integer', required: 'true' }
},
/**
* Before create callback.
*
* @param {sails.model.user} values
* @param {Function} next
*/
beforeCreate: function(values, next) {
console.log("PERFORMING BEFORE CREATE");
bcrypt.hash(values.password, 10, function(err, hash) {
if(err) return next(err);
values.encryptedPassword = hash;
next();
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment