Advertisement
Guest User

Untitled

a guest
Apr 28th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. login(req, res) {
  2. if (!req.body.memail || !req.body.mpassword) {
  3. return res.status(404).send({
  4. message: 'Email and password can not be empty!',
  5. });
  6. } else {
  7. const email = req.body.memail;
  8. const password = crypto.createHash('md5').update(req.body.mpassword).digest("hex");
  9. const potentialUser = {
  10. where: {
  11. memail: email,
  12. mpassword: password
  13. },
  14. attributes: ['memail', 'muuid', 'cid']
  15. };
  16. Member.findOne(potentialUser)
  17. .then(user => {
  18. if(!user) {
  19. return res.status(404).send({
  20. message: 'fail',
  21. error: 'User not found. Authentication failed.'
  22. });
  23. }
  24. const token = jwt.sign({
  25. muuid: user.muuid,
  26. memail: user.memail,
  27. cid: user.cid
  28. },
  29. 'secret_key',
  30. {
  31. expiresIn :"2h"
  32. }
  33. )
  34. return res.status(200).send({ message: 'success', token: token});
  35.  
  36. })
  37. .catch((error) => res.status(400).send(error));
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement