From 0ce5183056785958a849859e92ddbf3768a9fd65 Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 24 Oct 2021 15:34:00 +0700 Subject: [PATCH] handle failed login --- tubearchivist/home/templates/home/login.html | 3 +++ tubearchivist/home/views.py | 9 +++------ tubearchivist/static/css/style.css | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tubearchivist/home/templates/home/login.html b/tubearchivist/home/templates/home/login.html index 5e2c23d..03d2167 100644 --- a/tubearchivist/home/templates/home/login.html +++ b/tubearchivist/home/templates/home/login.html @@ -24,6 +24,9 @@ {% endif %}

Tube Archivist

Your Self Hosted YouTube Media Server

+ {% if form_error %} +

Failed to login.

+ {% endif %}
{% csrf_token %} {% for field in form %} diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index b8103c2..6da67df 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -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(): diff --git a/tubearchivist/static/css/style.css b/tubearchivist/static/css/style.css index 29d901c..f03b21f 100644 --- a/tubearchivist/static/css/style.css +++ b/tubearchivist/static/css/style.css @@ -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;