Ejemplo n.º 1
0
def mask(request, template_name='masquerade/mask_form.html', pk=None):
    if not request.user.is_masked and not request.user.is_staff:
        return HttpResponseForbidden()
    elif not request.user.is_superuser and MASQUERADE_REQUIRE_SUPERUSER:
        return HttpResponseForbidden()

    if pk:
        User = get_user_model()
        user = get_object_or_404(User, pk=pk)
        if request.method == 'POST':
            form = MaskUserForm(request.POST)
            if form.is_valid():
                request.session['mask_user'] = user.username
                mask_on.send(sender=form, mask_username=user.username)
                return HttpResponseRedirect(MASQUERADE_REDIRECT_URL)
        else:
            form = MaskUserForm()
            return render_to_response('masquerade/mask_user_form.html',
                                      {'form': form, 'user': user}, context_instance=RequestContext(request))
    if request.method == 'POST':
        form = MaskForm(request.POST)
        if form.is_valid():
            # turn on masquerading
            request.session['mask_user'] = form.cleaned_data['mask_user']
            mask_on.send(sender=form,
                mask_username=form.cleaned_data['mask_user'])
            return HttpResponseRedirect(MASQUERADE_REDIRECT_URL)
    else:
        form = MaskForm()

    return render_to_response(template_name, {'form': form},
      context_instance=RequestContext(request))
Ejemplo n.º 2
0
def mask(request, uid):
    if not request.user.is_masked and not request.user.is_staff:
        return PermissionDenied()
    elif not request.user.is_superuser and MASQUERADE_REQUIRE_SUPERUSER:
        return PermissionDenied()

    try:
        user = User.objects.get(pk = uid)
        request.session['mask_user'] = user.username
        mask_on.send(sender = object(), mask_username = request.session['mask_user'])
    except Exception, e:
        messages.error(request, '1) ' + str(e))
Ejemplo n.º 3
0
def mask(request, uid):
    if not request.user.is_masked and not request.user.is_staff:
        return PermissionDenied()
    elif not request.user.is_superuser and MASQUERADE_REQUIRE_SUPERUSER:
        return PermissionDenied()

    try:
        user = User.objects.get(pk = uid)
        request.session['mask_user'] = user.username
        mask_on.send(sender = object(), mask_username = request.session['mask_user'])
    except Exception, e:
        messages.error(request, '1) ' + str(e))
Ejemplo n.º 4
0
def mask(request, template_name="masquerade/mask_form.html"):
    if not request.user.is_masked and not request.user.is_staff:
        return HttpResponseForbidden()
    elif not request.user.is_superuser and MASQUERADE_REQUIRE_SUPERUSER:
        return HttpResponseForbidden()

    if request.method == "POST":
        form = MaskForm(request.POST)
        if form.is_valid():
            # turn on masquerading
            request.session["mask_user"] = form.cleaned_data["mask_user"]
            mask_on.send(sender=form, mask_username=form.cleaned_data["mask_user"], request=request)
            return HttpResponseRedirect(MASQUERADE_REDIRECT_URL)
    else:
        form = MaskForm()

    return render_to_response(template_name, {"form": form}, context_instance=RequestContext(request))