Dashboard login based on user's permissions.
-
I would like to set user's permissions in custom dashboards (the same used at datapoints/datasources). So if user's permissions doesn't match dashboard permissions it will redirect to login page. I believe it should be a directive, but I don't know how to implement it.
-
Hey tomi, I can help you with this. What template did you start with?
-
Hello Jared, thank you. I am using Admin Template.
-
Make these changes in app.js
Around line 40:
auth: ['$rootScope', 'User', function($rootScope, User) { // retrieves the current user when we navigate to a dashboard page // if an error occurs the $stateChangeError listener redirects to the login page $rootScope.user = User.current(); return $rootScope.user.$promise.then(function(user) { if (!user.hasPermission('my-permission')) { throw 'Wrong permission'; } return user; }); }],
Around line 221
// redirect to login page if we can't retrieve the current user when changing state $rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) { if (error && (error.status === 401 || error.status === 403 || error === 'Wrong permission')) { event.preventDefault(); $state.loginRedirect = toState; $state.go('login'); } });
-
Thank you Jared, it works smoothly.
Also, I would like to redirect to the dashboard login page after user click on logout button. Currently it goes to the default Mango login page.
-
You should be able to control that from the system setting. Here is a screenshot of mine. Setting the Login page url should do this for you.
-
@JoelHaggar Thanks Joel, I did that, but I have 2 different dashboards, so I would like to go to the login page of the dashboard which I am leaving.