Restoroo/core/managers.py

43 lines
1.2 KiB
Python
Raw Permalink Normal View History

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)