diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index 1c57ad6e..6cc8b6c1 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -31,17 +31,26 @@ app.post('/users', async (req, res) => { try { // Check if required fields are present in the request body validateRequiredFields(req, ['username', 'password', 'profileImage']); + // Check if the password has at least 4 characters + if (req.body.password.length < 4) { + res.status(400).json({ error: "Password must be at least 4 characters long" }); + return; + } + if (req.body.username.length === 0) { + res.status(400).json({ error: "Username can't be empty" }); + return; + } + if (req.body.username.length > 20) { + res.status(400).json({ error: "Username can't have more than 20 characters" }); + return; + } // Check if the user already exists const existingUser = await User.findOne({ username: req.body.username.toString() }); if (existingUser) { res.status(400).json({ error: "User already exist" }); return; } - // Check if the password has at least 4 characters - if (req.body.password.length < 4) { - res.status(400).json({ error: "Password must be at least 4 characters long" }); - return; - } + // Encrypt the password before saving it const hashedPassword = await bcrypt.hash(req.body.password, 10); diff --git a/webapp/src/messages/messages_en.json b/webapp/src/messages/messages_en.json index 2a8e3241..f57c8a54 100644 --- a/webapp/src/messages/messages_en.json +++ b/webapp/src/messages/messages_en.json @@ -17,6 +17,8 @@ "Passwords do not match": "Passwords do not match", "Password must be at least 4 characters long": "Password must be at least 4 characters long", "User already exist": "User already exist", + "Username can't be empty": "Username can't be empty", + "Username can't have more than 20 characters": "Username can't have more than 20 characters", "menu": "Menu", "langen": "English", diff --git a/webapp/src/messages/messages_es.json b/webapp/src/messages/messages_es.json index 267e8b24..bd9d525d 100644 --- a/webapp/src/messages/messages_es.json +++ b/webapp/src/messages/messages_es.json @@ -17,6 +17,8 @@ "Passwords do not match": "Las contraseñas no coinciden", "Password must be at least 4 characters long": "La contraseña debe tener al menos 4 caracteres", "User already exist": "El usuario ya existe", + "Username can't be empty": "El nombre de usuario no puede estar vacío", + "Username can't have more than 20 characters": "El nombre de usuario no puede tener más de 20 caracteres", "menu": "Menú", "langen": "Inglés", diff --git a/webapp/src/messages/messages_fr.json b/webapp/src/messages/messages_fr.json index 8f168812..09bdc04a 100644 --- a/webapp/src/messages/messages_fr.json +++ b/webapp/src/messages/messages_fr.json @@ -17,6 +17,8 @@ "Passwords do not match": "Les mots de passe ne correspondent pas", "Password must be at least 4 characters long": "Le mot de passe doit comporter au moins 4 caractères", "User already exist": "L'utilisateur existe déjà", + "Username can't be empty": "Le nom d'utilisateur ne peut pas être vide", + "Username can't have more than 20 characters": "Le nom d'utilisateur ne peut pas comporter plus de 20 caractères", "menu": "Menu", "langen": "Anglais", diff --git a/webapp/src/messages/messages_it.json b/webapp/src/messages/messages_it.json index 345f7658..21931f18 100644 --- a/webapp/src/messages/messages_it.json +++ b/webapp/src/messages/messages_it.json @@ -18,6 +18,8 @@ "Passwords do not match": "Le password non corrispondono", "Password must be at least 4 characters long": "La password deve essere lunga almeno 4 caratteri", "User already exist": "L'utente esiste già", + "Username can't be empty": "Il nome utente non può essere vuoto", + "Username can't have more than 20 characters": "Il nome utente non può avere più di 20 caratteri", "menu": "Menu", "langen": "Inglese",