changing default redirect after failed login attempt.

280 views
Skip to first unread message

Chris Steel

unread,
Nov 10, 2011, 3:45:13 AM11/10/11
to web2py-users
Everything seems to work with the following set up except for when
signing on with an incorrect password in which case the user gets
directed to "default/user/login" instead of
"plugin_user_admin/user/login".

Basically I have moved the user function into a different controller
along with the corresponding view.

Here is the setup as it is:

views/layout.html - edited the auth nav bar as follows:

{{try:}}{{=auth.navbar(action=URL('plugin_user_admin','user'))}}{{except:pass}}

controllers/plugin_user_admin.py

My user function is now in this controller instead of the default controller.

views/plugin_user_admin/user.html

My user view is now in the corresponding view.

When a user types an incorrect password they get redirected to
default/user and get the message "invalid function (default/user)"

I tried setting auth.settings.login_url = URL('user', args='login')
to be:

auth.settings.login_url = URL('plugin_user_admin', 'user', args='login')

...in db.py but it does not have any effect on the redirect after a
failed login attempt.

Does anyone know a way to overide the default redirect URL on a failed
login to be the new location of my user function or get this working
some other way?

Thanks
--

Chris

Bruno Rocha

unread,
Nov 10, 2011, 3:54:50 AM11/10/11
to web...@googlegroups.com
In Auth class we have:

settings.on_failed_authentication = lambda x: redirect(x)

so try

auth.settings.on_failed_authentication = redirect(URL(.....))


--

Bruno Rocha

unread,
Nov 10, 2011, 3:58:27 AM11/10/11
to web...@googlegroups.com
forget about it, it needs to be a lambda because of:

return call_or_redirect(
                                self.settings.on_failed_authentication,
                                self.settings.login_url+\
                                    '?_next='+urllib.quote(next))

it says that should be redirected to self.settings.login_url

Christopher Steel

unread,
Nov 10, 2011, 9:56:07 AM11/10/11
to web...@googlegroups.com
Ah ha!

This works like a charm, makes sense

auth.settings.controller = 'plugin_user_admin'

David Orme

unread,
Aug 10, 2020, 9:03:04 AM8/10/20
to web2py-users
Just to note that I had a similar fix to make and I think this solution is flawed:
 
auth.settings.controller = 'plugin_user_admin'

It's exactly the right setting, but initialising an Auth instance uses `settings.controller` to  initialise a whole bunch of links and I don't think these get updated if you alter the setting after the event. You can specify the controller when you create the Auth instance, and then the controller is used throughout the setup

auth = Auth(db, 
            host_names=configuration.get('host.names'),
            controller='plugin_user_admin')


Reply all
Reply to author
Forward
0 new messages