2015-02-11 14:24:42 +01:00
|
|
|
"""
|
|
|
|
The CustomPermissionsUser users email as the identifier, but uses the normal
|
|
|
|
Django permissions model. This allows us to check that the PermissionsMixin
|
|
|
|
includes everything that is needed to interact with the ModelBackend.
|
|
|
|
"""
|
2024-01-26 12:45:07 +01:00
|
|
|
|
2015-02-11 14:24:42 +01:00
|
|
|
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
|
|
|
|
from django.db import models
|
|
|
|
|
2016-02-04 17:47:51 +01:00
|
|
|
from .custom_user import CustomUserManager, RemoveGroupsAndPermissions
|
|
|
|
|
2015-02-11 14:24:42 +01:00
|
|
|
|
|
|
|
class CustomPermissionsUserManager(CustomUserManager):
|
|
|
|
def create_superuser(self, email, password, date_of_birth):
|
|
|
|
u = self.create_user(email, password=password, date_of_birth=date_of_birth)
|
|
|
|
u.is_superuser = True
|
|
|
|
u.save(using=self._db)
|
|
|
|
return u
|
|
|
|
|
|
|
|
|
|
|
|
with RemoveGroupsAndPermissions():
|
2022-02-03 20:24:19 +01:00
|
|
|
|
2015-02-11 14:24:42 +01:00
|
|
|
class CustomPermissionsUser(AbstractBaseUser, PermissionsMixin):
|
|
|
|
email = models.EmailField(
|
|
|
|
verbose_name="email address", max_length=255, unique=True
|
|
|
|
)
|
|
|
|
date_of_birth = models.DateField()
|
|
|
|
|
|
|
|
custom_objects = CustomPermissionsUserManager()
|
|
|
|
|
|
|
|
USERNAME_FIELD = "email"
|
|
|
|
REQUIRED_FIELDS = ["date_of_birth"]
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.email
|