Example #1
0
def mylogin(request):
    if request.method == "POST":
        username = request.POST.get("username", "")
        password = request.POST.get("password", "")
        user = authenticate(username=username, password=password)

        if user is not None:
            login(request, user)
            return HttpResponseRedirect(reverse("file_list"))
        else:
            return render(request, "app/login.html", {"message": _(u"Incorrect username or password")})
    else:
        return render(request, "app/login.html")
Example #2
0
def file_list(request):
    module_thumbnails = settings.THUMBNAIL_MODULE
    if request.user.is_superuser:
        users = User.objects.all()
    else:
        users = User.objects.filter(pk=request.user.id)
    return render(request, "app/file_list.html", {"users": users, "module_thumbnails": module_thumbnails})
Example #3
0
def delete_user(request, id):
    user = get_object_or_404(User, pk=id)
    if user.is_superuser:
        raise Http404

    if request.method == "POST":
        user.delete()
        return HttpResponseRedirect(reverse("manage_users"))
    else:
        return render(request, "app/delete_user.html", {"show_form": True, "this_user": user})
Example #4
0
def set_password(request, id):
    user = get_object_or_404(User, pk=id)
    if request.method == "POST":
        form = SetPasswordForm(user, request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse("manage_users"))
    else:
        form = SetPasswordForm(user)
    return render(request, "app/set_password.html", {"form": form, "this_user": user})
Example #5
0
def send_instructions(request, id):
    user = get_object_or_404(User, pk=id)
    if user.is_superuser:
        raise Http404
    if request.method == "POST":
        form = InstructionsForm(request.POST)
        if form.is_valid():
            form.send(user.username, RawPassword.objects.get(user=user).password)
            return HttpResponseRedirect(reverse("file_list"))
    else:
        form = InstructionsForm()
    return render(request, "app/send_instructions.html", {"form": form})
Example #6
0
def add_file(request, user_id):
    user = get_object_or_404(User, pk=user_id)
    # Only superusers or the owner can upload files to that profile.
    if not request.user.is_superuser and request.user != user:
        raise Http404

    if request.method == "POST":
        xs = sorted(get_field_numbers(request.FILES))
        new_post = select_fields(request.POST, xs)
        form = MultipleFileUploadForm(user, xs, new_post, request.FILES)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse("file_list"))
    else:
        form = SingleFileUploadForm(0)
    return render(request, "app/add_file.html", {"form": form, "user_id": user_id})
Example #7
0
def view_thumbnail(request, id):
    file = get_object_or_404(File, pk=id)
    _, extension = os.path.splitext(file.file.path)

    if extension in settings.THUMBNAIL_SUPPORTED:
        is_supported = "true"
    else:
        is_supported = "false"
    if extension in settings.THUMBNAIL_ARCHIVES:
        is_archive = "true"
    else:
        is_archive = "false"

    return render(
        request, "app/view_thumbnail.json", {"file": file, "is_supported": is_supported, "is_archive": is_archive}
    )
Example #8
0
def manage_users(request):
    if request.method == "POST":
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse("manage_users"))
    else:
        form = UserCreationForm()

    # Remove help text
    form.fields["username"].help_text = ""

    user_list = []
    for user in User.objects.all():
        user_list.append((user, RawPassword.objects.get(user=user), user.file_set.count(), total_size(user)))

    return render(request, "app/manage_users.html", {"user_list": user_list, "form": form, "chart_url": get_stats()})
Example #9
0
def disconnected(request):
    return render(request, "app/disconnected.html")
Example #10
0
def help(request):
    return render(request, "app/help.html")