Skip to content

Commit

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

def create_user(self, email, password=None, **extra_fields):
if not email:
raise ValueError('User must have an email address.')
user = self.model(email=self.normalize_email(email), **extra_fields)
user.set_password(password)
user.save(using=self._db)
Expand Down
4 changes: 4 additions & 0 deletions app/core/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ def test_new_user_email_normalized(self):
for email, expected in sample_emails:
user = get_user_model().objects.create_user(email, 'sample123')
self.assertEqual(user.email, expected)

def test_new_user_without_email_raises_error(self):
with self.assertRaises(ValueError):
get_user_model().objects.create_user('', 'sample123')

0 comments on commit e46a7e5

Please sign in to comment.