From 46d306fa1c8fe1a6515969989a5e66fa8c9481b0 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Fri, 8 Apr 2016 21:14:23 +0200 Subject: Authentication to JARR with email address or nickname. --- src/web/forms.py | 15 ++++++++++----- src/web/templates/login.html | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/web/forms.py b/src/web/forms.py index 9aca234d..97ca75b0 100644 --- a/src/web/forms.py +++ b/src/web/forms.py @@ -89,8 +89,10 @@ class SigninForm(RedirectForm): """ Sign in form (connection to jarr). """ - email = EmailField("Email", [validators.Length(min=6, max=35), - validators.Required(lazy_gettext("Please enter your email address."))]) + email_or_nickmane = TextField("Email or nickname", + [validators.Length(min=3, max=35), + validators.Required( + lazy_gettext("Please enter your email address or nickname."))]) password = PasswordField(lazy_gettext('Password'), [validators.Required(lazy_gettext("Please enter a password.")), validators.Length(min=6, max=100)]) @@ -104,13 +106,16 @@ class SigninForm(RedirectForm): validated = super().validate() ucontr = UserController() try: - user = ucontr.get(email=self.email.data) + user = ucontr.get(**{'__or__': + {'email': self.email_or_nickmane.data, + 'nickname': self.email_or_nickmane.data}}) except NotFound: - self.email.errors.append('Wrong login') + self.email_or_nickmane.errors.append( + 'Wrong email address or nickname') validated = False else: if not user.is_active: - self.email.errors.append('User is desactivated') + self.email_or_nickmane.errors.append('User is desactivated') validated = False if not ucontr.check_password(user, self.password.data): self.password.errors.append('Wrong password') diff --git a/src/web/templates/login.html b/src/web/templates/login.html index 70e01f9c..4bbb28f9 100644 --- a/src/web/templates/login.html +++ b/src/web/templates/login.html @@ -7,9 +7,9 @@ {{ form.hidden_tag() }}
- {{ form.email(class_="form-control", placeholder=_('Your email')) }} + {{ form.email_or_nickmane(class_="form-control", placeholder=_('Your email or nickname')) }}
- {% for message in form.email.errors %} + {% for message in form.email_or_nickmane.errors %} {% endfor %} -- cgit