Skip to content

Instantly share code, notes, and snippets.

@gregbarcza
Last active January 2, 2016 22:59
Show Gist options
  • Save gregbarcza/8373276 to your computer and use it in GitHub Desktop.
Save gregbarcza/8373276 to your computer and use it in GitHub Desktop.
/**
* Users
*
* @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: {
/* e.g.
nickname: 'string'
*/
name:{
type: 'string',
},
email:{
type:'email',
required:true
},
username:{
type:'string',
required:true
},
password: {
type: 'string'
},
phone: {
type:'string',
required:true
},
isTaxis:{
type:'boolean',
defaultsTo:false
},
toJSON: function() {
var obj = this.toObject();
delete obj.password;
return obj;
}
},
beforeCreate: function(user, cb) {
var password=(Math.floor(Math.random()*9000) + 1000).toString();
console.log('%s jelszava: %d',user.email,password);
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(password, salt, function(err, hash) {
if (err) {
console.log(err);
cb(err);
}else{
user.password = hash;
cb(null, user);
}
});
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment