khaganat-web/pwdb/views.py

24 lines
869 B
Python
Raw Permalink Normal View History

2019-07-27 15:17:21 +00:00
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth import authenticate
from django.shortcuts import render
from .models import SharedPasswordAccess
from .forms import AuthForm
@staff_member_required(login_url="login")
2019-07-27 15:17:21 +00:00
def list_passwords(request):
try:
pwd = request.POST["pwdb_check"]
user = authenticate(username=request.user, password=pwd)
assert user is not None
lst = (
SharedPasswordAccess.objects.select_related("password")
.filter(user__pk=user.pk)
.order_by("password__name")
)
ctx = {"passwords": [e.password for e in lst]}
return render(request, "pwdb/list_passwords.html", ctx)
except (KeyError, AssertionError):
ctx = {"form": AuthForm()}
return render(request, "pwdb/authenticate.html", ctx)