This repository has been archived on 2026-05-01. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
chatless/backend/service-authentication/checkLogin.js
2021-05-28 08:52:35 +02:00

21 lines
700 B
JavaScript

const {sendError, sendMessage} = require ("./message");
const auth = require ('./auth');
async function checkLogin (req,res) {
if (typeof req.body.login === 'undefined')
return sendError(res, 'Vous n\'avez pas envoyé le champ login');
if (typeof req.body.password === 'undefined')
return sendError(res, 'Vous n\'avez pas envoyé le champ password');
const result = await auth.authenticate(req, res);
if (result > 0){
return sendMessage(res, {
id: result,
username: req.body.login
});
}
else{
return sendError(res, 'Invalid username or password');
}
}
module.exports = checkLogin;