Undo a masquerade session and redirect the user back to where they started
    cloaking from (or where ever the "next" POST parameter points)

def uncloak(request):
    """
    Undo a masquerade session and redirect the user back to where they started
    cloaking from (or where ever the "next" POST parameter points)
    """
    try:
        del request.session[SESSION_USER_KEY]
    except KeyError:
        pass # who cares

    # figure out where to redirect
    next = request.POST.get(REDIRECT_FIELD_NAME) or request.session.get(SESSION_REDIRECT_KEY)
    if next and is_safe_url(next, request.get_host()):
        return HttpResponseRedirect(next)
    return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)