From b7833126e338ab88676ae0761e793be88f81b871 Mon Sep 17 00:00:00 2001 From: mein Name Date: Thu, 6 Feb 2025 12:14:19 +0000 Subject: [PATCH] improve login so that it can redirect to app authorization properly --- catalog/templates/item_base.html | 2 +- common/templates/404.html | 1 + common/templates/_header.html | 2 +- common/views.py | 1 + journal/views/profile.py | 6 +++++- users/templates/users/account.html | 5 ++--- users/templates/users/login.html | 2 +- users/templates/users/verify_email.html | 6 +++--- users/templates/users/welcome.html | 4 ++-- users/views/account.py | 2 +- 10 files changed, 18 insertions(+), 13 deletions(-) diff --git a/catalog/templates/item_base.html b/catalog/templates/item_base.html index f9eb83bd..9ffb640c 100644 --- a/catalog/templates/item_base.html +++ b/catalog/templates/item_base.html @@ -111,7 +111,7 @@ {% else %}

- + {% trans 'Login or register to review or add this item to your collection.' %}

diff --git a/common/templates/404.html b/common/templates/404.html index fe8c3831..684f36d1 100644 --- a/common/templates/404.html +++ b/common/templates/404.html @@ -22,6 +22,7 @@ {% blocktrans %}You may have visited an incorrect URL, or the content you are looking for has been deleted by the author.{% endblocktrans %}
{% blocktrans %}If you believe this is our mistake, please contact us through the link at the bottom of the page.{% endblocktrans %} + {trans "Go to Home"} {% include "_footer.html" %} diff --git a/common/templates/_header.html b/common/templates/_header.html index 7793149a..b0ccc37e 100644 --- a/common/templates/_header.html +++ b/common/templates/_header.html @@ -115,7 +115,7 @@ {% endif %} {% else %}
  • - {% trans 'Sign up or Login' %} + {% trans 'Sign up or Login' %}
  • {% endif %} diff --git a/common/views.py b/common/views.py index 4f86af3c..fb740d6e 100644 --- a/common/views.py +++ b/common/views.py @@ -89,6 +89,7 @@ def error_403(request, exception=None): def error_404(request, exception=None): + request.session.pop("next_url", None) return render(request, "404.html", status=404, context={"exception": exception}) diff --git a/journal/views/profile.py b/journal/views/profile.py index 63aa60e7..440d0932 100644 --- a/journal/views/profile.py +++ b/journal/views/profile.py @@ -1,4 +1,5 @@ import datetime +from urllib.parse import quote_plus from django.contrib.auth.decorators import login_required from django.shortcuts import render @@ -25,7 +26,10 @@ def profile(request: AuthedHttpRequest, user_name): return render( request, "users/home_anonymous.html", - {"identity": target, "redir": f"/account/login?next={target.url}"}, + { + "identity": target, + "redir": f"/account/login?next={quote_plus(target.url)}", + }, ) if (target.local and user_name != target.handle) or ( diff --git a/users/templates/users/account.html b/users/templates/users/account.html index b28468a6..d60f5d3b 100644 --- a/users/templates/users/account.html +++ b/users/templates/users/account.html @@ -17,7 +17,7 @@
    {% trans "Display name, avatar and other information" %} -
    @@ -42,8 +42,7 @@
    {% trans 'Email' %} - +
    diff --git a/users/templates/users/welcome.html b/users/templates/users/welcome.html index d83453d9..65ad13b9 100644 --- a/users/templates/users/welcome.html +++ b/users/templates/users/welcome.html @@ -20,11 +20,11 @@

    {% trans "Welcome" %}

    {% blocktrans %} - {{ site_name }} is flourishing because of collaborations and contributions from users like you. Please read our term of service, and feel free to contact us if you have any question or feedback. + {{ site_name }} is flourishing because of collaborations and contributions from users like you. Please read our rules, and feel free to contact us if you have any question or feedback. {% endblocktrans %}

    - +
    diff --git a/users/views/account.py b/users/views/account.py index c503c6aa..2587ff94 100644 --- a/users/views/account.py +++ b/users/views/account.py @@ -131,7 +131,7 @@ def register(request: AuthedHttpRequest): auth_login(request, new_user) return render(request, "users/welcome.html") else: - return redirect(reverse("common:home")) + return redirect(request.session.get("next_url", reverse("common:home"))) # use verified email if presents for new account creation if verified_account and verified_account.platform == Platform.EMAIL: