Restoroo/core/managers.py
Kumi a38d324bdb Initial commit
Custom user model
Preparations for module/template discovery
2022-05-21 17:06:18 +02:00

42 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.contrib.auth.base_user import BaseUserManager
from django.utils.translation import gettext_lazy as _
class UserManager(BaseUserManager):
"""
Custom user manager for Restoroo
"""
def create_user(self, email: str, password: str, **extra_fields):
"""
Create new User object with given email and password
Args:
email (str): Email address to use for the User object must be unique
password (str): Password to use for the User object
"""
if not email:
raise ValueError(_("%{variable} must be set") %
{"variable": "email"})
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save()
return user
def create_superuser(self, email: str, password: str, **extra_fields):
"""
Create new User with is_superuser set to True
Args:
email (str): Email address to use for the User object must be unique
password (str): Password to use for the User object
"""
extra_fields["is_superuser"] = True
return self.create_user(email, password, **extra_fields)