How to stopped redirection to user/login.html

98 views
Skip to first unread message

Patito Feo

unread,
Aug 21, 2019, 3:06:06 PM8/21/19
to web2py-users
Hi,

I have created a login.html page. I intent to redirect users to this url instead of default behavior redirecting to user/login.html.
In fact i have commented out entire user() function on controller.
Also i have,

auth.settings.login_url = URL( 'default', 'mylogin ) and auth.settings.on_failed_authentication = URL('default', 'mylogin')

But controller is still redirecting to user/login.


Any ideas?


Cheers,

Annet

unread,
Aug 22, 2019, 1:44:39 AM8/22/19
to web2py-users
What about:

auth.settings.on_failed_authentication = lambda url: redirect(url)

That is what the book says changing the default behaviour.


Kind regards,

Annet



Patito Feo

unread,
Aug 22, 2019, 7:32:02 PM8/22/19
to web2py-users
Hi,

This does not worked.
Redirecting still goes to user/login.html.

Any ideas?


Cheers,

Dave S

unread,
Aug 22, 2019, 8:01:04 PM8/22/19
to web2py-users
On Thursday, August 22, 2019 at 4:32:02 PM UTC-7, Patito Feo wrote:
Hi,

This does not worked.
Redirecting still goes to user/login.html.

Any ideas?

Cheers,


For a little more context, here's a larger quote form the book:

If the visitor is not logger in, and calls a function that requires authentication, the user is redirected to auth.settings.login_url which defaults to URL('default', 'user/login'). One can replace this behavior by redefining:


auth.settings.on_failed_authentication = lambda url: redirect(url)
This is the function called for the redirection. The argument url` passed to this function is the url for the login page.

If the visitor does not have permission to access a given function, the visitor is redirect to the URL defined by

auth.settings.on_failed_authorization =     URL('user', args='on_failed_authorization')
You can change this variable and redirect the user elsewhere.

Often on_failed_authorization is a URL but it can be a function that returns the URL and it will be called on failed authorization.


from <URL:http://web2py.com/books/default/chapter/29/09/access-control#Auth-Settings-and-messages>

Good luck!

/dps
 

Patito Feo

unread,
Aug 23, 2019, 12:27:34 AM8/23/19
to web2py-users
Hi and thanks for your answer,

I did what the manual points to do. But the redirection still points to user/login.html. In fact here is part of my config:

auth.settings.login_url = URL( 'ingreso' )
auth.settings.logged_url = URL( 'preferencias')

auth.settings.on_failed_authentication = lambda url: redirect( URL( 'ingreso' ) )


I have defined a auth custom table, is there anything Im missing?


Regards,

Patito Feo

unread,
Aug 31, 2019, 11:35:07 AM8/31/19
to web2py-users
Any suggestion?


Cheers,

Patito Feo

unread,
Sep 11, 2019, 7:40:26 PM9/11/19
to web...@googlegroups.com
Hi,

I had done tests using a new empty application and this works. 
My current application uses a customdb auth table and its using 

auth.settings.on_failed_authentication = lambda url: redirect(url)

but with custom tables settings do not apply.

This are my auth.settings: 'on_failed_authentication': <function <lambda> at 0x7ff0d5f81758>.
The setting is set correctly but still redirects to user/login.


Regards,



El jueves, 22 de agosto de 2019, 19:01:04 (UTC-5), Dave S escribió:

Patito Feo

unread,
Sep 17, 2019, 2:18:06 PM9/17/19
to web2py-users
Hi,

After many hours of desperately search i found the solution.

You dont import Auth() on any of the controllers.

#from gluon.tools import Auth
#auth = Auth(db)

So, in db.py will imported and configured it for all the app.


Regards,
Reply all
Reply to author
Forward
0 new messages