Last active
January 2, 2016 22:59
-
-
Save gregbarcza/8373276 to your computer and use it in GitHub Desktop.
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
/** | |
* 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