Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. {required : true}
  2.  
  3. {
  4. "error": "E_VALIDATION",
  5. "status": 400,
  6. "summary": "1 attribute is invalid",
  7. "model": "User",
  8. "invalidAttributes": {
  9. "encrPassword": [
  10. {
  11. "rule": "string",
  12. "message": "Value should be a string (instead of null, which is an object)"
  13. },
  14. {
  15. "rule": "required",
  16. "message": ""required" validation rule failed for input: nullnSpecifically, it threw an error. Details:n undefined"
  17. }
  18. ]
  19. }
  20.  
  21. attributes: {
  22. fullname : {type : 'string'},
  23. username : {type : 'string', unique:true, required:true},
  24. encrPassword : {type : 'string'},
  25. },
  26.  
  27. insert : function(req, cb){
  28. console.log('Insert ', req);
  29. if(typeof req.fullName == 'string' && typeof req.username == 'string'){
  30. User.findOne({username : req.username}).exec(function(err, res){
  31. if(!res){
  32. User.create(req).exec(function(err, resp){
  33. console.log('create', null, resp);
  34. if(err)
  35. cb(err);
  36. else cb(null, resp);
  37. });
  38. }
  39. else cb({message: 'already eists'})
  40. });
  41. }
  42. else cb({message: 'Bad Request'});
  43. },
  44.  
  45. beforeCreate : function(req, next){
  46. console.log('In bcrypt');
  47. bcrypt.genSalt(10, function(err, salt){
  48. if(err) return next(err);
  49. bcrypt.hash(req.password, salt, function(err, hash){
  50. if(err) return next(err);
  51. req.encrPassword = hash;
  52. delete req.password;
  53. console.log('Leaving BCrypt');
  54. next();
  55. });
  56. });
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement