Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect people to intended destination after login #872

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion TWLight/templates/login_partial.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<div class="row">
<div class="col-lg-6 col-md-12 col-sm-12 homepage-login">
{% comment %}Translators: Button that logs editors in via Wikipedia.{% endcomment %}
<a class="btn btn-lg btn-light homepage-login-button" href="{% url 'oauth_login' %}?next={% url 'users:my_library' %}&from_homepage=true">
<a class="btn btn-lg btn-light homepage-login-button" href="{% url 'oauth_login' %}?next={{ next_url }}&from_homepage=true">
{% trans "Login via Wikipedia" %}
</a>
</div>
Expand Down
9 changes: 7 additions & 2 deletions TWLight/users/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,13 @@ def get(self, request, *args, **kwargs):
_("To view this link you need to be an eligible library user. Please login to continue."),
# fmt: on
)

local_redirect = reverse_lazy("homepage")
if return_url:
homepage = reverse_lazy("homepage")
local_redirect = "{homepage}?next_url={return_url}".format(
homepage=homepage, return_url=return_url
)
else:
local_redirect = reverse_lazy("homepage")

logger.info("handshaker initiated.")
self.request.session["request_token"] = _dehydrate_token(request_token)
Expand Down
6 changes: 6 additions & 0 deletions TWLight/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.db.models import Q
from django.http import HttpResponse, HttpResponseBadRequest
from django.shortcuts import render, redirect
from django.urls import reverse_lazy
from django.utils.translation import get_language, gettext_lazy as _
from django.template import TemplateDoesNotExist, loader
from django.views.decorators.csrf import requires_csrf_token
Expand Down Expand Up @@ -108,6 +109,11 @@ def get_context_data(self, **kwargs):
}
)
context["partners"] = partners_obj
param_next_url = self.request.GET.get("next_url", None)
if param_next_url:
context["next_url"] = param_next_url
else:
context["next_url"] = reverse_lazy("users:my_library")

return context

Expand Down