How to check current user role?

1
I need to check if the current user is an anonymous guest or registered local user. I created a variable to store the current user name and retrieved an object of the User entity with the same name. So now I have a current user User object. How can I check its role?  I tried this way, but how should I finish the expression?  
asked
3 answers
2

Hi Maxim,

You can check the user role in retrieve action, see the screenshot below for example

 

Hope this helps!

answered
1

Hi Maxim, 

For your question, how to check if the user is anonymous.

After retrieving the User, check for the boolean IsAnonymous.

All anonymous users will have this boolean set to true.

If you want to retrieve all roles of the user, use the association “UserRoles” from User entity. 

BTW, I see that you are using DB calls to retrieve the User. This is not needed. You can use $currentUser which is already a System.User entity. From $currentuser you can also access associations. You could save one database call, as database calls are always costly (performance wise).

Regards,

Nirmal

answered
0

I want to acess the list of  registered user from system, how can I get this! 

answered