Beispiel #1
0
def remove_paste(request, char_id):
    """
    Remove a single paste
    """
    if not request.user.is_authenticated():
        return render(request, "pastes/remove_paste/remove_error.html",
                      {"reason": "not_logged_in"})

    try:
        paste = cache.get("paste:%s" % char_id)

        if paste == None:
            paste = Paste.objects.select_related("user").get(char_id=char_id)
            cache.set("paste:%s" % char_id, paste)
        elif paste == False:
            return render(request,
                          "pastes/remove_paste/show_error.html",
                          {"reason": "not_found"},
                          status=404)
    except ObjectDoesNotExist:
        return render(request, "pastes/remove_paste/remove_error.html",
                      {"reason": "not_found"})

    # Check that the user can delete the paste
    if paste.user != request.user and not request.user.is_staff:
        return render(request, "pastes/remove_paste/remove_error.html",
                      {"reason": "not_owner"})

    if paste.is_expired():
        return render(request, "pastes/remove_paste/remove_error.html",
                      {"reason": "expired"})
    if paste.is_removed():
        return render(request, "pastes/remove_paste/remove_error.html",
                      {"reason": "removed"})

    verify_form = VerifyPasswordForm(request.POST or None, user=request.user)
    remove_form = RemovePasteForm(request.POST or None)

    if verify_form.is_valid() and remove_form.is_valid():
        if remove_form.cleaned_data["removal_reason"].strip() == "":
            paste.remove_paste(type=Paste.USER_REMOVAL)
        else:
            paste.remove_paste(
                type=Paste.USER_REMOVAL,
                reason=remove_form.cleaned_data["removal_reason"])

        return render(request, "pastes/remove_paste/paste_removed.html")

    return render(request, "pastes/remove_paste/remove_paste.html", {
        "paste": paste,
        "verify_form": verify_form,
        "remove_form": remove_form
    })
Beispiel #2
0
def delete_account(request, args):
    """
    Delete the user's account
    """
    form = VerifyPasswordForm(request.POST or None, user=request.user)
    
    if form.is_valid():
        PastebinUser.delete_user(request.user)
        logout(request)
        
        return render(request, "users/settings/delete_account/account_deleted.html")
    
    args["form"] = form
    
    return render(request, "users/settings/delete_account/delete_account.html", args)
Beispiel #3
0
def delete_account(request, args):
    """
    Delete the user's account
    """
    form = VerifyPasswordForm(request.POST or None, user=request.user)

    if form.is_valid():
        PastebinUser.delete_user(request.user)
        logout(request)

        return render(request,
                      "users/settings/delete_account/account_deleted.html")

    args["form"] = form

    return render(request, "users/settings/delete_account/delete_account.html",
                  args)
Beispiel #4
0
def remove_paste(request, char_id):
    """
    Remove a single paste
    """
    if not request.user.is_authenticated():
        return render(request, "pastes/remove_paste/remove_error.html", {"reason": "not_logged_in"})
    
    try:
        paste = cache.get("paste:%s" % char_id)
        
        if paste == None:
            paste = Paste.objects.select_related("user").get(char_id=char_id)
            cache.set("paste:%s" % char_id, paste)
        elif paste == False:
            return render(request, "pastes/remove_paste/show_error.html", {"reason": "not_found"}, status=404)
    except ObjectDoesNotExist:
        return render(request, "pastes/remove_paste/remove_error.html", {"reason": "not_found"})
    
    # Check that the user can delete the paste
    if paste.user != request.user and not request.user.is_staff:
        return render(request, "pastes/remove_paste/remove_error.html", {"reason": "not_owner"})
    
    if paste.is_expired():
        return render(request, "pastes/remove_paste/remove_error.html", {"reason": "expired"})
    if paste.is_removed():
        return render(request, "pastes/remove_paste/remove_error.html", {"reason": "removed"})
    
    verify_form = VerifyPasswordForm(request.POST or None, user=request.user)
    remove_form = RemovePasteForm(request.POST or None)
    
    if verify_form.is_valid() and remove_form.is_valid():
        if remove_form.cleaned_data["removal_reason"].strip() == "":
            paste.remove_paste(type=Paste.USER_REMOVAL)
        else:
            paste.remove_paste(type=Paste.USER_REMOVAL, reason=remove_form.cleaned_data["removal_reason"])
        
        return render(request, "pastes/remove_paste/paste_removed.html")
    
    return render(request, "pastes/remove_paste/remove_paste.html", {"paste": paste,
                                                                     
                                                                     "verify_form": verify_form,
                                                                     "remove_form": remove_form})