extend login method of Auth class

213 views
Skip to first unread message

reyelts

unread,
Feb 16, 2010, 12:37:40 AM2/16/10
to web2py-users
I'd like to extend the login method of the Auth class to do a couple
of initialization things based on the login. Based on what I've been
reading, it looks like I *should* be able to do something like this:

from gluon.tools import *

class MyAuth(Auth):
def login(
self,
next=None,
onvalidation=None,
onaccept=None,
log=None,
):

Auth.login(self,next,onvalidation,onaccept,log)

if self.environment.session.auth:
self.environment.session.blah = somevalue

auth=MyAuth(globals(),db) # authentication/
authorization

Of course, my "something like this" doesn't work. What's the correct
way to do this?

Thanks in advance...

mdipierro

unread,
Feb 16, 2010, 1:41:02 AM2/16/10
to web2py-users
It is simpler that that

def mystuff(form): do_something_with(form.vars)

auth.settings.login_onaccept=mystuff

reyelts

unread,
Feb 16, 2010, 11:59:39 AM2/16/10
to web2py-users
Thanks... it's a beautiful thing.
Sorry I didn't see that in the doc... I clearly wasn't searching on
the right keywords.

reyelts

unread,
Feb 16, 2010, 12:41:35 PM2/16/10
to web2py-users
Hmm... I stumbled on a headscratcher that took a while to figure out.
When I use the register function to create a new user, that user is
automatically logged in. But, auth.settings.login_onaccept was never
invoked. I would have expected one of the following:

A) The auth.settings.login_onaccept function is invoked in addition to
auth.settings.register_onaccept because the register function
automatically logs me in.

B) The register function does not automatically log me in but instead
redirects to the login page for me to supply my new login info (and
consequently get auth.settings.login_onaccept invoked along the way).

or

C) The documentation for auth.settings.login_onaccept makes clear the
fact that it does not apply to the automatic login that happens at
registration time. This way we know we need to duplicate
auth.settings.login_onaccept in auth.settings.register_onaccept.

mdipierro

unread,
Feb 16, 2010, 12:48:28 PM2/16/10
to web2py-users
It should be B is you require email verification. Need to update the
docs.
Reply all
Reply to author
Forward
0 new messages