How can I protect the entire controller to be available only for logged in users? Something like @auth.requires_login() but for the entire controller instead of each method ?
--
---
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
redirect( ... )put the logic on top of controller file:if not auth.is_logged_in():
# At the top of the controller
auth.requires_login()(lambda: None)()
On Wednesday, July 24, 2013 7:56:48 AM UTC-4, Marin Pranjić wrote:
redirect( ... )put the logic on top of controller file:if not auth.is_logged_in():
Or if you want to get the automatic redirect and messaging behavior of the @auth.requires_login() decorator, you can use this trick:
# At the top of the controller
auth.requires_login()(lambda: None)()
auth.requires_login() returns a decorator that takes a function and returns another function -- above just passes a dummy lambda function to the decorator and then calls the resulting function to run the requires_login code. Works with the other Auth decorators as well (all of which ultimately call auth.requires(), which is the method that produces the decorator).Anthony--
Anthony, what the advantage of that over @auth.requires_login() ??
Anthony