From 63f6eb3cd806739bf610de2a639060f87c3285d5 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 13 Aug 2025 22:26:19 +0200 Subject: [PATCH] email disposable domains --- rowers/forms.py | 8 ++++++++ rowers/tests/test_newusers.py | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/rowers/forms.py b/rowers/forms.py index aba62313..ad865dd6 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -1000,6 +1000,8 @@ class RegistrationFormTermsOfService(RegistrationForm): error_messages={'required': "You must agree to the terms to register"}) +DISPOSABLE_DOMAINS = ["powerscrews.com"] + class RegistrationFormUniqueEmail(RegistrationFormTermsOfService): """ Subclass of ``RegistrationFormTermsOfService`` which enforces uniqueness of @@ -1011,6 +1013,12 @@ class RegistrationFormUniqueEmail(RegistrationFormTermsOfService): Validate that the supplied email address is unique for the site. """ + + email = self.cleaned_data['email'] + domain = email.split('@')[-1].lower() + if domain in DISPOSABLE_DOMAINS: + raise ValidationError("Registration using this domain is not allowed") + if User.objects.filter(email__iexact=self.cleaned_data['email']): # pragma: no cover raise forms.ValidationError( "This email address is already in use. Please supply a different email address.") diff --git a/rowers/tests/test_newusers.py b/rowers/tests/test_newusers.py index 5a098885..138643cb 100644 --- a/rowers/tests/test_newusers.py +++ b/rowers/tests/test_newusers.py @@ -157,3 +157,25 @@ class NewUserRegistrationTest(TestCase): expected_url='/rowers/register/', status_code=302,target_status_code=200) + @patch('rowers.dataprep.workout_summary_to_df',side_effect=mock_workout_summaries) + def test_newuser_disposable(self,mock_workout_summaries): + form_data = { + 'first_name':'Jan', + 'last_name':'Roeiert', + 'email':'jan@powerscrews.com', + 'username':'janderoeiert', + 'password1':'Aapindewei2', + 'password2':'Aapindewei2', + 'url': '', + 'tos':True, + 'weightcategory':'hwt', + 'adaptiveclass': 'None', + 'sex':'male', + 'next':'/rowers/list-workouts', + 'birthdate':datetime.datetime(year=1970,month=4,day=2) + } + + form = RegistrationFormSex(form_data) + self.assertFalse(form.is_valid()) + +