diff --git a/apps/authentication/managers.py b/apps/authentication/managers.py index 7957e69..95f24ee 100644 --- a/apps/authentication/managers.py +++ b/apps/authentication/managers.py @@ -2,12 +2,12 @@ import logging -from django.contrib.auth import models +from django.contrib.auth.models import BaseUserManager log = logging.getLogger(__name__) -class DiscordUserOAuth2Manager(models.UserManager): +class DiscordUserOAuth2Manager(BaseUserManager): """ Manager for the DiscordUser class. """ diff --git a/apps/authentication/migrations/0002_alter_discorduser_managers.py b/apps/authentication/migrations/0002_alter_discorduser_managers.py new file mode 100644 index 0000000..05ee828 --- /dev/null +++ b/apps/authentication/migrations/0002_alter_discorduser_managers.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.1 on 2024-03-13 13:45 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentication', '0001_initial'), + ] + + operations = [ + migrations.AlterModelManagers( + name='discorduser', + managers=[ + ], + ), + ] diff --git a/apps/authentication/models.py b/apps/authentication/models.py index 77f66da..fc35b91 100644 --- a/apps/authentication/models.py +++ b/apps/authentication/models.py @@ -3,6 +3,7 @@ from django.db import models from django.utils import timezone from django.utils.translation import gettext_lazy as _ +# from django.contrib.auth.models import AbstractBaseUser from .managers import DiscordUserOAuth2Manager @@ -12,7 +13,6 @@ class DiscordUser(models.Model): Represents a User authenticated with Discord OAuth2. """ - # Discord Attributes id = models.PositiveBigIntegerField( @@ -88,12 +88,33 @@ class DiscordUser(models.Model): objects = DiscordUserOAuth2Manager() - def is_authenticated(self, request): - return True + REQUIRED_FIELDS = [] + USERNAME_FIELD = "username" def __str__(self): return self.global_name or self.username @property def avatar_url(self): - return f"https://cdn.discordapp.com/avatars/{self.id}/{self.avatar}.webp?size=128" \ No newline at end of file + return f"https://cdn.discordapp.com/avatars/{self.id}/{self.avatar}.webp?size=128" + + @property + def password(self): + return "password" + + @property + def is_authenticated(self): + return True + + @property + def is_anonymous(self): + return False + + def get_username(self): + return self.username + + def has_perm(self, perm, obj=None): + return self.is_superuser + + def has_module_perms(self, app_label): + return self.is_superuser \ No newline at end of file diff --git a/core/settings.py b/core/settings.py index 3008c1b..b583863 100644 --- a/core/settings.py +++ b/core/settings.py @@ -58,7 +58,7 @@ LOGIN_URL = "/login/" LOGIN_REDIRECT_URL = "/" LOGOUT_REDIRECT_URL = "/" -# AUTH_USER_MODEL = "authentication.User" +AUTH_USER_MODEL = "authentication.DiscordUser" TEMPLATES = [ {