Skip to content

Commit

Permalink
normalize email address
Browse files Browse the repository at this point in the history
  • Loading branch information
ytliuSVN committed Nov 4, 2024
1 parent 7bf9717 commit 2c7ae13
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UserManager(BaseUserManager):
"""Manager for users."""

def create_user(self, email, password=None, **extra_fields):
user = self.model(email=email, **extra_fields)
user = self.model(email=self.normalize_email(email), **extra_fields)
user.set_password(password)
user.save(using=self._db)

Expand Down
11 changes: 11 additions & 0 deletions app/core/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ def test_create_user_with_email_successful(self):

self.assertEqual(user.email, email)
self.assertTrue(user.check_password(password))

def test_new_user_email_normalized(self):
sample_emails = [
['[email protected]', '[email protected]'],
['[email protected]', '[email protected]'],
['[email protected]', '[email protected]'],
['[email protected]', '[email protected]'],
]
for email, expected in sample_emails:
user = get_user_model().objects.create_user(email, 'sample123')
self.assertEqual(user.email, expected)

0 comments on commit 2c7ae13

Please sign in to comment.