Coverage for backend/authentication/user/models.py: 61%
38 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-11-06 23:27 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-11-06 23:27 +0000
1from django.db import models
2from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin, AnonymousUser
5# Create your models here.
7class UserManager(BaseUserManager):
8 def create_user(self, username, password=None, **kwargs):
9 """Create and return a `User` with a phone number, username and password."""
10 if username is None: 10 ↛ 11line 10 didn't jump to line 11 because the condition on line 10 was never true
11 raise TypeError('Users must have a username.')
13 user = self.model(username=username)
14 user.set_password(password)
15 user.save(using=self._db)
17 return user
19 def create_superuser(self, username, password):
20 """
21 Create and return a `User` with superuser (admin) permissions.
22 """
23 if password is None:
24 raise TypeError('Superusers must have a password.')
25 if username is None:
26 raise TypeError('Superusers must have an username.')
28 user = self.create_user(username, password)
29 user.is_superuser = True
30 user.is_staff = True
31 user.save(using=self._db)
33 return user
36class User(AbstractBaseUser, PermissionsMixin):
37 username = models.CharField(db_index=True, max_length=255, unique=True)
38 email = models.EmailField(db_index=True, max_length=255, null=True)
39 is_active = models.BooleanField(default=True)
40 is_staff = models.BooleanField(default=False)
41 first_name = models.CharField(max_length=50, default="")
42 last_name = models.CharField(max_length=50, default="")
44 USERNAME_FIELD = 'username'
46 objects = UserManager()
48 def __str__(self):
49 return f"{self.id}"
51class BotUser(AnonymousUser):
52 @property
53 def is_authenticated(self):
54 return True
56 @property
57 def is_anonymous(self):
58 return True