forked from GithubBackups/healthchecks
Login form: rename the email box to "identity" to avoid some auto-signup bots
This commit is contained in:
parent
a58ce791c0
commit
4acd6a16e8
@ -13,10 +13,12 @@ class LowercaseEmailField(forms.EmailField):
|
|||||||
|
|
||||||
|
|
||||||
class EmailForm(forms.Form):
|
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):
|
def clean_identity(self):
|
||||||
v = self.cleaned_data["email"]
|
v = self.cleaned_data["identity"]
|
||||||
|
|
||||||
# If registration is not open then validate if an user
|
# If registration is not open then validate if an user
|
||||||
# account with this address exists-
|
# account with this address exists-
|
||||||
|
@ -10,7 +10,7 @@ from django.conf import settings
|
|||||||
class LoginTestCase(TestCase):
|
class LoginTestCase(TestCase):
|
||||||
|
|
||||||
def test_it_sends_link(self):
|
def test_it_sends_link(self):
|
||||||
form = {"email": "alice@example.org"}
|
form = {"identity": "alice@example.org"}
|
||||||
|
|
||||||
r = self.client.post("/accounts/login/", form)
|
r = self.client.post("/accounts/login/", form)
|
||||||
assert r.status_code == 302
|
assert r.status_code == 302
|
||||||
@ -34,17 +34,17 @@ class LoginTestCase(TestCase):
|
|||||||
|
|
||||||
@override_settings(REGISTRATION_OPEN=False)
|
@override_settings(REGISTRATION_OPEN=False)
|
||||||
def test_it_obeys_registration_open(self):
|
def test_it_obeys_registration_open(self):
|
||||||
form = {"email": "dan@example.org"}
|
form = {"identity": "dan@example.org"}
|
||||||
|
|
||||||
r = self.client.post("/accounts/login/", form)
|
r = self.client.post("/accounts/login/", form)
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
self.assertContains(r, "Incorrect email")
|
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 = User(username="alice", email="alice@example.org")
|
||||||
alice.save()
|
alice.save()
|
||||||
|
|
||||||
form = {"email": "ALICE@EXAMPLE.ORG"}
|
form = {"identity": "ALICE@EXAMPLE.ORG"}
|
||||||
|
|
||||||
r = self.client.post("/accounts/login/", form)
|
r = self.client.post("/accounts/login/", form)
|
||||||
assert r.status_code == 302
|
assert r.status_code == 302
|
||||||
|
@ -71,7 +71,7 @@ def login(request):
|
|||||||
else:
|
else:
|
||||||
magic_form = EmailForm(request.POST)
|
magic_form = EmailForm(request.POST)
|
||||||
if magic_form.is_valid():
|
if magic_form.is_valid():
|
||||||
email = magic_form.cleaned_data["email"]
|
email = magic_form.cleaned_data["identity"]
|
||||||
user = None
|
user = None
|
||||||
try:
|
try:
|
||||||
user = User.objects.get(email=email)
|
user = User.objects.get(email=email)
|
||||||
|
@ -18,16 +18,16 @@
|
|||||||
<form id="magic-link-form" method="post">
|
<form id="magic-link-form" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
{% if magic_form.email.errors %}
|
{% if magic_form.errors %}
|
||||||
<p class="text-danger">Incorrect email address.</p>
|
<p class="text-danger">Incorrect email address.</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>Enter your <strong>email address</strong>.</p>
|
<p>Enter your <strong>email address</strong>.</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="email"
|
||||||
class="form-control input-lg"
|
class="form-control input-lg"
|
||||||
name="email"
|
name="identity"
|
||||||
value="{{ magic_form.email.value|default:"" }}"
|
value="{{ magic_form.email.value|default:"" }}"
|
||||||
placeholder="you@example.org">
|
placeholder="you@example.org">
|
||||||
|
|
||||||
@ -53,7 +53,7 @@
|
|||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="action" value="login" />
|
<input type="hidden" name="action" value="login" />
|
||||||
|
|
||||||
{% if form.non_field_errors %}
|
{% if form.errors %}
|
||||||
<p class="text-danger">Incorrect email or password.</p>
|
<p class="text-danger">Incorrect email or password.</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>
|
<p>
|
||||||
@ -62,7 +62,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="email"
|
||||||
class="form-control input-lg"
|
class="form-control input-lg"
|
||||||
name="email"
|
name="email"
|
||||||
value="{{ form.email.value|default:"" }}"
|
value="{{ form.email.value|default:"" }}"
|
||||||
|
@ -138,7 +138,7 @@
|
|||||||
<input
|
<input
|
||||||
type="email"
|
type="email"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
name="email"
|
name="identity"
|
||||||
autocomplete="email"
|
autocomplete="email"
|
||||||
placeholder="Email">
|
placeholder="Email">
|
||||||
</div>
|
</div>
|
||||||
@ -456,7 +456,7 @@
|
|||||||
<input
|
<input
|
||||||
type="email"
|
type="email"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
name="email"
|
name="identity"
|
||||||
autocomplete="email"
|
autocomplete="email"
|
||||||
placeholder="Email">
|
placeholder="Email">
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user