2015-07-03 01:14:48 +00:00
|
|
|
// 'use strict';
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2015-07-03 01:14:48 +00:00
|
|
|
// angular.module('users').factory('Authorization', ['$rootScope', '$http', '$q', '$state', 'Principal',
|
|
|
|
// function($rootScope, $http, $q, $state, Principal) {
|
|
|
|
// var service = {
|
|
|
|
// authorize: function(){
|
|
|
|
// var deferred = $q.defer();
|
|
|
|
// $http.get('/user/me').success(function(response) {
|
2015-06-30 06:12:32 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2015-07-03 01:14:48 +00:00
|
|
|
// //user is logged in
|
|
|
|
// if(response.data !== null){
|
|
|
|
// deferred.resolve();
|
|
|
|
// }else {
|
|
|
|
// $rootScope.message = 'You need to log in.';
|
|
|
|
// deferred.reject();
|
|
|
|
// $state.go('/login');
|
|
|
|
// }
|
2015-06-30 06:12:32 +00:00
|
|
|
|
2015-07-03 01:14:48 +00:00
|
|
|
// });
|
|
|
|
// return deferred.promise();
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// return service;
|
|
|
|
// // 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-07-03 01:14:48 +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-07-03 01:14:48 +00:00
|
|
|
// // // now, send them to the signin state so they can log in
|
|
|
|
// // $location.path('/signin');
|
|
|
|
// // }
|
|
|
|
// // // }
|
|
|
|
// // }
|
|
|
|
// // });
|
|
|
|
// // };
|
|
|
|
// }
|
|
|
|
// ]);
|