From 82fda1217cd67a346d468b893babd310bfda07a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Garc=C3=ADa?= Date: Thu, 17 Oct 2024 10:22:19 +0200 Subject: [PATCH] Avoid duplicate validation message when trying to register a user with existing email --- .../test/resources/org/fao/geonet/api/Messages.properties | 3 +-- .../resources/org/fao/geonet/api/Messages_fre.properties | 3 +-- .../api/users/validation/UserRegisterDtoValidator.java | 8 +++----- .../classes/org/fao/geonet/api/Messages.properties | 3 +-- .../classes/org/fao/geonet/api/Messages_fre.properties | 3 +-- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/core/src/test/resources/org/fao/geonet/api/Messages.properties b/core/src/test/resources/org/fao/geonet/api/Messages.properties index 4db47277a6b..823338a3a32 100644 --- a/core/src/test/resources/org/fao/geonet/api/Messages.properties +++ b/core/src/test/resources/org/fao/geonet/api/Messages.properties @@ -54,8 +54,7 @@ user_password_changed='%s' password was updated. user_password_notchanged=A problem occurred trying to change '%s' password. Contact the helpdesk. user_password_invalid_changekey='%s' is an invalid change key for '%s'. Change keys are only valid for one day. user_registered=User '%s' registered. -user_with_that_email_found=A user with this email or username already exists. -user_with_that_username_found=A user with this email or username already exists. +user_with_that_email_username_found=A user with this email or username already exists. register_email_admin_subject=%s / New account for %s as %s register_email_admin_message=Dear Admin,\n\ Newly registered user %s has requested %s access for %s.\n\ diff --git a/core/src/test/resources/org/fao/geonet/api/Messages_fre.properties b/core/src/test/resources/org/fao/geonet/api/Messages_fre.properties index fa2455ebbf2..d93b300f600 100644 --- a/core/src/test/resources/org/fao/geonet/api/Messages_fre.properties +++ b/core/src/test/resources/org/fao/geonet/api/Messages_fre.properties @@ -53,8 +53,7 @@ user_password_sent=Si l''utilisateur existe, vous recevrez un courriel contenant user_password_changed=Le mot de passe de %s a \u00E9t\u00E9 mis \u00E0 jour. user_password_notchanged=\u00C9chec lors du changement de mot de passe de %s. Contactez le support. user_password_invalid_changekey=%s est une cl\u00E9 invalide pour %s. Les cl\u00E9s ne sont valides que pendant une journ\u00E9e. -user_with_that_email_found=Un utilisateur avec cette adresse email ou ce nom d''utilisateur existe d\u00E9j\u00E0. -user_with_that_username_found=Un utilisateur avec cette adresse email ou ce nom d''utilisateur existe d\u00E9j\u00E0. +user_with_that_email_username_found=Un utilisateur avec cette adresse email ou ce nom d''utilisateur existe d\u00E9j\u00E0. register_email_admin_subject=%s / Cr\u00E9ation de compte pour %s en tant que %s register_email_admin_message=Cher administrateur,\n\ L'utilisateur %s vient de demander une cr\u00E9ation de compte pour %s.\n\ diff --git a/services/src/main/java/org/fao/geonet/api/users/validation/UserRegisterDtoValidator.java b/services/src/main/java/org/fao/geonet/api/users/validation/UserRegisterDtoValidator.java index 2ba53946b18..f22d7cc821f 100644 --- a/services/src/main/java/org/fao/geonet/api/users/validation/UserRegisterDtoValidator.java +++ b/services/src/main/java/org/fao/geonet/api/users/validation/UserRegisterDtoValidator.java @@ -60,12 +60,10 @@ public void validate(Object target, Errors errors) { } UserRepository userRepository = ApplicationContextHolder.get().getBean(UserRepository.class); - if (userRepository.findOneByEmail(userRegisterDto.getEmail()) != null) { - errors.rejectValue("", "user_with_that_email_found", "A user with this email or username already exists."); + if ((userRepository.findOneByEmail(userRegisterDto.getEmail()) != null) || + (!userRepository.findByUsernameIgnoreCase(userRegisterDto.getEmail()).isEmpty())) { + errors.rejectValue("", "user_with_that_email_username_found", "A user with this email or username already exists."); } - if (userRepository.findByUsernameIgnoreCase(userRegisterDto.getEmail()).size() != 0) { - errors.rejectValue("", "user_with_that_username_found", "A user with this email or username already exists."); - } } } diff --git a/web/src/main/webapp/WEB-INF/classes/org/fao/geonet/api/Messages.properties b/web/src/main/webapp/WEB-INF/classes/org/fao/geonet/api/Messages.properties index 6d945f9df7f..c3cb510a706 100644 --- a/web/src/main/webapp/WEB-INF/classes/org/fao/geonet/api/Messages.properties +++ b/web/src/main/webapp/WEB-INF/classes/org/fao/geonet/api/Messages.properties @@ -54,8 +54,7 @@ user_password_changed='%s' password was updated. user_password_notchanged=A problem occurred trying to change '%s' password. Contact the helpdesk. user_password_invalid_changekey='%s' is an invalid change key for '%s'. Change keys are only valid for one day. user_registered=User '%s' registered. -user_with_that_email_found=A user with this email or username already exists. -user_with_that_username_found=A user with this email or username already exists. +user_with_that_email_username_found=A user with this email or username already exists. register_email_admin_subject=%s / New account for %s as %s register_email_admin_message=Dear Admin,\n\ Newly registered user %s has requested %s access for %s.\n\ diff --git a/web/src/main/webapp/WEB-INF/classes/org/fao/geonet/api/Messages_fre.properties b/web/src/main/webapp/WEB-INF/classes/org/fao/geonet/api/Messages_fre.properties index b0180115f96..5650e16f1ca 100644 --- a/web/src/main/webapp/WEB-INF/classes/org/fao/geonet/api/Messages_fre.properties +++ b/web/src/main/webapp/WEB-INF/classes/org/fao/geonet/api/Messages_fre.properties @@ -53,8 +53,7 @@ user_password_sent=Si l''utilisateur existe, vous recevrez un courriel contenant user_password_changed=Le mot de passe de %s a \u00E9t\u00E9 mis \u00E0 jour. user_password_notchanged=\u00C9chec lors du changement de mot de passe de %s. Contactez le support. user_password_invalid_changekey=%s est une cl\u00E9 invalide pour %s. Les cl\u00E9s ne sont valides que pendant une journ\u00E9e. -user_with_that_email_found=Un utilisateur avec cette adresse email ou ce nom d''utilisateur existe d\u00E9j\u00E0. -user_with_that_username_found=Un utilisateur avec cette adresse email ou ce nom d''utilisateur existe d\u00E9j\u00E0. +user_with_that_email_username_found=Un utilisateur avec cette adresse email ou ce nom d''utilisateur existe d\u00E9j\u00E0. register_email_admin_subject=%s / Cr\u00E9ation de compte pour %s en tant que %s register_email_admin_message=Cher administrateur,\n\ L'utilisateur %s vient de demander une cr\u00E9ation de compte pour %s.\n\