Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. router.post('/authenticateAdmin',(req, res) => {
  2. console.log('går in i authenticateAdmin');
  3.  
  4. let getMessage = function() {
  5. let loginmessage;
  6. // The 'authenticateAdmin' route is only supposed to check if the admin can login. (returns 200 or nothing?)
  7. // TODO: Check if the user actually exists instead of creating a new one
  8. let assistant = model.findAssistant(req.body.username);
  9. if (assistant === undefined) {
  10. console.log('This username does not exist.');
  11. loginmessage = 'This username does not exist.'
  12. return loginmessage;
  13. }
  14. else {
  15. console.log('user exists in the database.');
  16. //check if password is correct
  17. console.log(req.body.password);
  18. console.log(assistant.password);
  19.  
  20. const checkPassword = async function() {
  21. console.log('inside function');
  22. const match = await bcrypt.compare(req.body.password, assistant.password);
  23. console.log('match inside checkpassword= '+match);
  24. if (match) {
  25. loginmessage = 'LOGIN OK'
  26. console.log('LOGIN OK');
  27. }
  28. else {
  29. console.log('wrong password.');
  30. loginmessage = 'Wrong password.'
  31. }
  32. return loginmessage;
  33. }
  34.  
  35. checkPassword().then(loginmessage => {
  36. console.log('loginmessage inside then='+ loginmessage);
  37. console.log('går hit');
  38. return loginmessage;
  39. });
  40. }
  41. }
  42.  
  43. let sendResponse = function(callback) {
  44. console.log('Inside sendresponse');
  45. res.status(200).json({ message: callback() });
  46. // console.log('LOGINMESSAGE IN SENDRESPONSE IS: ' + callback());
  47. }
  48.  
  49. sendResponse(getMessage);
  50. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement