Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {required : true}
- {
- "error": "E_VALIDATION",
- "status": 400,
- "summary": "1 attribute is invalid",
- "model": "User",
- "invalidAttributes": {
- "encrPassword": [
- {
- "rule": "string",
- "message": "Value should be a string (instead of null, which is an object)"
- },
- {
- "rule": "required",
- "message": ""required" validation rule failed for input: nullnSpecifically, it threw an error. Details:n undefined"
- }
- ]
- }
- attributes: {
- fullname : {type : 'string'},
- username : {type : 'string', unique:true, required:true},
- encrPassword : {type : 'string'},
- },
- insert : function(req, cb){
- console.log('Insert ', req);
- if(typeof req.fullName == 'string' && typeof req.username == 'string'){
- User.findOne({username : req.username}).exec(function(err, res){
- if(!res){
- User.create(req).exec(function(err, resp){
- console.log('create', null, resp);
- if(err)
- cb(err);
- else cb(null, resp);
- });
- }
- else cb({message: 'already eists'})
- });
- }
- else cb({message: 'Bad Request'});
- },
- beforeCreate : function(req, next){
- console.log('In bcrypt');
- bcrypt.genSalt(10, function(err, salt){
- if(err) return next(err);
- bcrypt.hash(req.password, salt, function(err, hash){
- if(err) return next(err);
- req.encrPassword = hash;
- delete req.password;
- console.log('Leaving BCrypt');
- next();
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement