Adam Gomaa avatar 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.")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.