From 9fdb586d035a12991e2063c3cf65b7f071a3e0d5 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Mon, 15 Apr 2013 10:06:25 -0500 Subject: [PATCH] auth.requires_login() and ajax - don't force just 401, thanks Anthony --- VERSION | 2 +- applications/admin/static/css/web2py.css | 1 + applications/examples/static/css/web2py.css | 1 + applications/welcome/static/css/web2py.css | 1 + gluon/tools.py | 12 +++++++++--- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index 869b3746..b4a21b07 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.4.6-stable+timestamp.2013.04.12.23.32.51 +Version 2.4.6-stable+timestamp.2013.04.15.10.05.39 diff --git a/applications/admin/static/css/web2py.css b/applications/admin/static/css/web2py.css index 7bcc151d..2073b995 100644 --- a/applications/admin/static/css/web2py.css +++ b/applications/admin/static/css/web2py.css @@ -191,6 +191,7 @@ div.error { .web2py_grid {width:100%} .web2py_grid table {width:100%} .web2py_grid tbody td {padding:2px 5px 2px 5px; vertical-align: middle;} +.web2py_grid .web2py_form td {vertical-align: top;} .web2py_grid thead th,.web2py_grid tfoot td { background-color:#EAEAEA; diff --git a/applications/examples/static/css/web2py.css b/applications/examples/static/css/web2py.css index 7bcc151d..2073b995 100644 --- a/applications/examples/static/css/web2py.css +++ b/applications/examples/static/css/web2py.css @@ -191,6 +191,7 @@ div.error { .web2py_grid {width:100%} .web2py_grid table {width:100%} .web2py_grid tbody td {padding:2px 5px 2px 5px; vertical-align: middle;} +.web2py_grid .web2py_form td {vertical-align: top;} .web2py_grid thead th,.web2py_grid tfoot td { background-color:#EAEAEA; diff --git a/applications/welcome/static/css/web2py.css b/applications/welcome/static/css/web2py.css index 7bcc151d..2073b995 100644 --- a/applications/welcome/static/css/web2py.css +++ b/applications/welcome/static/css/web2py.css @@ -191,6 +191,7 @@ div.error { .web2py_grid {width:100%} .web2py_grid table {width:100%} .web2py_grid tbody td {padding:2px 5px 2px 5px; vertical-align: middle;} +.web2py_grid .web2py_form td {vertical-align: top;} .web2py_grid thead th,.web2py_grid tfoot td { background-color:#EAEAEA; diff --git a/gluon/tools.py b/gluon/tools.py index 23099284..1128e20a 100644 --- a/gluon/tools.py +++ b/gluon/tools.py @@ -1183,6 +1183,14 @@ class Auth(object): # ## these are messages that can be customized messages = self.messages = Messages(current.T) messages.update(Auth.default_messages) + messages.update(ajax_failed_authentication=DIV(H4('NOT AUTHORIZED'), + 'Please ', + A('login', + _href=self.settings.login_url + + ('?_next=' + urllib.quote(current.request.env.http_web2py_component_location)) + if current.request.env.http_web2py_component_location else ''), + ' to view this content.', + _class='not-authorized alert alert-block')) messages.lock_keys = True # for "remember me" option @@ -2948,7 +2956,7 @@ class Auth(object): if requires_login: if not user: if current.request.ajax: - raise HTTP(401) + raise HTTP(401, self.messages.ajax_failed_authentication) elif not otherwise is None: if callable(otherwise): return otherwise() @@ -2956,8 +2964,6 @@ class Auth(object): elif self.settings.allow_basic_login_only or \ basic_accepted or current.request.is_restful: raise HTTP(403, "Not authorized") - elif current.request.ajax: - return A('login', _href=self.settings.login_url) else: next = self.here() current.session.flash = current.response.flash