role_names = ["admin","supervisor","auditor"]
@auth_requires(any( auth.has_membership(role) for role in role_names) ) ]
ALLOWED = set(('admin', 'contributor'))
@auth.requires(lambda: auth.user_id and ALLOWED & set(auth.user_groups.values()))
request = current.request
session = current.session
auth = session.auth
self.user_groups = auth and auth.user_groups or {}
Then all data about auth.* using "session data"
Reference:
https://github.com/web2py/web2py/blob/master/gluon/tools.py#L1805
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
and yes, using a lambda makes that piece of code execute only when that decorated function is called rather than every time the controller is hit.
--
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+unsubscribe@googlegroups.com.
i assume the same thing goes to auth.user vs auth.is_logged_in(), auth.user faster than auth.is_logged_in() because auth.user didn't hit the database, isnt it?
if self.user:
return True
return False
--
auth.has_membership(group_id, user_id, role)
The doc are here:
http://web2py.com/books/default/chapter/29/09/access-control#Authorization
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.