From 4acd6a16e8f3be2bde7244f2b2a5dd2bbf216a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Wed, 10 Oct 2018 09:53:42 +0300 Subject: [PATCH] Login form: rename the email box to "identity" to avoid some auto-signup bots --- hc/accounts/forms.py | 8 +++++--- hc/accounts/tests/test_login.py | 8 ++++---- hc/accounts/views.py | 2 +- templates/accounts/login.html | 10 +++++----- templates/front/welcome.html | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/hc/accounts/forms.py b/hc/accounts/forms.py index a1765fa2..ab389830 100644 --- a/hc/accounts/forms.py +++ b/hc/accounts/forms.py @@ -13,10 +13,12 @@ class LowercaseEmailField(forms.EmailField): class EmailForm(forms.Form): - email = LowercaseEmailField() + # Call it "identity" instead of "email" + # to avoid some of the dumber bots + identity = LowercaseEmailField() - def clean_email(self): - v = self.cleaned_data["email"] + def clean_identity(self): + v = self.cleaned_data["identity"] # If registration is not open then validate if an user # account with this address exists- diff --git a/hc/accounts/tests/test_login.py b/hc/accounts/tests/test_login.py index a2a7b088..0d640dbe 100644 --- a/hc/accounts/tests/test_login.py +++ b/hc/accounts/tests/test_login.py @@ -10,7 +10,7 @@ from django.conf import settings class LoginTestCase(TestCase): def test_it_sends_link(self): - form = {"email": "alice@example.org"} + form = {"identity": "alice@example.org"} r = self.client.post("/accounts/login/", form) assert r.status_code == 302 @@ -34,17 +34,17 @@ class LoginTestCase(TestCase): @override_settings(REGISTRATION_OPEN=False) def test_it_obeys_registration_open(self): - form = {"email": "dan@example.org"} + form = {"identity": "dan@example.org"} r = self.client.post("/accounts/login/", form) assert r.status_code == 200 self.assertContains(r, "Incorrect email") - def test_it_ignores_ces(self): + def test_it_ignores_case(self): alice = User(username="alice", email="alice@example.org") alice.save() - form = {"email": "ALICE@EXAMPLE.ORG"} + form = {"identity": "ALICE@EXAMPLE.ORG"} r = self.client.post("/accounts/login/", form) assert r.status_code == 302 diff --git a/hc/accounts/views.py b/hc/accounts/views.py index a88d5722..e85cd9a4 100644 --- a/hc/accounts/views.py +++ b/hc/accounts/views.py @@ -71,7 +71,7 @@ def login(request): else: magic_form = EmailForm(request.POST) if magic_form.is_valid(): - email = magic_form.cleaned_data["email"] + email = magic_form.cleaned_data["identity"] user = None try: user = User.objects.get(email=email) diff --git a/templates/accounts/login.html b/templates/accounts/login.html index 474919f6..edc3a766 100644 --- a/templates/accounts/login.html +++ b/templates/accounts/login.html @@ -18,16 +18,16 @@