Created
July 16, 2015 06:16
-
-
Save Shekharrajak/b2687a0f62ccfd1cb58e to your computer and use it in GitHub Desktop.
For the tutorial on medium.com : passportJS auth
This file contains 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 | |
*/ | |
var bcrypt = require('bcrypt'); | |
module.exports = { | |
attributes: { | |
email: { | |
type: 'email', | |
required: true, | |
unique: true | |
}, | |
password: { | |
type: 'string', | |
minLength: 6, | |
required: true | |
}, | |
toJSON: function() { | |
var obj = this.toObject(); | |
delete obj.password; | |
return obj; | |
} | |
}, | |
beforeCreate: function(user, cb) { | |
bcrypt.genSalt(10, function(err, salt) { | |
bcrypt.hash(user.password, salt, function(err, hash) { | |
if (err) { | |
console.log(err); | |
cb(err); | |
} else { | |
user.password = hash; | |
cb(); | |
} | |
}); | |
}); | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment