Advertisement
Guest User

Untitled

a guest
Feb 21st, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. var jwthelper = require('../shared/jwthelper.js');
  2. var aud = "Custom";
  3. var currentRequest;
  4.  
  5. exports.post = function(request, response) {
  6. currentRequest = request;
  7. var postValues = currentRequest.body;
  8. if (postValues.members != null)
  9. postValues = postValues.members;
  10.  
  11. var accounts = currentRequest.service.tables.getTable('AccountData');
  12. var item = {
  13. password : postValues.password,
  14. email : postValues.email,
  15. dob : postValues.dob,
  16. username : '',
  17. privacyReceive: 'Just Friends',
  18. privacyShare: 'Just Friends'
  19. };
  20. if (item.password.length < 7) {
  21. response.send(200, { Status : 'FAIL', Error: 'Invalid password (at least 7 chars required)'});
  22. return;
  23. }
  24. accounts.where({ email : item.email}).read({
  25. success: function(results) {
  26. if (results.length > 0) {
  27. response.send(200, { Status : 'FAIL', Error: 'This email already exists'});
  28. return;
  29. }
  30. else {
  31. console.log("Creating account data");
  32. item.salt = jwthelper.createSalt();
  33. jwthelper.hash(item.password, item.salt, function(err, h) {
  34. item.password = h;
  35. item.status = 'NewAccount';
  36. item.createDate = new Date();
  37. item.updateDate = new Date();
  38.  
  39. accounts.insert(item, {
  40. success: function () {
  41. var userId = aud + ":" + item.id;
  42.  
  43. //update our record with the user id
  44. item.userId = userId;
  45. accounts.update(item);
  46.  
  47. // We don't want the salt or the password going back to the client
  48. delete item.password;
  49. delete item.salt;
  50. delete item.status;
  51.  
  52. item.token = jwthelper.zumoJwt(aud, userId, request.service.config.masterKey);
  53. item.Status = 'User registered';
  54. response.send(201, item);
  55. }
  56. });
  57. });
  58. }
  59. }
  60. });
  61. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement