Skip to content

Instantly share code, notes, and snippets.

@dsauerbrun dsauerbrun/.js Secret
Created Oct 24, 2016

Embed
What would you like to do?
app.run(function($rootScope, $state, Session, $http, helperService) {
$rootScope.$on('$stateChangeStart', function(e, to, toParams, fromState, fromParams) {
console.log(to,'wewe');
if (!to.data) {
return null;
} else {
$http.get('/api/profile')
.then(function(user) {
console.log(to.data.needAgentPlus, !helperService.isAgentPlus(user.data.userRoles));
if ((to.data.needAdmin && !helperService.isAdmin(user.data.userRoles)) ||
(to.data.needAgentPlus && !helperService.isAgentPlus(user.data.userRoles)) ||
(to.data.needTranslator && !helperService.isTranslator(user.data.userRoles))) {
e.preventDefault();
if (Session.userRoles.length == 1 && $rootScope.isTranslator) {
$state.go('user.translations');
} else {
$state.go('user.dashboard');
}
}
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.