[web2py] Re: auth for entire controller

2012-07-25 Thread Richard Penman
I mean is there a better way than something like: if not auth.has_membership('admin'): session.flash = 'You are not part of the admin group' redirect(URL(r=request, c='default', f='index')) --

[web2py] Re: auth for entire controller

2012-07-25 Thread Anthony
That looks pretty good. If you want to avoid running all your models, you can put that logic early in your models (obviously somewhere after auth is defined): if request.controller == 'secret_stuff' and not auth.has_membership('admin' ): Anthony On Wednesday, July 25, 2012 9:14:31 PM UTC-4,

Re: [web2py] Re: auth for entire controller

2012-07-25 Thread Bruno Rocha
You can do in the way anthony said, but you can do it all in models, no need to touch controller code. models/...py auth = Auth() # a dict of controllers as keys, and a list of allowed groups as values auth_rules = {

Re: [web2py] Re: auth for entire controller

2012-07-25 Thread Anthony
You can do in the way anthony said, but you can do it all in models, no need to touch controller code. Note, I did suggest moving it to a model file to avoid unnecessarily executing all the models. Anthony --

Re: [web2py] Re: auth for entire controller

2012-07-25 Thread Bruno Rocha
You can do in the way anthony said, but you can do it all in models, no need to touch controller code. Note, I did suggest moving it to a model file to avoid unnecessarily executing all the models. The redirect in: if not any(has_membership): redirect(URL(r=request, c='default',

Re: [web2py] Re: auth for entire controller

2012-07-25 Thread Anthony
The redirect in: if not any(has_membership): redirect(URL(r=request, c='default', f='index')) will not break the execution of models? Since the original code did not test for the controller, I assumed it was inserted at the top of the controller in question, which would allow all

Re: [web2py] Re: auth for entire controller

2012-07-25 Thread Richard Baron Penman
thanks for tips - yes I did have that inserted in the controller. On Thu, Jul 26, 2012 at 2:01 PM, Anthony abasta...@gmail.com wrote: The redirect in: if not any(has_membership): redirect(URL(r=request, c='default', f='index')) will not break the execution of models? Since the