From 280a296c8560d54fa13014d377eca108f166d36c Mon Sep 17 00:00:00 2001 From: Paul Craciunoiu Date: Tue, 30 Mar 2010 17:49:02 -0700 Subject: [PATCH] Adding django user integration, backend and middleware for TikiUser --- apps/sumo/middleware.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/apps/sumo/middleware.py b/apps/sumo/middleware.py index da176e3a7..9875edf10 100644 --- a/apps/sumo/middleware.py +++ b/apps/sumo/middleware.py @@ -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) +