Back to All

Custom Pages > How to access information about the current user

(edited)

Question

How can I access information about the currently logged-in user on a custom admin page?

Answer

With Angularjs, you can inject the adminService and use the getInfo() function to get an object containing details about the current user.

(function ()
{
	module.controller( 'MyCustomController', MyCustomController );
	MyCustomController.$inject = ['$scope', '$log', '$http', 'adminService'];
	function MyCustomController( $scope, $log, $http, adminService)
	{
      adminService.getInfo().then(function(res) {
      	console.log(res.data);
      });
	}
} )();

Here we create a new controller called MyCustomController and specify to angular to include adminService in the injections. Once inside the controller function, we can then call adminService.getInfo() to get the http promise. The res object is the response, and the data about the user is in res.data. The structure of this data looks like this:

{
    "BannerHtml": null,
    "DataPoints": [...],
    "Settings": { ... },
    "User": {
        "FirstName": "Joe",
        "Id": 123456,
        "IsDiscoUser": true,
        "LastName": "Schmoe",
        "RoleId": 100,
        "Username": "myUserName"
    },
    "Permissions": ["ACTIVITY_LOG_VIEW", ... ]
}

The data.User object contains details related explicitly to the logged-in user, such as username, first and last name, and role ID.