Commits

Adam Gomaa committed e9d5a77 Draft

Add support for post-impersonation redirect. Fix README example so path is never empty.

Comments (0)

Files changed (2)

 
     from django_vicar import vicar
     # ...
-        url(r'^vicar/(.*)$', vicar),
+        url(r'^vicar/(.+)$', vicar),
     # ...
 
 And by putting 'django_vicar.VicarMiddleware' somewhere in your

django_vicar/__init__.py

-from django.http import HttpResponse
+from django.http import HttpResponse, HttpResponseRedirect
 from django.contrib.auth.models import User
 
 
             request.user = vicar_user
 
 
-def vicar(request, ident):
+def vicar(request, ident, opts=None):
+    if opts is None:
+        opts = {}
     if request.session.get('_orig_user'):
         orig_user = User.objects.get(id=request.session['_orig_user'])
     else:
     if ident == '0':
         del request.session['_vicar_user']
         del request.session['_orig_user']
+        if opts.get('stop_redirect'):
+            return HttpResponseRedirect(opts.get('stop_redirect'))
         return HttpResponse("suddenly you're boring again...")
 
     # /vicar/uken
     if orig_user is None:
         request.session['_orig_user'] = request.user.id
     request.session['_vicar_user'] = wannabe.id
+    if opts.get('start_redirect'):
+        return HttpResponseRedirect(opts.get('start_redirect'))
 
     return HttpResponse("you're a poseur. it's french for poser.")