Guest User

Untitled

a guest
Apr 12th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. signUp: function(req, cb) { //console.log("===========++++++++++++++++++++",req)
  2. Utils.async.waterfall([
  3.  
  4. function(callback) {
  5. Utils.universalFunctions.logger('In Step 1 of user creation')
  6. checkUserEmailExits(req, function(err, res) {
  7. if (err) {
  8. callback(err)
  9. } else {
  10. if (res) {
  11. callback(null, req)
  12. } else {
  13. callback({ status: "warning", message: 'Email id already registered with us' })
  14. }
  15. }
  16. })
  17.  
  18. },
  19. function(data,callback) {
  20. Utils.universalFunctions.logger('In Step 2 of user creation')
  21. checkUserNameExits(req, function(err, res) {
  22. if (err) {
  23. callback(err)
  24. } else {
  25. if (res) {
  26. callback(null, req)
  27. } else {
  28. callback({ status: "warning", message: 'Username already registered with us' })
  29. }
  30. }
  31. })
  32.  
  33. },
  34. function(request, callback) {
  35. Utils.universalFunctions.logger('In Step 3 of user creation')
  36. if (request) {
  37. var obj = {
  38. userName: req.userName,
  39. email: req.email,
  40. password: Utils.md5(req.password),
  41. device_type: req.device_type,
  42. device_token: req.device_token
  43. };
  44. userModel.Users(obj).save(function(err, res) {
  45. if (err) {
  46. callback(err);
  47. } else {
  48. req.userId = res._id
  49. //req.resemail=res.email
  50. callback(null, res)
  51. }
  52. })
  53. }
  54. },
  55. function(request, callback) {
  56. Utils.universalFunctions.logger('In Step 4 of user creation creating token and sending mail')
  57. sendVerificationEmail([request], function(err, res) {
  58. console.log(res)
  59. if (err) {
  60. callback(err)
  61. } else {
  62.  
  63. callback(null,res)
  64. }
  65. })
  66. },
  67. ], function(err, res) {
  68. if (err) {
  69. if (err.status == "warning") {
  70. cb(null, err)
  71. } else {
  72. cb(err)
  73. }
  74. } else {
  75. cb(null, res)
  76. }
  77. });
  78.  
  79. },
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. {
  87. method: 'POST',
  88. path: '/v1/Users/signUp',
  89. config: {
  90. description: 'API for user sign up on ravingfans',
  91. notes: 'API for user sign up on ravingfans',
  92. tags: ['api'],
  93. validate: {
  94. payload: {
  95. userName: Utils.Joi.string().required().regex(/^(?=.*[a-z])[a-zA-Z0-9,'. ]{3,50}$/).options({ language: { string: { regex: { base: 'must be valid and should be of minimum 3 characters' } } } }).label('userName'),
  96. email: Utils.Joi.string().email().lowercase().required().label('email'),
  97. password: Utils.Joi.string().required().regex(/[0-9a-zA-Z].{5,25}$/).options({ language: { string: { regex: { base: 'must be between 5 to 25 characters.' } } } }).label('password'),
  98. device_token: Utils.Joi.string().optional(),
  99. device_type: Utils.Joi.number().optional().default(1).valid(1, 2)
  100. },
  101. failAction: Utils.universalFunctions.failActionFunction
  102. }
  103. },
  104. handler: function(request, reply) {
  105. userService.signUp(request.payload, function(err, res) {
  106. console.log('----------------22222----------',err,res);
  107. if (err) {
  108. Utils.response.error(reply);
  109. } else {
  110.  
  111. if (res.status == "warning") {
  112. Utils.response.warning(reply, res.message);
  113. } else {
  114. Utils.response.success(reply, res.message,res.data);
  115. }
  116. }
  117. });
  118.  
  119.  
  120. }
  121. },
Add Comment
Please, Sign In to add comment