From ae6a68d85bb1fdec05ff82a4dfe5c737f06e8a73 Mon Sep 17 00:00:00 2001 From: SDE Date: Sun, 3 Dec 2023 17:43:01 +0300 Subject: [PATCH 1/3] 0.8.30 check password --- AuthApp/forms.py | 24 +++++++++--------------- AuthApp/js_views.py | 12 ++++++------ 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/AuthApp/forms.py b/AuthApp/forms.py index 3bb6697..a324d3a 100644 --- a/AuthApp/forms.py +++ b/AuthApp/forms.py @@ -30,21 +30,15 @@ class RegistrationForm(forms.Form): agreement = forms.BooleanField(initial=False, required=True) def clean(self): - pass - # cleaned_data = super().clean() - # for item in self.changed_data: - # if item in self.data: - # - # - # cc_myself = cleaned_data.get("cc_myself") - # subject = cleaned_data.get("subject") - # - # if cc_myself and subject: - # # Only do something if both fields are valid so far. - # if "help" not in subject: - # raise ValidationError( - # "Did not send for 'help' in the subject despite " "CC'ing yourself." - # ) + cleaned_data = super().clean() + if cleaned_data['confirm_password'] != cleaned_data['password']: + self.add_error("password", _('Пароль и подтверждение пароля не совпадают')) + self.add_error("confirm_password", _('Пароль и подтверждение пароля не совпадают')) + + users = User.objects.filter(email=cleaned_data['email']) + if users: + self.add_error('email', _("Пользователь с указанным email уже существует")) + diff --git a/AuthApp/js_views.py b/AuthApp/js_views.py index 639cb37..d769b82 100644 --- a/AuthApp/js_views.py +++ b/AuthApp/js_views.py @@ -393,12 +393,12 @@ def registration_ajax(request): html = render_to_string('forms/f_registration.html', Dict, request=request) return JsonResponse({'html': html}, status=400) - users = User.objects.filter(email=form.data['email']) - if users: - form.errors['email'] = _("Пользователь с указанным email уже существует") - Dict = {'form': form} - html = render_to_string('forms/f_registration.html', Dict, request=request) - return JsonResponse({'html': html}, status=400) + # users = User.objects.filter(email=form.data['email']) + # if users: + # form.errors['email'] = _("Пользователь с указанным email уже существует") + # Dict = {'form': form} + # html = render_to_string('forms/f_registration.html', Dict, request=request) + # return JsonResponse({'html': html}, status=400) user = User.objects.create_user(username=form.data['email'], email=form.data['email'], password=form.data['password']) # user = auth.authenticate(username=new_user_Dict['name'], password=new_user_Dict['pass']) From 20fb49b3e4c8e33716b0ccd0efc730d3a63cebf1 Mon Sep 17 00:00:00 2001 From: SDE Date: Sun, 3 Dec 2023 17:47:29 +0300 Subject: [PATCH 2/3] 0.8.30 fix registration form --- AuthApp/forms.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AuthApp/forms.py b/AuthApp/forms.py index a324d3a..b6665df 100644 --- a/AuthApp/forms.py +++ b/AuthApp/forms.py @@ -31,6 +31,9 @@ class RegistrationForm(forms.Form): def clean(self): cleaned_data = super().clean() + for name, val in cleaned_data.items(): + if not val: + self.add_error(name, _('Обязательное поле')) if cleaned_data['confirm_password'] != cleaned_data['password']: self.add_error("password", _('Пароль и подтверждение пароля не совпадают')) self.add_error("confirm_password", _('Пароль и подтверждение пароля не совпадают')) From 3469a3923c7aecdf0abc94f098996a11779ffcf6 Mon Sep 17 00:00:00 2001 From: SDE Date: Sun, 3 Dec 2023 18:07:39 +0300 Subject: [PATCH 3/3] 0.8.30 fix registration form --- AuthApp/forms.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/AuthApp/forms.py b/AuthApp/forms.py index b6665df..c66debf 100644 --- a/AuthApp/forms.py +++ b/AuthApp/forms.py @@ -31,16 +31,23 @@ class RegistrationForm(forms.Form): def clean(self): cleaned_data = super().clean() - for name, val in cleaned_data.items(): - if not val: - self.add_error(name, _('Обязательное поле')) - if cleaned_data['confirm_password'] != cleaned_data['password']: - self.add_error("password", _('Пароль и подтверждение пароля не совпадают')) - self.add_error("confirm_password", _('Пароль и подтверждение пароля не совпадают')) + i = 0 + names = list(cleaned_data.keys()) + while i < len(names): + # for name, val in cleaned_data.items(): + if not cleaned_data[names[i]]: + self.add_error(names[i], _('Обязательное поле')) + i += 1 - users = User.objects.filter(email=cleaned_data['email']) - if users: - self.add_error('email', _("Пользователь с указанным email уже существует")) + if cleaned_data and 'confirm_password' in cleaned_data and 'password' in cleaned_data: + if cleaned_data['confirm_password'] != cleaned_data['password']: + self.add_error("password", _('Пароль и подтверждение пароля не совпадают')) + self.add_error("confirm_password", _('Пароль и подтверждение пароля не совпадают')) + + if cleaned_data and 'email' in cleaned_data: + users = User.objects.filter(email=cleaned_data['email']) + if users: + self.add_error('email', _("Пользователь с указанным email уже существует"))