2015-06-30 07:28:29 +00:00
|
|
|
// 'use strict';
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2015-06-30 07:28:29 +00:00
|
|
|
// angular.module('users').service('Authorization', ['$rootScope', '$location', 'Principal',
|
|
|
|
// function($rootScope, $location, Principal) {
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2015-06-30 07:28:29 +00:00
|
|
|
// this.authorize = function() {
|
|
|
|
// return Principal.identity().then(function(){
|
|
|
|
// var isAuthenticated = Principal.isAuthenticated();
|
|
|
|
// if( angular.isDefined($rootScope.toState.data) ){
|
|
|
|
// // if ($rootScope.toState.data.roles && $rootScope.toState.data.roles.length > 0 && !principal.isInAnyRole($rootScope.toState.data.roles)) {
|
|
|
|
// if (!isAuthenticated){ //$location.path('/access_denied'); // user is signed in but not authorized for desired state
|
|
|
|
// // console.log('isAuthenticated: '+isAuthenticated);
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2015-06-30 07:28:29 +00:00
|
|
|
// // else {
|
|
|
|
// // user is not authenticated. so the state they wanted before you
|
|
|
|
// // send them to the signin state, so you can return them when you're done
|
|
|
|
// $rootScope.returnToState = $rootScope.toState;
|
|
|
|
// $rootScope.returnToStateParams = $rootScope.toStateParams;
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2015-06-30 07:28:29 +00:00
|
|
|
// // now, send them to the signin state so they can log in
|
|
|
|
// $location.path('/signin');
|
|
|
|
// }
|
|
|
|
// // }
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// };
|
|
|
|
// }
|
|
|
|
// ]);
|