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") 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)