mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #29628 -- Made createsuperuser validate password against username and required fields.
This commit is contained in:
committed by
Tim Graham
parent
f1fbef6cd1
commit
793e9bb35a
@@ -9,7 +9,7 @@ from django.db import models
|
||||
# that every user provide a date of birth. This lets us test
|
||||
# changes in username datatype, and non-text required fields.
|
||||
class CustomUserManager(BaseUserManager):
|
||||
def create_user(self, email, date_of_birth, password=None):
|
||||
def create_user(self, email, date_of_birth, password=None, **fields):
|
||||
"""
|
||||
Creates and saves a User with the given email and password.
|
||||
"""
|
||||
@@ -19,14 +19,15 @@ class CustomUserManager(BaseUserManager):
|
||||
user = self.model(
|
||||
email=self.normalize_email(email),
|
||||
date_of_birth=date_of_birth,
|
||||
**fields
|
||||
)
|
||||
|
||||
user.set_password(password)
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
def create_superuser(self, email, password, date_of_birth):
|
||||
u = self.create_user(email, password=password, date_of_birth=date_of_birth)
|
||||
def create_superuser(self, email, password, date_of_birth, **fields):
|
||||
u = self.create_user(email, password=password, date_of_birth=date_of_birth, **fields)
|
||||
u.is_admin = True
|
||||
u.save(using=self._db)
|
||||
return u
|
||||
@@ -37,11 +38,12 @@ class CustomUser(AbstractBaseUser):
|
||||
is_active = models.BooleanField(default=True)
|
||||
is_admin = models.BooleanField(default=False)
|
||||
date_of_birth = models.DateField()
|
||||
first_name = models.CharField(max_length=50)
|
||||
|
||||
custom_objects = CustomUserManager()
|
||||
|
||||
USERNAME_FIELD = 'email'
|
||||
REQUIRED_FIELDS = ['date_of_birth']
|
||||
REQUIRED_FIELDS = ['date_of_birth', 'first_name']
|
||||
|
||||
def __str__(self):
|
||||
return self.email
|
||||
|
||||
Reference in New Issue
Block a user