If I use your if statement in my controller, this is the error I get <type 'exceptions.AttributeError'> 'Auth' object has no attribute 'user_groups'
why?? On Monday, June 2, 2014 3:13:26 PM UTC+2, Michael Beller wrote: > > If the user is logged in, then auth.user_groups contains a dictionary of > the user's roles. You can also use auth.has_membership('role name') to > check membership. > > You can search auth.user_groups for a role, e.g., > if any (role in ['customer_service', 'admin'] for role in auth.user_groups > .itervalues()): > > On Monday, June 2, 2014 8:53:55 AM UTC-4, Yebach wrote: >> >> Hello >> >> I am trying to get user's role looking into membership table etc. >> >> Following all the codes on majority of forums my code does not work. >> >> this is my controller >> >> from gluon.tools import Auth >> >> database = request.cookies['mycookie'].value >> db = DAL('postgres://postgres:postg...@195.xxx.yyy.zzz/' + database, >> migrate=False) >> auth = Auth(db) >> >> def index(): >> if not auth.is_logged_in(): >> >> login_adress= auth.settings.login_url = URL('user','user', >> args='login') >> redirect (login_adress) >> >> print auth.user_id ###Works >> >> print auth.user_group ### result is <bound method Auth.user_group of >> <gluon.tools.Auth object at 0x000000000A307F28>> >> print auth.has_membership(auth.id_group('Member'),auth.user.id) >> >> <type 'exceptions.AttributeError'> 'NoneType' object has no attribute >> 'role' >> >> Also, If I try with some DAL select sentances none of them work. error is >> usually >> >> if code is >> rows = db(db.auth_user).select() >> >> or >> >> rows = db((db.auth_user.email == >> auth.user.email)&(db.auth_membership.user_id == auth.user_id)&( >> db.auth_group.id==db.auth_membership.group_id)).select(db.auth_group.ALL) >> >> error is >> >> <type 'exceptions.KeyError'> 'auth_user' >> >> what am I doing wrong here. It is a f#"$"# simple ask. Get user role so I >> can get a user a specific view based on that role (btw any suggestions on >> that would be nice). >> >> thank you >> > -- 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.