From d597f362db9012a47164369e7614fd6a2060e7e5 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 13 Oct 2014 23:41:12 -0400 Subject: [PATCH] Return to provider if user cancels login When the cancel button is hit return to the provider and eventually to the original application via return urls. Signed-off-by: Simo Sorce Reviewed-by: Patrick Uiterwijk --- ipsilon/login/common.py | 22 ++++++++++++++++++++++ templates/login/form.html | 6 +++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ipsilon/login/common.py b/ipsilon/login/common.py index cb45fd6..6cd1ca8 100755 --- a/ipsilon/login/common.py +++ b/ipsilon/login/common.py @@ -226,6 +226,8 @@ class LoginFormBase(LoginPageBase): "next_url": next_url, "username": username, "login_target": target, + "cancel_url": '%s/login/cancel?%s' % (self.basepath, + self.trans.get_GET_arg()), } context.update(kwargs) if self.trans is not None: @@ -242,6 +244,7 @@ class Login(Page): def __init__(self, *args, **kwargs): super(Login, self).__init__(*args, **kwargs) + self.cancel = Cancel(*args, **kwargs) self.first_login = None self.info = Info(self._site) @@ -279,6 +282,25 @@ class Logout(Page): return self._template('logout.html', title='Logout') +class Cancel(Page): + + def GET(self, *args, **kwargs): + + session = UserSession() + session.logout(None) + + # return to the caller if any + transdata = self.get_valid_transaction('login', **kwargs).retrieve() + if 'login_return' not in transdata: + raise cherrypy.HTTPError(401) + raise cherrypy.HTTPRedirect(transdata['login_return']) + + def root(self, *args, **kwargs): + op = getattr(self, cherrypy.request.method, self.GET) + if callable(op): + return op(*args, **kwargs) + + class LoginMgrsInstall(object): def __init__(self): diff --git a/templates/login/form.html b/templates/login/form.html index e5e5978..69a0cc7 100644 --- a/templates/login/form.html +++ b/templates/login/form.html @@ -33,7 +33,11 @@
- Cancel + {% if cancel_url %} + Cancel + {% else %} + Cancel + {% endif %} {% if next_url %} Next method {% endif %} -- 2.20.1