Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ynr/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from allauth.account.forms import LoginForm, SignupForm
from django.forms import ValidationError


class CustomLoginForm(LoginForm):
Expand All @@ -15,3 +16,13 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for field in ("username", "email", "password1", "password2"):
del self.fields[field].widget.attrs["placeholder"]

def clean_email(self):
email = self.cleaned_data["email"]
prohibited_domains = [".gov", ".ac.uk"]
for domain in prohibited_domains:
if email.endswith(domain):
raise ValidationError(
"Please use a non-government or non-academic email address."
)
return email
20 changes: 20 additions & 0 deletions ynr/tests/test_signup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django_webtest import WebTest


class TestSignUpPage(WebTest):
def test_invalid_email(self):
response = self.app.get("/accounts/signup/")

self.assertEqual(response.status_code, 200)
# submit the form with an prohibited email domain
form = response.forms["signup_form"]
form["email"] = "[email protected]"
form["password1"] = "password"
form["password2"] = "password"
response = form.submit()
self.assertFormError(
response,
"form",
"email",
"Please use a non-government or non-academic email address.",
)
1 change: 0 additions & 1 deletion ynr/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.views.generic import TemplateView


from allauth.account.views import SignupView


Expand Down