Baghera
Baghera

Reputation: 53

web2py How to know a user is logged in as admin

I can use the application's auth, but here I would like to know if the user is logged in as admin (which is required to access the application's appadmin controller), whether he's logged into the application or not.

Upvotes: 2

Views: 762

Answers (1)

Anthony
Anthony

Reputation: 25536

To check whether the user of a given application is also currently logged into the "admin" app (which is required in order to access the "appadmin" controller of any application), you can use check_credentials:

from gluon import fileutils
is_logged_into_admin = fileutils.check_credentials(request)

To use this with the Auth.requires decorator, you can do:

@auth.requires(lambda: fileutils.check_credentials(request))
def myfunction():

Upvotes: 1

Related Questions