groups and access control

48 views
Skip to first unread message

Joe Lwe

unread,
Oct 11, 2016, 9:54:48 PM10/11/16
to web2py-users
Hello,
a)How can i specify automatic group assignment on creation of user based on a particular condition.
Consider, on signup form a user can select if he is registering as a business or an individual..
if user selects business account is automatically assigned group business
else assigned to individual group.

b)how can i enforce group access control on forms/tables.. i have seen e.g
@auth.requires_login()
def function ():
form = crud(db.tablename, next = '')
return dict(form=form)

based on the above its like anyone who can login  will have access to the function.

Thanks those above are troubling me.. thanks so much for your help.. (am a newbie i like web2py thx for your efforts in the project)

Marlysson Silva

unread,
Oct 13, 2016, 6:50:33 AM10/13/16
to web2py-users
Here have some methods to manage users arround groups:

http://web2py.com/books/default/chapter/29/09/access-control#Authorization

Specially method :


auth.add_membership(group_id, user_id)
That add a user to the group , then you search the group, if ( business and individual ) , then make a "if" ,checking the choice and insert.
Message has been deleted

Marlysson Silva

unread,
Oct 13, 2016, 6:53:32 AM10/13/16
to web2py-users
B) To verify user permission use these decorators , using membership or permission decorators.


Em terça-feira, 11 de outubro de 2016 22:54:48 UTC-3, Joe Lwe escreveu:

Joe Lwe

unread,
Oct 23, 2016, 6:10:32 AM10/23/16
to web...@googlegroups.com
Thanks so much Silva,
I have declared the code below in default.py

auth.add_group('induvidual', 'induvidual group')
auth.add_group('non_induvidual','induvidual')

if db(db.auth_user.account_type == 'Non Induvidual'):
    auth.add_membership(non_induvidual, user_id)
elif db(db.auth_user.account_type =='Induvidual'):
    auth.add_membership(induvidual, user_id)




Thanks again
Reply all
Reply to author
Forward
0 new messages