- Added login method for users

This commit is contained in:
Alexis
2020-07-04 23:07:52 +02:00
parent 5d1b44cf6d
commit ba89dc8c5e
2 changed files with 80 additions and 18 deletions

View File

@@ -63,6 +63,30 @@ router.get('/:uuid/', async (req, res) => {
})
// LOG A USER ------------------
const logUser = (mail, password) => {
return Users.logUser(mail, password)
.catch(err => {
console.log(err)
throw err
})
}
router.post('/login', async (req, res) => {
logUser(req.body.mail, req.body.password)
.then(v => {
res.setHeader('Content-Type', 'application/json;charset=utf-8')
res.end(JSON.stringify(v))
})
.catch(err => {
res.status(err.code).send(JSON.stringify(
{
"error": err.message,
"code": err.code
})
)
})
})
// CREATE ONE ------------------
const addUser = (u) => {
return Users.addOne(u)