Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post('/authenticateAdmin',(req, res) => {
- console.log('går in i authenticateAdmin');
- let getMessage = function() {
- let loginmessage;
- // The 'authenticateAdmin' route is only supposed to check if the admin can login. (returns 200 or nothing?)
- // TODO: Check if the user actually exists instead of creating a new one
- let assistant = model.findAssistant(req.body.username);
- if (assistant === undefined) {
- console.log('This username does not exist.');
- loginmessage = 'This username does not exist.'
- return loginmessage;
- }
- else {
- console.log('user exists in the database.');
- //check if password is correct
- console.log(req.body.password);
- console.log(assistant.password);
- const checkPassword = async function() {
- console.log('inside function');
- const match = await bcrypt.compare(req.body.password, assistant.password);
- console.log('match inside checkpassword= '+match);
- if (match) {
- loginmessage = 'LOGIN OK'
- console.log('LOGIN OK');
- }
- else {
- console.log('wrong password.');
- loginmessage = 'Wrong password.'
- }
- return loginmessage;
- }
- checkPassword().then(loginmessage => {
- console.log('loginmessage inside then='+ loginmessage);
- console.log('går hit');
- return loginmessage;
- });
- }
- }
- let sendResponse = function(callback) {
- console.log('Inside sendresponse');
- res.status(200).json({ message: callback() });
- // console.log('LOGINMESSAGE IN SENDRESPONSE IS: ' + callback());
- }
- sendResponse(getMessage);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement