add: merged front with back
This commit is contained in:
parent
1832ed12ec
commit
48f50a1daa
42 changed files with 5458 additions and 20 deletions
|
@ -1,32 +0,0 @@
|
|||
const express = require('express');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const sha256 = require("sha256");
|
||||
|
||||
const { getConnection, getUser } = require("../../../libs/mysql");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
const {username, password} = req.body;
|
||||
|
||||
const connection = await getConnection();
|
||||
const user = await getUser(connection, username);
|
||||
|
||||
if (!user[0]) {
|
||||
return res.status(400).send({error: "wrong login informations"});
|
||||
}
|
||||
|
||||
if (!(sha256(password) == user[0].password)) {
|
||||
return res.status(400).send({error: "wrong login informations"});
|
||||
}
|
||||
|
||||
if (!user[0].verified) {
|
||||
return res.status(400).send({error: "you need to be verified to login"})
|
||||
}
|
||||
|
||||
const expiration = new Date().getTime() + 1000 * 60 * 60 * 24 * 7;
|
||||
|
||||
res.status(200).send({message: "connection successful", token: jwt.sign({user: {id: user[0].id, username: user[0].username, name: user[0].name, lastname: user[0].lastname, admin: user[0].admin}, expiration: expiration}, process.env.JWTSecret)});
|
||||
});
|
||||
|
||||
module.exports = router;
|
Loading…
Add table
Add a link
Reference in a new issue