Created
July 29, 2014 14:44
-
-
Save coderberry/e7d1f9208ef55acddddd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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