handle failed login

This commit is contained in:
simon 2021-10-24 15:34:00 +07:00
parent dffe974f9e
commit 0ce5183056
3 changed files with 12 additions and 6 deletions

View File

@ -24,6 +24,9 @@
{% endif %}
<h1>Tube Archivist</h1>
<h2>Your Self Hosted YouTube Media Server</h2>
{% if form_error %}
<p class="danger-zone">Failed to login.</p>
{% endif %}
<form action="/login/" method="POST" name="login">
{% csrf_token %}
{% for field in form %}

View File

@ -148,12 +148,10 @@ class LoginView(View):
def get(self, request):
"""handle get requests"""
failed = bool(request.GET.get("failed"))
colors = self.read_config()
form = CustomAuthForm()
context = {
"colors": colors,
"form": form,
}
context = {"colors": colors, "form": form, "form_error": failed}
return render(request, "home/login.html", context)
@staticmethod
@ -162,12 +160,11 @@ class LoginView(View):
form = AuthenticationForm(data=request.POST)
if form.is_valid():
next_url = request.POST.get("next") or "home"
print(f"next url: {next_url}")
user = form.get_user()
login(request, user)
return redirect(next_url)
return redirect("login")
return redirect("/login?failed=true")
@staticmethod
def read_config():

View File

@ -542,6 +542,12 @@ button:hover {
min-width: 200px;
}
.login-page button,
.login-page .danger-zone {
width: 210px;
margin-top: 5px;
}
.login-links a {
text-decoration: underline;
margin: 30px 0;