auth.requires_login() and ajax - don't force just 401, thanks Anthony

This commit is contained in:
mdipierro
2013-04-15 10:06:25 -05:00
parent 448c398341
commit 9fdb586d03
5 changed files with 13 additions and 4 deletions
+1 -1
View File
@@ -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
+1
View File
@@ -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;
@@ -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;
@@ -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;
+9 -3
View File
@@ -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