Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 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'}, // ==> this works
  25. // encrPassword : {type : 'string', required:true}, ==> this doesn't
  26. },
  27.  
  28. insert : function(req, cb){
  29. console.log('Insert ', req);
  30. if(typeof req.fullName == 'string' && typeof req.username == 'string'){
  31. User.findOne({username : req.username}).exec(function(err, res){
  32. if(!res){
  33. User.create(req).exec(function(err, resp){
  34. console.log('create', null, resp);
  35. if(err)
  36. cb(err);
  37. else cb(null, resp);
  38. });
  39. }
  40. else cb({message: 'already eists'})
  41. });
  42. }
  43. else cb({message: 'Bad Request'});
  44. },
  45.  
  46. beforeCreate : function(req, next){
  47. console.log('In bcrypt');
  48. bcrypt.genSalt(10, function(err, salt){
  49. if(err) return next(err);
  50. bcrypt.hash(req.password, salt, function(err, hash){
  51. if(err) return next(err);
  52. req.encrPassword = hash;
  53. delete req.password;
  54. console.log('Leaving BCrypt');
  55. next();
  56. });
  57. });
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement