Created
October 15, 2014 12:53
-
-
Save jtallieu/b62be3afd52d372d1364 to your computer and use it in GitHub Desktop.
Using the django masquerade.py middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@user_passes_test(lambda u: u.is_superuser) | |
def view_as_user(request, id): | |
""" | |
Allows a priveledged user to view the website as another without | |
logging in as that user | |
""" | |
log.info("Finding user %s" % id) | |
try: | |
user = User.objects.get(pk=id) | |
log.info("User %s" % user) | |
except User.DoesNotExist: | |
return None | |
request.session["_masq_user"] = user | |
#return render_to_response('control/main.html',{}) | |
return redirect("/settings") | |
@login_required | |
def stop_masq(request): | |
""" | |
Ends the masquerade sessions | |
""" | |
try: request.session.pop('_masq_user') | |
except:pass | |
return redirect("/control_panel") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment