requires_login with registration

2 views
Skip to first unread message

DenesL

unread,
Jul 3, 2009, 11:55:42 AM7/3/09
to web2py Web Framework
In my app I have an @auth.requires_login() before most of the actions
but this only shows me a form asking for username and password (since
I have field username in auth_user table), but I would like to be able
to register a new user too instead.

It seems that I need to set auth.settings.login_form to a function
which creates the custom form. This custom form would have to bundle
two forms: one for login, one for registration.
Am I on the right track here?.

Thanks,
Denes.

mdipierro

unread,
Jul 3, 2009, 12:39:27 PM7/3/09
to web2py Web Framework
not sure.

Try

@auth.requires_login()
def register_other():
return dict(form=auth.register(next=URL(r=request,f='index')))

and see it does what you want or not.

DenesL

unread,
Jul 3, 2009, 1:35:00 PM7/3/09
to web2py Web Framework
On Jul 3, 12:39 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> not sure.
>
> Try
>
> @auth.requires_login()
> def register_other():
> return dict(form=auth.register(next=URL(r=request,f='index')))
>
> and see it does what you want or not.

Huh? you lost me there.
Where should register_other go?
It can't be just after the decorator.
I tried placing it in the same controller but I get the same form
asking for just username and password.

Denes.

mdipierro

unread,
Jul 3, 2009, 1:52:20 PM7/3/09
to web2py Web Framework
I guess I do not understand what you want to do. I was assuming you
wanted registered users (logged in) to be able to register other
users. It is asking for username and password becuase you must be
logged in to register somebody else.

DenesL

unread,
Jul 3, 2009, 1:56:36 PM7/3/09
to web2py Web Framework
I want to be able to login OR register with the form shown by
@auth.requires_login.

mdipierro

unread,
Jul 3, 2009, 2:17:51 PM7/3/09
to web2py Web Framework
def index():
form=SQLFORM(db.auth_table, fields=['email','password']
if FORM.accepts(request.vars,session):
user=session.user=auth.get_or_create_user(form.vars)
redirect(....)
return dict(form=form)

DenesL

unread,
Jul 3, 2009, 3:51:20 PM7/3/09
to web2py Web Framework
def index in my controller?

tools.login does a bunch of things based on the settings before it
gets to the form, so I feel it would be better to set
auth.settings.login_form.
What are the parameters for auth.settings.login_form?



mdipierro

unread,
Jul 3, 2009, 4:35:53 PM7/3/09
to web2py Web Framework
You need to look into the code. gluon.tools

DenesL

unread,
Jul 3, 2009, 4:58:24 PM7/3/09
to web2py Web Framework
That is what I have been doing but I am slow getting it.

Line 814 in tools.py says:
cas_user = cas.get_user()

Do I have to define a get_user function or is that a bug and it should
say
cas_user = cas.get_or_create_user()

mdipierro

unread,
Jul 3, 2009, 5:23:56 PM7/3/09
to web2py Web Framework
It is not a bug. It is a hook to create cas methods.

Look into the docstring for gluon/contrib/login_methods/
gae_google_account.py

Massimo
Reply all
Reply to author
Forward
0 new messages