Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. * signup() {
  2. const name = this.request.body.name;
  3. const email = this.request.body.email;
  4. const password = this.request.body.password;
  5.  
  6. // validacions
  7.  
  8. try {
  9. const user = yield users.add({
  10. name, email, password,
  11. });
  12.  
  13. delete user.email;
  14. delete user.password;
  15.  
  16. this.body = user;
  17. this.status = 200;
  18. } catch (error) {
  19. this.errors.push(error);
  20. this.status = 401;
  21. }
  22. },
  23.  
  24. ///////
  25.  
  26. * add(params) {
  27. const user = params;
  28.  
  29. if (params.password) {
  30. const salt = yield bcrypt.genSalt(10);
  31. user.password = yield bcrypt.hash(params.password, salt);
  32. }
  33.  
  34. return yield knex('users').insert(user)
  35. .then(users => users.toJSON());
  36. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement