Advertisement
Guest User

Untitled

a guest
May 21st, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. exports.login = function (req, res){
  2. User.findUser(req.body.username, function(err, user) {
  3. if (!err) {
  4. console.log(user);
  5. if (user === null){
  6. return res.send(Boom.forbidden("invalid username or password"));
  7. }
  8. if (req.body.password === Common.decrypt(user.password)) {
  9. if(!user.isVerified){
  10. return res.send(Boom.forbidden("Your email address is not verified. please verify your email address to proceed"));
  11. }
  12. else{
  13. var tokenData = {
  14. username: user.username,
  15. scope: [user.scope],
  16. id: user._id
  17. };
  18. var result = {
  19. username: user.username,
  20. scope: user.scope,
  21. token: Jwt.sign(tokenData, privateKey)
  22. };
  23.  
  24. return res.json(result);
  25. }
  26. } else{
  27. return res.send(Boom.forbidden("invalid username or password"));
  28. }
  29. } else {
  30. if (11000 === err.code || 11001 === err.code) {
  31. return res.send(Boom.forbidden("please provide another user email"));
  32. } else {
  33. console.error(err);
  34. return res.send(Boom.badImplementation(err));
  35. }
  36. }
  37. })
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement