Fix login so user is sent to their target page after authentication.
This commit is contained in:
parent
2762e8e072
commit
d296b5bde5
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2014 Lance Edgar
|
# Copyright © 2010-2015 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -49,11 +49,12 @@ def forbidden(request):
|
||||||
This is triggered whenever access is not allowed for an otherwise
|
This is triggered whenever access is not allowed for an otherwise
|
||||||
appropriate view.
|
appropriate view.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
msg = literal("You do not have permission to do that.")
|
msg = literal("You do not have permission to do that.")
|
||||||
if not authenticated_userid(request):
|
if not authenticated_userid(request):
|
||||||
msg += literal(" (Perhaps you should %s?)" %
|
msg += literal(" (Perhaps you should %s?)" %
|
||||||
tags.link_to("log in", request.route_url('login')))
|
tags.link_to("log in", request.route_url('login')))
|
||||||
|
# Store current URL in session, for smarter redirect after login.
|
||||||
|
request.session['next_url'] = request.current_route_url()
|
||||||
request.session.flash(msg, allow_duplicate=False)
|
request.session.flash(msg, allow_duplicate=False)
|
||||||
|
|
||||||
url = request.referer
|
url = request.referer
|
||||||
|
@ -73,7 +74,6 @@ def login(request):
|
||||||
"""
|
"""
|
||||||
The login view, responsible for displaying and handling the login form.
|
The login view, responsible for displaying and handling the login form.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
referrer = request.get_referrer()
|
referrer = request.get_referrer()
|
||||||
|
|
||||||
# Redirect if already logged in.
|
# Redirect if already logged in.
|
||||||
|
@ -89,6 +89,8 @@ def login(request):
|
||||||
request.session.flash("{0} logged in at {1}".format(
|
request.session.flash("{0} logged in at {1}".format(
|
||||||
user, localtime(request.rattail_config).strftime('%I:%M %p')))
|
user, localtime(request.rattail_config).strftime('%I:%M %p')))
|
||||||
headers = remember(request, user.uuid)
|
headers = remember(request, user.uuid)
|
||||||
|
# Treat URL from session as referrer, if available.
|
||||||
|
referrer = request.session.pop('next_url', referrer)
|
||||||
return HTTPFound(location=referrer, headers=headers)
|
return HTTPFound(location=referrer, headers=headers)
|
||||||
request.session.flash("Invalid username or password")
|
request.session.flash("Invalid username or password")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue