Progress in implementing passport
This commit is contained in:
45
api/models/User.js
Normal file
45
api/models/User.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* User
|
||||
*
|
||||
* @module :: Model
|
||||
* @description :: A short summary of how this model works and what it represents.
|
||||
* @docs :: http://sailsjs.org/#!documentation/models
|
||||
*/
|
||||
|
||||
var bcrypt = require('bcrypt');
|
||||
|
||||
module.exports = {
|
||||
|
||||
attributes: {
|
||||
username: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
unique: true
|
||||
},
|
||||
password: {
|
||||
type: 'string',
|
||||
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(null, user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user