handle next url parameter in login

This commit is contained in:
simon 2021-10-22 12:01:30 +07:00
parent 01ccca16e4
commit 825ebd874e
2 changed files with 5 additions and 1 deletions

View File

@ -29,6 +29,7 @@
{% for field in form %}
{{ field }}<br>
{% endfor %}
<input type="hidden" name="next" value="{{ request.GET.next }}" />
<button type="submit">Login</button>
</form>
<p class="login-links"><span><a href="https://github.com/bbilly1/tubearchivist" target="_blank">Github</a></span> <span><a href="https://github.com/bbilly1/tubearchivist#donate" target="_blank">Donate</a></span></p>

View File

@ -161,10 +161,13 @@ class LoginView(View):
"""handle login post request"""
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("/")
return redirect("login")
@staticmethod
def read_config():