This commit is contained in:
Lukian LEIZOUR 2024-06-01 19:14:23 +02:00
parent 0bac40a72f
commit 8ace4a6356
6 changed files with 32 additions and 7 deletions

View file

@ -12,11 +12,11 @@ router.post('/', async (req, res) => {
const user = await getUser(username);
if (!user[0]) {
return res.status(500).send({error: "wrong login informations"});
return res.status(400).send({error: "wrong login informations"});
}
if (!(sha256(password) == user[0].password)) {
return res.status(500).send({error: "wrong login informations"});
return res.status(400).send({error: "wrong login informations"});
}
res.status(200).send({message: "connection successful", token: jwt.sign({username: username, expiration: 20000}, process.env.JWTSecret)});

View file

@ -9,13 +9,13 @@ router.post('/', async (req, res) => {
const {username, name, lastname, password} = req.body;
if (!username || !name || !lastname || !password) {
return res.status(500).send({error: "invalid request"});
return res.status(400).send({error: "invalid request"});
}
const user = await getUser(username);
if (user[0]) {
return res.status(500).send({error: "user already exist"});
return res.status(400).send({error: "user already exist"});
}
await addUser(username, name, lastname, sha256(password));

View file

@ -8,12 +8,14 @@ const router = express.Router();
router.post('/', async (req, res) => {
const {token} = req.body;
let user;
if (!token) {
return res.status(400).send({error: "invalid token"});
}
try {
user = jwt.verify(token, process.env.JWTSecret);
jwt.verify(token, process.env.JWTSecret);
} catch {
return res.status(500).send({error: "invalid token"});
return res.status(400).send({error: "invalid token"});
}
const games = await getGames();