1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-25 10:44:30 +01:00

adding a redirected to the originaly requested page on login

user not authenticated and requesting an url are redirected to
the signin page with the requested page url as the query string (in
base64). It permits to redirect them to the requested page once they
've log in.
This commit is contained in:
kakwa 2015-07-06 07:58:27 +02:00
parent 7241b6f8ee
commit 1f0cc50d58
2 changed files with 30 additions and 10 deletions

View File

@ -15,6 +15,7 @@ import logging
import logging.handlers import logging.handlers
from operator import itemgetter from operator import itemgetter
from socket import error as socket_error from socket import error as socket_error
import base64
from exceptions import * from exceptions import *
from ldapcherry.roles import Roles from ldapcherry.roles import Roles
@ -475,12 +476,18 @@ class LdapCherry(object):
if self.auth_mode == 'none': if self.auth_mode == 'none':
return 'anonymous' return 'anonymous'
username = cherrypy.session.get(SESSION_KEY) username = cherrypy.session.get(SESSION_KEY)
if cherrypy.request.query_string == '':
qs = ''
else:
qs = '?' + cherrypy.request.query_string
b64requrl = base64.b64encode(cherrypy.url() + qs)
if not username: if not username:
raise cherrypy.HTTPRedirect("/signin") raise cherrypy.HTTPRedirect("/signin?url=%(url)s" % {'url': b64requrl})
if not 'connected' in cherrypy.session \ if not 'connected' in cherrypy.session \
or not cherrypy.session['connected']: or not cherrypy.session['connected']:
raise cherrypy.HTTPRedirect("/signin") raise cherrypy.HTTPRedirect("/signin?url=%(url)s" % {'url': b64requrl})
if cherrypy.session['connected'] and \ if cherrypy.session['connected'] and \
not cherrypy.session['isadmin']: not cherrypy.session['isadmin']:
if must_admin: if must_admin:
@ -492,8 +499,7 @@ class LdapCherry(object):
cherrypy.session['isadmin']: cherrypy.session['isadmin']:
return username return username
else: else:
raise cherrypy.HTTPRedirect("/signin") raise cherrypy.HTTPRedirect("/signin?url=%(url)s" % {'url': b64requrl})
def _adduser(self, params): def _adduser(self, params):
cherrypy.log.error( cherrypy.log.error(
@ -700,13 +706,13 @@ class LdapCherry(object):
return ret return ret
@cherrypy.expose @cherrypy.expose
def signin(self): def signin(self, url=None):
"""simple signin page """simple signin page
""" """
return self.temp_login.render() return self.temp_login.render(url=url)
@cherrypy.expose @cherrypy.expose
def login(self, login, password): def login(self, login, password, url=None):
"""login page """login page
""" """
auth = self._auth(login, password) auth = self._auth(login, password)
@ -727,7 +733,11 @@ class LdapCherry(object):
severity = logging.INFO severity = logging.INFO
) )
cherrypy.session[SESSION_KEY] = cherrypy.request.login = login cherrypy.session[SESSION_KEY] = cherrypy.request.login = login
raise cherrypy.HTTPRedirect("/") if url is None:
redirect = "/"
else:
redirect = base64.b64decode(url)
raise cherrypy.HTTPRedirect(redirect)
else: else:
message = "login failed for user '%(user)s'" % { message = "login failed for user '%(user)s'" % {
'user': login 'user': login
@ -736,7 +746,11 @@ class LdapCherry(object):
msg = message, msg = message,
severity = logging.WARNING severity = logging.WARNING
) )
raise cherrypy.HTTPRedirect("/signin") if url is None:
qs = ''
else:
qs = '?url=' + url
raise cherrypy.HTTPRedirect("/signin" + qs)
@cherrypy.expose @cherrypy.expose
def logout(self): def logout(self):

View File

@ -4,7 +4,13 @@
<div class="row clearfix" style="margin-top:30px"> <div class="row clearfix" style="margin-top:30px">
<div class="col-md-4 column"></div> <div class="col-md-4 column"></div>
<div class="col-md-4 column well"> <div class="col-md-4 column well">
<form method='POST' action='/login' role="form" class="form-signin"> <%
if url is None:
qs=''
else:
qs='?url=' + url
%>
<form method='POST' action='/login${qs}' role="form" class="form-signin">
<div class="form-group"> <div class="form-group">
<h2 class="form-signin-heading">Please sign in</h2> <h2 class="form-signin-heading">Please sign in</h2>
<div class="input-group"> <div class="input-group">