Coverage for users/managers.py: 77%
20 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-10-10 18:02 -0500
« prev ^ index » next coverage.py v6.4.4, created at 2022-10-10 18:02 -0500
1from django.contrib.auth.models import BaseUserManager
4class UserManager(BaseUserManager):
5 """
6 Custom User Manager class for User model
7 """
8 use_in_migrations = True
10 def _create_user(self, email, password, **extra_fields):
11 """
12 Create and save a user with the given email, and password.
13 """
14 email = self.normalize_email(email)
15 user = self.model(email=email, **extra_fields)
16 user.set_password(password)
17 user.save(using=self._db)
18 return user
20 def create_user(self, email=None, password=None, **extra_fields):
21 """
22 Custom create user method
23 """
24 extra_fields['is_staff'] = False
25 extra_fields['is_superuser'] = False
26 return self._create_user(email, password, **extra_fields)
28 def create_superuser(self, email, password, **extra_fields):
29 """
30 Custom create superuser method
31 """
32 extra_fields['is_staff'] = True
33 extra_fields['is_superuser'] = True
34 return self._create_user(email, password, **extra_fields)
36 def create_user_without_password(self, email):
37 """
38 Define flow for creating user without a defined password,
39 for example when an employee registers a new user
40 """
41 user, _ = self.get_or_create(email=email)
42 return user