Skip to content

Commit

Permalink
improve login so that it can redirect to app authorization properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mein Name authored and alphatownsman committed Feb 6, 2025
1 parent 5d9afbd commit b783312
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion catalog/templates/item_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ <h1>
{% else %}
<section>
<p class="empty">
<span><a href="{% url 'users:login' %}?next={{ request.path }}">
<span><a href="{% url 'users:login' %}?next={{ request.path | urlencode }}">
{% trans 'Login or register to review or add this item to your collection.' %}
</a></span>
</p>
Expand Down
1 change: 1 addition & 0 deletions common/templates/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ <h3>🤷🏻 {% trans "Something is missing" %}</h3>
{% blocktrans %}You may have visited an incorrect URL, or the content you are looking for has been deleted by the author.{% endblocktrans %}
<br>
{% blocktrans %}If you believe this is our mistake, please contact us through the link at the bottom of the page.{% endblocktrans %}
<a href="{% url 'common:home' %}" class="button">{trans "Go to Home"}</a>
</article>
</main>
{% include "_footer.html" %}
Expand Down
2 changes: 1 addition & 1 deletion common/templates/_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
{% endif %}
{% else %}
<li>
<a href="{% url 'users:login' %}?next={{ request.path }}">{% trans 'Sign up or Login' %}</a>
<a href="{% url 'users:login' %}?next={{ request.path | urlencode }}">{% trans 'Sign up or Login' %}</a>
</li>
{% endif %}
</ul>
Expand Down
1 change: 1 addition & 0 deletions common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})


Expand Down
6 changes: 5 additions & 1 deletion journal/views/profile.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 (
Expand Down
5 changes: 2 additions & 3 deletions users/templates/users/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<article>
<details>
<summary>{% trans "Display name, avatar and other information" %}</summary>
<form action="{% url 'users:profile' %}?next={{ request.path }}"
<form action="{% url 'users:profile' %}"
method="post"
{% if request.user.mastodon and not request.user.preference.mastodon_skip_userinfo %}onsubmit="return confirm('{% trans "Updating profile information here will turn off automatic sync of display name, bio and avatar from your Mastodon instance. Sure to continue?" %}')"{% endif %}
enctype="multipart/form-data">
Expand All @@ -42,8 +42,7 @@
<article>
<details>
<summary>{% trans 'Email' %}</summary>
<form action="{% url 'users:register' %}?next={{ request.path }}"
method="post">
<form action="{% url 'users:register' %}" method="post">
<input value="{{ request.user.username }}" type="hidden" name="username" />
<fieldset>
<label>
Expand Down
2 changes: 1 addition & 1 deletion users/templates/users/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</header>
<div>
{% if request.user.is_authenticated %}
<a href="{{ request.session.next_url | default:'/' }}" class="button">{% trans 'back to your home page.' %}</a>
<a href="{{ request.session.next_url | default:'/' }}" class="button">{% trans 'Continue' %}</a>
{% elif allow_any_site %}
<div role="group">
{% if enable_email %}
Expand Down
6 changes: 3 additions & 3 deletions users/templates/users/verify_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
<h4>{% trans 'Verify Your Email' %}</h4>
{% if success %}
<p>
{{ request.user.email }} {% trans "verified successfully." %}
{{ request.user.email }} {% trans "Verified successfully." %}
<br>
<a href="{% url 'common:home' %}">{% trans "back to your home page." %}</a>
<a href="{{ request.session.next_url | default:'/' }}" class="button">{% trans 'Continue' %}</a>
</p>
{% else %}
<p>
{{ error }}
<a href="{% url 'users:login' %}">{% trans "login again" %}</a>
<a href="{% url 'users:login' %}">{% trans "Login again" %}</a>
</p>
{% endif %}
</article>
Expand Down
4 changes: 2 additions & 2 deletions users/templates/users/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
<h4>{% trans "Welcome" %}</h4>
<p>
{% blocktrans %}
{{ site_name }} is flourishing because of collaborations and contributions from users like you. Please read our <a href="/pages/terms">term of service</a>, and feel free to <a href="{{ support_link }}">contact us</a> if you have any question or feedback.
{{ site_name }} is flourishing because of collaborations and contributions from users like you. Please read our <a href="/pages/rules">rules</a>, and feel free to <a href="{{ support_link }}">contact us</a> if you have any question or feedback.
{% endblocktrans %}
</p>
<form action="{{ request.session.next_url | default:'/' }}" method="get">
<input type="submit" value="{% trans 'Cut the sh*t and get me in!' %}">
<input type="submit" value="{% trans 'Accept' %}">
</form>
</article>
</div>
Expand Down
2 changes: 1 addition & 1 deletion users/views/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b783312

Please sign in to comment.