-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implements tenant configuration
- Loading branch information
1 parent
b18204d
commit f0f4a55
Showing
15 changed files
with
232 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. | ||
from apps.users.models.users import VisuleoUser | ||
|
||
admin.site.site_header = "Visuleo Admin" | ||
admin.site.site_title = "Visuleo Admin Portal" | ||
admin.site.index_title = "Welcome to Visuleo Portal" | ||
|
||
admin.site.register(VisuleoUser) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,103 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import AbstractUser | ||
from django.contrib.auth.models import AbstractUser, BaseUserManager | ||
from django.utils.translation import gettext_lazy as _ | ||
from django.utils import timezone | ||
from apps.users.models import BaseModel | ||
|
||
|
||
class VisuleoUserManager(BaseUserManager): | ||
""" | ||
Custom user model manager for Visuleo. | ||
""" | ||
|
||
def create_user(self, email, password, **extra_fields): | ||
""" | ||
Create and save a Visuleo user with the given email and password. | ||
""" | ||
if not email: | ||
raise ValueError(_("The email must be set.")) | ||
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, password, **extra_fields): | ||
""" | ||
Create and save a Visuleo superuser with the given email and password. | ||
""" | ||
extra_fields.setdefault("is_staff", True) | ||
extra_fields.setdefault("is_superuser", True) | ||
extra_fields.setdefault("is_email_verified", True) | ||
extra_fields.setdefault("is_phone_number_verified", True) | ||
return self.create_user(email, password, **extra_fields) | ||
|
||
|
||
class VisuleoUser(BaseModel, AbstractUser): | ||
""" | ||
Custom user model for Visuleo. | ||
""" | ||
|
||
name = models.CharField( | ||
_('name'), | ||
_("name"), | ||
max_length=255, | ||
blank=True, | ||
help_text=_('User\'s full name.'), | ||
help_text=_("User's full name."), | ||
) | ||
email = models.EmailField( | ||
_('email address'), | ||
_("email address"), | ||
unique=True, | ||
help_text=_('User\'s email address.'), | ||
help_text=_("User's email address."), | ||
) | ||
phone_number = models.CharField( | ||
_('phone number'), | ||
_("phone number"), | ||
max_length=20, | ||
blank=True, | ||
help_text=_('User\'s phone number.'), | ||
help_text=_("User's phone number."), | ||
) | ||
is_email_verified = models.BooleanField( | ||
_('is email verified'), | ||
_("is email verified"), | ||
default=False, | ||
help_text=_('Boolean field to mark if this user\'s email is verified.'), | ||
help_text=_("Boolean field to mark if this user's email is verified."), | ||
) | ||
is_phone_number_verified = models.BooleanField( | ||
_('is phone number verified'), | ||
_("is phone number verified"), | ||
default=False, | ||
help_text=_('Boolean field to mark if this user\'s phone number is verified.'), | ||
help_text=_("Boolean field to mark if this user's phone number is verified."), | ||
) | ||
is_active = models.BooleanField( | ||
_('is active'), | ||
_("is active"), | ||
default=True, | ||
help_text=_('Boolean field to mark if this user is active.'), | ||
help_text=_("Boolean field to mark if this user is active."), | ||
) | ||
is_superuser = models.BooleanField( | ||
_('is superuser'), | ||
_("is superuser"), | ||
default=False, | ||
help_text=_('Boolean field to mark if this user is superuser.'), | ||
help_text=_("Boolean field to mark if this user is superuser."), | ||
) | ||
last_login = models.DateTimeField( | ||
_('last login'), | ||
_("last login"), | ||
default=timezone.now, | ||
help_text=_('Date and time when this user last logged in.'), | ||
help_text=_("Date and time when this user last logged in."), | ||
) | ||
date_joined = models.DateTimeField( | ||
_('date joined'), | ||
_("date joined"), | ||
default=timezone.now, | ||
help_text=_('Date and time when this user joined.'), | ||
help_text=_("Date and time when this user joined."), | ||
) | ||
|
||
USERNAME_FIELD = 'email' | ||
|
||
objects = VisuleoUserManager() | ||
|
||
USERNAME_FIELD = "email" | ||
REQUIRED_FIELDS = [] | ||
|
||
class Meta: | ||
verbose_name = _('user') | ||
verbose_name_plural = _('users') | ||
ordering = ('-created', '-modified',) | ||
|
||
verbose_name = _("user") | ||
verbose_name_plural = _("users") | ||
ordering = ( | ||
"-created", | ||
"-modified", | ||
) | ||
|
||
def __str__(self) -> str: | ||
return self.email | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .auth_views import RegistrationView, LoginView, LogoutView | ||
from .default import DefaultView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from rest_framework.views import APIView | ||
from rest_framework.response import Response | ||
|
||
|
||
class DefaultView(APIView): | ||
""" | ||
Default view for the users app. | ||
""" | ||
authentication_classes = () | ||
permission_classes = () | ||
|
||
|
||
def get(self, request): | ||
return Response({"message": "No tenants found."}) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.