Commit 11e098fc authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Merge branch 'fix/two-registrations-one-email-address' into 'master'

Two registrations one email address

Closes #691

See merge request !950
parents 631b0c2c 7c8be8d5
......@@ -245,7 +245,9 @@ class Registration(Entry):
super().clean()
errors = {}
if get_user_model().objects.filter(email=self.email).exists():
if (get_user_model().objects.filter(email=self.email).exists() or
Registration.objects.filter(email=self.email)
.exclude(pk=self.pk).exists()):
errors.update({
'email': _('A user with that email address already exists. '
'Login using the existing account and renew the '
......
......@@ -97,8 +97,21 @@ class RegistrationTest(TestCase):
self.registration.clean()
def test_unique_email_user(self):
get_user_model().objects.create_user('johnnydoe',
'johndoe@example.com')
self.registration.clean()
user = get_user_model().objects.create_user('johnnydoe',
'johndoe@example.com')
with self.assertRaises(ValidationError):
self.registration.clean()
user.delete()
self.registration.clean()
Registration.objects.create(
first_name='John',
last_name='Doe',
birthday=timezone.now().replace(year=1990),
email='johndoe@example.com',
)
with self.assertRaises(ValidationError):
self.registration.clean()
......@@ -117,6 +130,18 @@ class RegistrationTest(TestCase):
with self.assertRaises(ValidationError):
self.registration.clean()
user.delete()
self.registration.clean()
Registration.objects.create(
first_name='John',
last_name='Doe',
birthday=timezone.now().replace(year=1990),
student_number='s1234567'
)
with self.assertRaises(ValidationError):
self.registration.clean()
def test_unique_username_user(self):
self.registration.username = 'johndoe'
self.registration.clean()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment