Hi,
I have an angular controller controlling a dasboard in the back office. I would like to show/hide a button if the currently logged in user is in the administrator role. Is there an umbraco js service that does this already?
There is a userService, which you can use. It has a method called getCurrentUser()...
So inject the userService into your controller and then call it like this
var getCurrentUser = userService.getCurrentUser().then(function(userObj){
var user = userObj;
$scope.currentUser = user.id;
});
I Can't remember if this actually returns the user role but if it's only the root admin account you need to check for then you can use id as shown in the example and check whether the user id is 0 or not.
Yeah, not everything is documented at the old belle site and it does not seem like it has been moved into the documentation section of our yet - So sometimes the way forward is to have a look at the Umbraco source code to get some ideas.
How to get user roles in Angular Controller?
Hi, I have an angular controller controlling a dasboard in the back office. I would like to show/hide a button if the currently logged in user is in the administrator role. Is there an umbraco js service that does this already?
I'm looking to do something like this...
then in the view I can...
Anyone done something like this before?
Thnx
Hi Louis
There is a userService, which you can use. It has a method called getCurrentUser()...
So inject the userService into your controller and then call it like this
I Can't remember if this actually returns the user role but if it's only the root admin account you need to check for then you can use id as shown in the example and check whether the user id is 0 or not.
Hope this helps a bit.
/Jan
Awesome!
That did the trick! I did search the Belle docs but did not find anything that looks like a user service tho'... anyway, it works.
Thank you Jan
Hi Louis
Happy to hear that :)
Yeah, not everything is documented at the old belle site and it does not seem like it has been moved into the documentation section of our yet - So sometimes the way forward is to have a look at the Umbraco source code to get some ideas.
Happy coding!
/Jan
is working on a reply...