Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- signUp: function(req, cb) { //console.log("===========++++++++++++++++++++",req)
- Utils.async.waterfall([
- function(callback) {
- Utils.universalFunctions.logger('In Step 1 of user creation')
- checkUserEmailExits(req, function(err, res) {
- if (err) {
- callback(err)
- } else {
- if (res) {
- callback(null, req)
- } else {
- callback({ status: "warning", message: 'Email id already registered with us' })
- }
- }
- })
- },
- function(data,callback) {
- Utils.universalFunctions.logger('In Step 2 of user creation')
- checkUserNameExits(req, function(err, res) {
- if (err) {
- callback(err)
- } else {
- if (res) {
- callback(null, req)
- } else {
- callback({ status: "warning", message: 'Username already registered with us' })
- }
- }
- })
- },
- function(request, callback) {
- Utils.universalFunctions.logger('In Step 3 of user creation')
- if (request) {
- var obj = {
- userName: req.userName,
- email: req.email,
- password: Utils.md5(req.password),
- device_type: req.device_type,
- device_token: req.device_token
- };
- userModel.Users(obj).save(function(err, res) {
- if (err) {
- callback(err);
- } else {
- req.userId = res._id
- //req.resemail=res.email
- callback(null, res)
- }
- })
- }
- },
- function(request, callback) {
- Utils.universalFunctions.logger('In Step 4 of user creation creating token and sending mail')
- sendVerificationEmail([request], function(err, res) {
- console.log(res)
- if (err) {
- callback(err)
- } else {
- callback(null,res)
- }
- })
- },
- ], function(err, res) {
- if (err) {
- if (err.status == "warning") {
- cb(null, err)
- } else {
- cb(err)
- }
- } else {
- cb(null, res)
- }
- });
- },
- {
- method: 'POST',
- path: '/v1/Users/signUp',
- config: {
- description: 'API for user sign up on ravingfans',
- notes: 'API for user sign up on ravingfans',
- tags: ['api'],
- validate: {
- payload: {
- 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'),
- email: Utils.Joi.string().email().lowercase().required().label('email'),
- 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'),
- device_token: Utils.Joi.string().optional(),
- device_type: Utils.Joi.number().optional().default(1).valid(1, 2)
- },
- failAction: Utils.universalFunctions.failActionFunction
- }
- },
- handler: function(request, reply) {
- userService.signUp(request.payload, function(err, res) {
- console.log('----------------22222----------',err,res);
- if (err) {
- Utils.response.error(reply);
- } else {
- if (res.status == "warning") {
- Utils.response.warning(reply, res.message);
- } else {
- Utils.response.success(reply, res.message,res.data);
- }
- }
- });
- }
- },
Add Comment
Please, Sign In to add comment