diff --git a/EpisodesCommunity/settings.py b/EpisodesCommunity/settings.py index 6dd7465..0774f06 100644 --- a/EpisodesCommunity/settings.py +++ b/EpisodesCommunity/settings.py @@ -47,6 +47,8 @@ AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', ) +AUTH_USER_MODEL = 'LandingPage.User' + INSTALLED_APPS = [ 'LandingPage.apps.LandingpageConfig', 'Show.apps.ShowConfig', diff --git a/LandingPage/admin.py b/LandingPage/admin.py index 5515ecf..13aef35 100644 --- a/LandingPage/admin.py +++ b/LandingPage/admin.py @@ -1,9 +1,18 @@ from django.contrib import admin +from django.contrib.auth.admin import UserAdmin from .models import * +from .forms import SpecialUserChangeForm + +class SpecialUserAdmin(UserAdmin): + form = SpecialUserChangeForm + + fieldsets = UserAdmin.fieldsets + ( + (None, {'fields': ('display_name',)}), + ) # Register your models here. admin.site.register(Show) -admin.site.register(ExternalUser) +admin.site.register(User, SpecialUserAdmin) admin.site.register(Admin) admin.site.register(Ban) admin.site.register(ShowModerator) @@ -18,4 +27,3 @@ admin.site.register(Watch) admin.site.register(DiscussionBoard) admin.site.register(DiscussionReply) admin.site.register(DiscussionVote) - diff --git a/LandingPage/backends.py b/LandingPage/backends.py index be13a4c..27673ee 100644 --- a/LandingPage/backends.py +++ b/LandingPage/backends.py @@ -5,7 +5,6 @@ import logging from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.auth.backends import ModelBackend -from .models import ExternalUser class OAuthBackend(ModelBackend): def authenticate(self, code=None): @@ -33,13 +32,15 @@ class OAuthBackend(ModelBackend): ).json() usermodel = get_user_model() - matches = usermodel.objects.filter(externaluser__icy_id=user_info['uuid']) + matches = usermodel.objects.filter(icy_id=user_info['uuid']) match = None if not len(matches): user = usermodel.objects.create_user( username = user_info['username'], email = user_info['email'], + icy_id = user_info['uuid'], + display_name = user_info['display_name'] ) if 'privilege' in user_info: @@ -48,12 +49,7 @@ class OAuthBackend(ModelBackend): user.is_staff = (priv > 0) user.save() - user.externaluser = ExternalUser( - user = user, - icy_id = user_info['uuid'], - display_name = user_info['display_name'] - ) - user.externaluser.save() + match = user else: match = matches[0] diff --git a/LandingPage/forms.py b/LandingPage/forms.py new file mode 100644 index 0000000..773d760 --- /dev/null +++ b/LandingPage/forms.py @@ -0,0 +1,6 @@ +from django.contrib.auth.forms import UserChangeForm +from .models import User + +class SpecialUserChangeForm(UserChangeForm): + class Meta(UserChangeForm.Meta): + model = User diff --git a/LandingPage/models.py b/LandingPage/models.py index 309acf8..879998c 100644 --- a/LandingPage/models.py +++ b/LandingPage/models.py @@ -1,5 +1,5 @@ from django.db import models -from django.contrib.auth.models import User +from django.contrib.auth.models import AbstractUser from django.core.files.storage import FileSystemStorage from django.conf import settings import os @@ -72,13 +72,7 @@ class Show(TimestampedModel): def __str__(self): return '%s [%s]'%(self.name,self.abbr) -class ExternalUser(TimestampedModel): - user = models.OneToOneField( - User, - on_delete=models.CASCADE, - help_text='The internal Django user', - verbose_name="User" - ) +class User(AbstractUser): icy_id = models.CharField( max_length=36, help_text='The UUID assigned to this user by IcyNet\'s auth servers' @@ -98,8 +92,6 @@ class ExternalUser(TimestampedModel): related_name='watched_by', through='Watch' ) - def __str__(self): - return 'External for %s (%s)'%(self.user.email, self.display_name) class Admin(User): pass @@ -326,7 +318,7 @@ class SubmissionVote(TimestampedModel): class Favorite(TimestampedModel): user = models.ForeignKey( - ExternalUser, + User, on_delete=models.CASCADE ) episode = models.ForeignKey( @@ -338,7 +330,7 @@ class Favorite(TimestampedModel): class Watch(TimestampedModel): user = models.ForeignKey( - ExternalUser, + User, on_delete=models.CASCADE ) episode = models.ForeignKey( diff --git a/LandingPage/templates/base.html b/LandingPage/templates/base.html index d729237..44580b1 100644 --- a/LandingPage/templates/base.html +++ b/LandingPage/templates/base.html @@ -21,7 +21,7 @@
{% if user.is_authenticated %} - {{ user.externaluser.display_name }} + {{ user.display_name }} {% else %} Log in {% endif %}