requires_login(next='')

10 views
Skip to first unread message
Message has been deleted

annet

unread,
May 6, 2009, 1:17:44 PM5/6/09
to web2py Web Framework
In t2 you could do:

@t2.requires_login(next='login')


In tools.py

@auth.requires_login(next='../authtool/login')

doesn't work:
TypeError: requires_login() got an unexpected keyword argument 'next'

What's the equivalent of t2.requires_login(next='login') in tools.py?



In the online documentation I read:

In your controller (for example in default.py) expose the auth
object (for example via a user action)


I created a controller authtool and defined the actions like this:

def register():
return dict(form=auth.register())

def login():
return dict(form=auth.login(next='../crudtool/index'))

....


Furthermore I created a controller crudtool in which I will define
crud actions. When I expose the index function in crudtool:

@auth.requires_login()
def index():
return dict(message="hello from crudtool.py")


it redirects to: http://127.0.0.1:8000/mock/crudtool/user/login, but
there is no function user and args login. Whereas it should redirect
me to http://127.0.0.1:8000/mock/authtool/login I thought I would
solve this using the next attribute...



Kind regards,
Annet

mdipierro

unread,
May 6, 2009, 1:45:46 PM5/6/09
to web2py Web Framework
auth.settings.login_next='.....'

Massimo
> me tohttp://127.0.0.1:8000/mock/authtool/loginI thought I would
Message has been deleted

annet....@gmail.com

unread,
May 13, 2009, 4:22:41 AM5/13/09
to web2py Web Framework
Massimo,

This works:

auth.settings.login_next=URL(r=request, c='crudtool', f='index') in
db.py, when I login I am redirected to http://127.0.0.1:8000/mock/crudtool/index


But this doesn't work:

auth.settings.logout_next=URL(r=request, c='authtool', f='login') in
db.py,

in the controller authtool the function:

def logout():
return dict()

when I logout I get an invalid function error which is correct, the
address in the browser reads: http://127.0.0.1:8000/mock/authtool/user/login

this: auth.settings.login_url=URL(r=request, c='authtool', f='login')
doesn't work either.



auth.settings.... also didn't solve the problem described in my
previous post:

Furthermore I created a controller crudtool in which I will define
crud actions. When I expose the index function in crudtool:

@auth.requires_login()
def index():
return dict(message="hello from crudtool.py")

it redirects to: http://127.0.0.1:8000/mock/crudtool/user/login, but
there is no function user and args login. Whereas it should redirect
me to http://127.0.0.1:8000/mock/authtool/login I thought I would

mdipierro

unread,
May 13, 2009, 10:52:52 AM5/13/09
to web2py Web Framework
auth.settings.login_url=URL(r=request, c='crudtool', f='index')

after logout it goes to login_url, same with failed requires_login.

Massimo

On May 13, 3:22 am, annet.verm...@gmail.com wrote:
> Massimo,
>
> This works:
>
> auth.settings.login_next=URL(r=request, c='crudtool', f='index') in
> db.py, when I login I am redirected tohttp://127.0.0.1:8000/mock/crudtool/index
>
> But this doesn't work:
>
> auth.settings.logout_next=URL(r=request, c='authtool', f='login') in
> db.py,
>
> in the controller authtool the function:
>
> def logout():
>     return dict()
>
> when I logout I get an invalid function error which is correct, the
> address in the browser reads:http://127.0.0.1:8000/mock/authtool/user/login
>
> this: auth.settings.login_url=URL(r=request, c='authtool', f='login')
> doesn't work either.
>
> auth.settings.... also didn't solve the problem described in my
> previous post:
>
> Furthermore I created a controller crudtool in which I will define
> crud actions. When I expose the index function in crudtool:
>
> @auth.requires_login()
> def index():
>     return dict(message="hello from crudtool.py")
>
> it redirects to:http://127.0.0.1:8000/mock/crudtool/user/login, but
> there is no function user and args login. Whereas it should redirect
> me tohttp://127.0.0.1:8000/mock/authtool/loginI thought I would

annet....@gmail.com

unread,
May 15, 2009, 4:28:21 AM5/15/09
to web2py Web Framework
Massimo,

> auth.settings.login_url=URL(r=request, c='crudtool', f='index')
>
> after logout it goes to login_url, same with failed requires_login.


The cause of the problem laid elsewhere:


Since I customized the registration process I did not define:

def user(): return dict(form=auth())


instead I defined:

def index():
redirect(URL(r=request,f='login'))
return dict()


def login():
return dict(form=auth.login())


def logout():
return dict()


def profile():
return dict(form=auth.profile())


def change_password():
return dict(form=auth.change_password())


def retrieve_username():
return dict(form=auth.retrieve_username())


def retrieve_password():
return dict(form=auth.retrieve_password())


I noticed that in all but the logout function, a function is called on
the auth object. So, I changed the logout function to read like:

def logout():
auth.logout()
return dict()

and now logout is working.


Kind regards,

Annet.


Reply all
Reply to author
Forward
0 new messages