From 4c0e2cbdeda3735a4ebc829d97e3f122f7a2e685 Mon Sep 17 00:00:00 2001 From: stalker2106 Date: Fri, 25 Aug 2023 18:12:25 +0200 Subject: [PATCH] fixed login length, server deletion --- routes/player/createPlayer.js | 8 ++++++-- routes/server/deleteServer.js | 7 ++++--- web/register.html | 8 ++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/routes/player/createPlayer.js b/routes/player/createPlayer.js index 5d91e5e..71e43ad 100644 --- a/routes/player/createPlayer.js +++ b/routes/player/createPlayer.js @@ -18,8 +18,8 @@ module.exports = { } }, handler: async (app, req, res, next) => { - if (req.body.LENOM.length < 3 || !/^[a-zA-Z0-9_]*$/.test(req.body.LENOM)) { - res.status(500).send('Username must consist only of alphanumeric characters, and be at least 3 characters long') + if ((req.body.LENOM.length < 2 && req.body.LENOM.length > 15) || !/^[a-zA-Z0-9_]*$/.test(req.body.LENOM)) { + res.status(500).send('Username must consist only of alphanumeric characters, and be between 2 and 15 characters long') return } if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(req.body.LEMAIL)) { @@ -30,6 +30,10 @@ module.exports = { res.status(500).send('LESOFT must be 2') return } + if (req.body.LEPASS.length < 2 && req.body.LEPASS.length > 10) { + res.status(500).send('Password length should be between 2 and 10') + return + } const player = await app.db.models.Players.findOne({ where: { [Op.or]: { diff --git a/routes/server/deleteServer.js b/routes/server/deleteServer.js index 140d1a2..26b9559 100644 --- a/routes/server/deleteServer.js +++ b/routes/server/deleteServer.js @@ -14,12 +14,13 @@ module.exports = { } }, handler: (app, req, res, next) => { - const server = app.serverList[app.serverList.findIndex((serv) => serv.owner === parseInt(req.body.LENUM))] + const serverIndex = app.serverList.findIndex((serv) => serv.owner === parseInt(req.body.LENUM)) + const server = app.serverList[serverIndex] if (!server) { res.status(500).send({ error: 'Invalid SERVERID' }) } else { - app.serverList.delete(parseInt(req.body.LENUM)) - utils.logger('game', `Server ${server.name} created by ${server.owner} terminated`) + app.serverList.splice(serverIndex, 1) + utils.logger('game', `Deleted server ${server.name} created by ${server.owner}`) res.status(200).send() } next() diff --git a/web/register.html b/web/register.html index 3934c14..12e4be2 100644 --- a/web/register.html +++ b/web/register.html @@ -59,9 +59,9 @@

Register

warning.style.display = 'block' return; } - if (username.length < 3) { + if (username.length < 2 || username.length > 15) { const warning = document.getElementById('usernameWarning') - warning.innerText = 'Username must be of at least 3 characters' + warning.innerText = 'Username must be between 2 and 15 characters' warning.style.display = 'block' return; } @@ -75,9 +75,9 @@

Register

} const password = document.getElementById('password').value - if (password.length < 8) { + if (password.length < 2 || password.length > 10) { const warning = document.getElementById('passwordWarning') - warning.innerText = 'Password must be of at least 8 characters' + warning.innerText = 'Password must be between 2 and 10 characters' warning.style.display = 'block' return; }