_this.requireplyLogin(request, reply, function () { if (_.intersection(request.payload.user.roles, roles).length) { return reply.continue(); } else { return reply(Boom.forbidden('User is not authorized')); } });
// hashPassword(req.payload.password, (error, hash) => { // if (error){ // reply( Boom.badRequest(error)) // return // } // user.password = hash user.save((error, user) => { if (!error) { var tokenData = { username: user.username, scope: [user.scope], id: user._id } Common.sentMailVerificationLink(user, createToken(tokenData), (error) => { if (error) { reply(Boom.serverUnavailable('Try again in a few Hours')) return } reply({message: 'Please confirm your email id by clicking on link in email'}) }) }else { if (11000 === error.code || 11001 === error.code) { reply(Boom.forbidden('please provide another user email')) } else { console.log(error) reply(Boom.forbidden(error)) // HTTP 403 //why? } } })
User.findOne({ $or: [ { email: request.payload.email }, { username: request.payload.username } ] }, function (error, user) { if (!error) { if (user === null) { reply(Boom.forbidden('invalid username or email')) return } Common.sentMailForgotPassword(user, (error) => { if (error) { reply(Boom.serverUnavailable('Try again in a few Hours')) return } reply({message: 'password is sent to registered email'}) }) }else { console.error(error) reply(Boom.badImplementation(error)) } })
Jwt.verify(request.params.token, privateKey, function (error, decoded) { if (decoded === undefined) { reply(Boom.forbidden('invalid verification link')) return reply(Boom.forbidden('invalid verification link')) return reply(Boom.forbidden('invalid verification link')) return reply(Boom.forbidden('account is already verified')) return