зеркало из https://github.com/mozilla/kitsune.git
Adding django user integration, backend and middleware for TikiUser
This commit is contained in:
Родитель
ad6915313e
Коммит
280a296c85
|
@ -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)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче