To take advantage of the decorators at a file level, you can also do this 
at the top level of a file:

auth.requires_login()(lambda: None)()

The decorators ultimately call auth.requires, which itself returns a 
decorator. The above passes a dummy function to that decorator and then 
simply calls it.

Anthony

On Thursday, February 12, 2015 at 6:11:40 AM UTC-5, mcamel wrote:
>
> Hello,
>
> You can use @auth* decorators to force authentication to single functions, 
> but how you can force authentication to your whole application?.
>
> I use this, just after defining auth:
>
> if not auth.is_logged_in():
>     # avoid infinite recursion
>     if request.url != auth.settings.login_url:
>         # after authentication go to the intended url
>         redirect(auth.settings.login_url + '?_next=' + request.env.
> request_uri)
>
> Any better aproach?.
>
> You can also exclude certain controllers and/or functions:
>
> if not auth.is_logged_in():
>     if request.controller != 'util' and request.function != 
> 'change_language':
>         # avoid infinite recursion
>         if request.url != auth.settings.login_url:
>             # after authentication go to the intended url
>             redirect(auth.settings.login_url + '?_next=' + request.env.
> request_uri)
>
> Regards.
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to