Skip to content

Commit

Permalink
auth ci
Browse files Browse the repository at this point in the history
  • Loading branch information
nitely committed Dec 2, 2018
1 parent 5288bca commit ebcb138
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions spirit/user/auth/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class RegistrationForm(CleanEmailMixin, forms.ModelForm):
label=_("Email confirmation"),
widget=forms.EmailInput,
max_length=254,
help_text=_("Enter the same email as above, for verification.")
)
help_text=_("Enter the same email as above, for verification."))
# todo: add password validator for Django 1.9
password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
honeypot = forms.CharField(label=_("Leave blank"), required=False)
Expand All @@ -45,10 +44,13 @@ def clean_honeypot(self):
def clean_username(self):
username = self.cleaned_data["username"]

is_taken = User.objects\
.filter(username=username)\
.exists()
if settings.ST_CASE_INSENSITIVE_USERNAMES:
username = username.lower()

is_taken = (
User.objects
.filter(username=username)
.exists())
if is_taken:
raise forms.ValidationError(_("The username is taken."))

Expand All @@ -63,8 +65,7 @@ def clean_email2(self):

if email and email != email2:
raise forms.ValidationError(
_("The two email fields didn't match.")
)
_("The two email fields didn't match."))

return email2

Expand Down Expand Up @@ -94,26 +95,28 @@ def _validate_username(self):
if not username:
return

is_found = User.objects\
.filter(username=username)\
.exists()
if settings.ST_CASE_INSENSITIVE_USERNAMES:
username = username.lower()

is_found = (
User.objects
.filter(username=username)
.exists())
if is_found:
return

if settings.ST_CASE_INSENSITIVE_EMAILS:
username = username.lower()

is_found_email = User.objects\
.filter(email=username)\
.exists()

is_found_email = (
User.objects
.filter(email=username)
.exists())
if is_found_email:
return

raise forms.ValidationError(
_("No account matches %(username)s.") % {'username': username}
)
_("No account matches %(username)s.") % {'username': username})

def clean(self):
self._validate_username()
Expand All @@ -130,18 +133,18 @@ def clean_email(self):
if settings.ST_CASE_INSENSITIVE_EMAILS:
email = email.lower()

is_existent = User.objects\
.filter(email=email)\
.exists()

is_existent = (
User.objects
.filter(email=email)
.exists())
if not is_existent:
raise forms.ValidationError(_("The provided email does not exists."))

self.user = User.objects\
.filter(email=email, st__is_verified=False)\
.order_by('-pk')\
.first()

self.user = (
User.objects
.filter(email=email, st__is_verified=False)
.order_by('-pk')
.first())
if not self.user:
raise forms.ValidationError(_("This account is verified, try logging-in."))

Expand Down

0 comments on commit ebcb138

Please sign in to comment.