Adding django user integration, backend and middleware for TikiUser

This commit is contained in:
Paul Craciunoiu 2010-03-30 17:49:02 -07:00
Родитель ad6915313e
Коммит 280a296c85
1 изменённых файлов: 24 добавлений и 0 удалений

Просмотреть файл

@ -8,10 +8,12 @@ import urllib
from django.http import HttpResponsePermanentRedirect
from django.utils.encoding import smart_str
from django.contrib import auth
import tower
from . import urlresolvers
from .models import Session
from sumo.helpers import urlparams
@ -56,3 +58,25 @@ class LocaleURLMiddleware(object):
request.path_info = '/' + prefixer.shortened_path
request.locale = prefixer.locale
tower.activate(prefixer.locale)
class TikiCookieMiddleware(object):
"""
This middleware looks at the SUMOv1 cookie set by Tiki and authenticates
the user in django.
"""
def process_request(self, request):
"""Look up the SUMOv1 cookie and authenticate the user"""
id = request.COOKIES.get('SUMOv1')
if id:
try:
session = Session.objects.get(pk=id)
except Session.DoesNotExist:
return
user = auth.authenticate(session=session)
if user is not None:
auth.login(request, user)