3 from django.contrib.sessions.models import Session
4 from django.shortcuts import get_object_or_404, render_to_response
5 from django.contrib.auth.models import User
6 from django.template import RequestContext
7 from django.conf import settings
10 def flash_login_required(function):
12 Decorator to recognize a user by its session.
13 Used for Flash-Uploading.
16 def decorator(request, *args, **kwargs):
18 engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
20 import django.contrib.sessions.backends.db
21 engine = django.contrib.sessions.backends.db
22 session_data = engine.SessionStore(request.POST.get('session_key'))
23 user_id = session_data['_auth_user_id']
24 #will return 404 if the session ID does not resolve to a valid user
25 request.user = get_object_or_404(User, pk=user_id)
26 return function(request, *args, **kwargs)