From 6a58099c4110715b16fe29438d4aca83c2a7732a Mon Sep 17 00:00:00 2001 From: wlorenzetti Date: Thu, 9 Nov 2023 17:16:46 +0100 Subject: [PATCH] Add email exists check on recovery username form. --- g3w-admin/usersmanage/forms.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/g3w-admin/usersmanage/forms.py b/g3w-admin/usersmanage/forms.py index 6bb827967..5ca9161fd 100644 --- a/g3w-admin/usersmanage/forms.py +++ b/g3w-admin/usersmanage/forms.py @@ -909,7 +909,18 @@ def clean_email(self): class G3WUsernameRecoveryForm(G3WreCaptchaFormMixin, PasswordResetForm): - pass + + def clean_email(self): + """ + Email exists into db + + :return: Cleaned data email + """ + + if not User.objects.filter(email=self.cleaned_data['email']).exists(): + raise ValidationError(_('No user is available with this email.'), code='email_invalid') + + return self.cleaned_data['email']