12345678910111213141516171819202122232425 |
- from django.contrib.auth.base_user import BaseUserManager
- from django.utils.translation import gettext_lazy as _
- class UserManager(BaseUserManager):
- def create_user(self, firstname, lastname, email, phone_number, password, **other_fields):
-
- if not email:
- raise ValueError(_('You must provide an email address'))
- email = self.normalize_email(email)
- user = self.model(firstname=firstname, lastname=lastname, email=email, phone_number=phone_number, **other_fields)
- user.set_password(password)
- user.save()
- return user
- def create_superuser(self, firstname, lastname, email, phone_number, password, **other_fields):
- other_fields.setdefault('is_staff', True)
- other_fields.setdefault('is_superuser', True)
- other_fields.setdefault('is_active', True)
- if other_fields.get('is_staff') is not True:
- raise ValueError(_('Superuser must have is_staff=True.'))
- if other_fields.get('is_superuser') is not True:
- raise ValueError(_('Superuser must have is_superuser=True.'))
- return self.create_user(firstname, lastname, email, phone_number, password, **other_fields)
|