Redirect to different pages depending on memebership

53 views
Skip to first unread message

Cristina Sig

unread,
Oct 30, 2019, 8:51:34 PM10/30/19
to web2py-users
Hi everyone,

I have two different memberships. One is 'Admin' and the other one is 'Schools' and what I want to do is redirect to different index pages depending if I'm login as Admin or as School.
This is my try:

Default.py
def check_membership():
   
if auth.has_membership(group_id='administrador'):
        redirect
(URL('default', 'indexAdmin'))
    elseif
:   
        redirect(URL('default', 'indexSchool'))


@auth.requires('check_membership')
def index():
   
return dict(message=T("Welcome!"))

It didn't work at all, so any suggestions how to achieve that?

Thanks!!

Ruslan Gareev

unread,
Oct 30, 2019, 10:15:37 PM10/30/19
to web2py-users
Hi, try:
@auth.requires(lambda: check_membership())
def index():
   
...your code...



четверг, 31 октября 2019 г., 5:51:34 UTC+5 пользователь Cristina Sig написал:

Cristina Sig

unread,
Oct 30, 2019, 11:57:39 PM10/30/19
to web2py-users
I tried your suggestion but it doesn't work.
It keeps loading the index page and doesn't allow me to see the login page.

Ruslan Gareev

unread,
Oct 31, 2019, 2:50:16 AM10/31/19
to web...@googlegroups.com
maybe make this?

@auth.requires_login()
def index():
   
if auth.has_membership(group_id='administrador'):

        redirect
(URL('default', 'indexAdmin'))

    else
:    

        redirect(URL('default', 'indexSchool'))

@auth.requires_membership(role="administrador")
def indexAdmin():
    ...your_code...

@auth.requires_login()
def indexSchool():
   ...your code...




четверг, 31 октября 2019 г., 8:57:39 UTC+5 пользователь Cristina Sig написал:

Cristina Sig

unread,
Oct 31, 2019, 4:33:07 PM10/31/19
to web2py-users
This works!!

Thank you so much
Reply all
Reply to author
Forward
0 new messages