Admin interface fixes
This commit is contained in:
parent
0d9356000e
commit
9ea5a645a0
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.contrib.auth import models
|
from django.contrib.auth.models import BaseUserManager
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class DiscordUserOAuth2Manager(models.UserManager):
|
class DiscordUserOAuth2Manager(BaseUserManager):
|
||||||
"""
|
"""
|
||||||
Manager for the DiscordUser class.
|
Manager for the DiscordUser class.
|
||||||
"""
|
"""
|
||||||
|
@ -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=[
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
@ -3,6 +3,7 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
# from django.contrib.auth.models import AbstractBaseUser
|
||||||
|
|
||||||
from .managers import DiscordUserOAuth2Manager
|
from .managers import DiscordUserOAuth2Manager
|
||||||
|
|
||||||
@ -12,7 +13,6 @@ class DiscordUser(models.Model):
|
|||||||
Represents a User authenticated with Discord OAuth2.
|
Represents a User authenticated with Discord OAuth2.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# Discord Attributes
|
# Discord Attributes
|
||||||
|
|
||||||
id = models.PositiveBigIntegerField(
|
id = models.PositiveBigIntegerField(
|
||||||
@ -88,12 +88,33 @@ class DiscordUser(models.Model):
|
|||||||
|
|
||||||
objects = DiscordUserOAuth2Manager()
|
objects = DiscordUserOAuth2Manager()
|
||||||
|
|
||||||
def is_authenticated(self, request):
|
REQUIRED_FIELDS = []
|
||||||
return True
|
USERNAME_FIELD = "username"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.global_name or self.username
|
return self.global_name or self.username
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def avatar_url(self):
|
def avatar_url(self):
|
||||||
return f"https://cdn.discordapp.com/avatars/{self.id}/{self.avatar}.webp?size=128"
|
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
|
@ -58,7 +58,7 @@ LOGIN_URL = "/login/"
|
|||||||
LOGIN_REDIRECT_URL = "/"
|
LOGIN_REDIRECT_URL = "/"
|
||||||
LOGOUT_REDIRECT_URL = "/"
|
LOGOUT_REDIRECT_URL = "/"
|
||||||
|
|
||||||
# AUTH_USER_MODEL = "authentication.User"
|
AUTH_USER_MODEL = "authentication.DiscordUser"
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user