Fixed SSOUser snafu

This commit is contained in:
2010-02-25 19:21:56 +00:00
parent 982223f4aa
commit 78cb8409b4
4 changed files with 51 additions and 17 deletions

View File

@@ -2,7 +2,22 @@
Admin interface models. Automatically detected by admin.autodiscover().
"""
from django.contrib import admin
from sso.models import Service, ServiceAccount
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from sso.models import Service, ServiceAccount, SSOUser
admin.site.register(Service)
admin.site.register(ServiceAccount)
class SSOUserProfileInline(admin.StackedInline):
model = SSOUser
fk_name = 'user'
max_num = 1
# Define a new UserAdmin class
class SSOUserAdmin(UserAdmin):
inlines = [SSOUserProfileInline, ]
# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, SSOUserAdmin)

View File

@@ -11,25 +11,26 @@ class CorporateOnlyService(Exception):
## Models
class SSOUser(User):
class SSOUser(models.Model):
""" Extended SSO User Profile options """
user = models.ForeignKey(User, unique=True, related_name='profile')
default_service_passwd = models.CharField(max_length=200)
default_service_username = models.CharField(max_length=200)
default_service_username = models.CharField(max_length=200, blank=True)
website = models.CharField(max_length=200)
aim = models.CharField(max_length=64)
msn = models.CharField(max_length=200)
icq = models.CharField(max_length=15)
xmpp = models.CharField(max_length=200)
website = models.CharField(max_length=200, blank=True)
aim = models.CharField(max_length=64, blank=True)
msn = models.CharField(max_length=200, blank=True)
icq = models.CharField(max_length=15, blank=True)
xmpp = models.CharField(max_length=200, blank=True)
def __str__(self):
return self.user
return self.user.__str__()
@staticmethod
def create_user_profile(sender, instance, created, **kwargs):
print 'trigger', instance
if created:
profile, created = SSOUser.objects.get_or_create(user=instance)

View File

@@ -1,7 +1,9 @@
from django.shortcuts import render_to_response
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from sso.models import ServiceAccount
from eve_api.models.api_player import EVEAccount
from sso.models import ServiceAccount, SSOUser
def index(request):
pass
@@ -10,10 +12,23 @@ def index(request):
def profile(request):
user = request.user
profile = request.user.get_profile()
srvaccounts = ServiceAccounts.objects.get(user=request.user)
try:
profile = request.user.get_profile()
except SSOUser.DoesNotExist:
profile = SSOUser(user=request.user)
profile.save()
return render_to_response('sso/profile.html', locals())
try:
srvaccounts = ServiceAccount.objects.get(user=request.user)
except ServiceAccount.DoesNotExist:
srvaccounts = None
try:
eveaccounts = EVEAccount.objects.get(user=request.user)
except EVEAccount.DoesNotExist:
eveaccounts = None
return render_to_response('profile.html', locals())
def service_add(request):

11
urls.py
View File

@@ -1,11 +1,14 @@
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
# Unregister unneeded interfaces
from eve_proxy.models import CachedDocument
admin.site.unregister(CachedDocument)
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
(r'^accounts/', include('registration.backends.default.urls')),
(r'^sso/', include('sso.urls')),
('', include('registration.backends.default.urls')),
('', include('sso.urls')),
)