Skip to content

Commit

Permalink
update repo with unsaved files
Browse files Browse the repository at this point in the history
  • Loading branch information
50-Course committed Sep 1, 2024
1 parent ebd9949 commit a6c8c07
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
1 change: 0 additions & 1 deletion backend/paycheck_core/src/paycheck/core/auth/backends.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib.auth.backends import BaseBackend
from django.http import HttpRequest


class PhoneEmailOrAccountNumberAuthBackend(BaseBackend):
Expand Down
Empty file.
52 changes: 39 additions & 13 deletions backend/paycheck_core/src/paycheck/core/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import AbstractUser, AbstractBaseUser, PermissionsMixin
from django.utils import choices
from django.utils.translation import gettext_lazy as _
from phone_field import PhoneField
from uuid import uuid4
from django.conf import settings


class BaseUser(AbstractUser):
class BaseUser(AbstractBaseUser, PermissionsMixin):
"""
Represent an abstract user model.
Expand Down Expand Up @@ -41,7 +42,12 @@ class BaseUser(AbstractUser):
"""

cannoical_id = models.UUIDField(
class USER_ROLES(models.TextChoices):
CUSTOMER = _("Customer")
SUPPORT = _("Support")
ADMIN = _("Admin")

id = models.UUIDField(
_("user id"),
primary_key=True,
default=uuid4,
Expand Down Expand Up @@ -70,6 +76,7 @@ class BaseUser(AbstractUser):
blank=True,
help_text="Designates the last name of the user",
)
date_joined = models.DateTimeField(auto_now_add=True)
last_login = models.DateTimeField(
_("last login"),
blank=True,
Expand All @@ -87,7 +94,22 @@ class BaseUser(AbstractUser):
help_text="Designates the phone number of the user",
)

role = models.CharField(
choices=USER_ROLES,
help_text="Determines which category a user falls in",
)

is_customer = models.BooleanField(default=False)
is_staff = models.BooleanField(
_("staff status"),
default=False,
help_text="Designates whether the user can access the admin panel",
)
is_admin = models.BooleanField(
_("admin status"),
default=False,
help_text="Designates whether the user is an admin",
)

REQUIRED_FIELDS = ["first_name", "last_name"]
USERNAME_FIELD = "email"
Expand All @@ -99,11 +121,6 @@ class Meta:
def __str__(self):
return self.username

@property
def full_name(self) -> str:
full_name = f"{self.first_name} {self.last_name}"
return full_name.strip()

def save(self, *args, **kwargs):
if not self.username:
self.username = self.email
Expand Down Expand Up @@ -244,7 +261,7 @@ class Meta:
]

def __str__(self):
return self.user.full_name()
return self.user.username

@property
def is_verified(self):
Expand Down Expand Up @@ -275,6 +292,11 @@ class Customer(BaseUser):
class Meta:
proxy = True

def save(self, *args, **kwargs) -> None:
self.is_customer = True
self.role = "customer"
super().save(*args, **kwargs)


class Support(BaseUser):
"""
Expand All @@ -285,13 +307,17 @@ class Support(BaseUser):
class Meta:
proxy = True

def __str__(self):
return self.user.full_name()
def save(self, *args, **kwargs) -> None:
self.is_staff = True
self.role = "support"
super().save(*args, **kwargs)


class Admin(BaseUser):
class Meta:
proxy = True

def __str__(self):
return self.user.full_name()
def save(self, *args, **kwargs) -> None:
self.is_admin = True
self.role = "admin"
super().save(*args, **kwargs)

0 comments on commit a6c8c07

Please sign in to comment.