replaced stateChangeStart with transitions.onStart in Admin UI
parent
fd37fd53aa
commit
8697c66c67
|
@ -8,12 +8,26 @@
|
||||||
*/
|
*/
|
||||||
app
|
app
|
||||||
.run([
|
.run([
|
||||||
'$rootScope', '$state', '$stateParams',
|
'$rootScope', '$state', '$transitions', '$location', '$window',
|
||||||
function ($rootScope, $state, $stateParams) {
|
function ($rootScope, $state, $transitions, $location, $window) {
|
||||||
$rootScope.$state = $state;
|
$rootScope.$state = $state;
|
||||||
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
|
$transitions.onStart( { }, function(trans) {
|
||||||
$rootScope.$emit('handleStateChange', toState.data.pageTitle);
|
if ($location.$$path.indexOf('login')==-1) {
|
||||||
});
|
var currentUser = undefined;
|
||||||
|
if ($window.localStorage.getItem("currentUser")){
|
||||||
|
currentUser = JSON.parse($window.localStorage.getItem("currentUser"));
|
||||||
|
}
|
||||||
|
console.log(currentUser);
|
||||||
|
console.log(currentUser == undefined);
|
||||||
|
console.log(currentUser.is_admin === false);
|
||||||
|
if (currentUser == undefined || currentUser.is_admin === false) {
|
||||||
|
$window.localStorage.removeItem("currentUser");
|
||||||
|
return $state.target("login.login");
|
||||||
|
} else {
|
||||||
|
$rootScope.pageTitle = trans.to().data.pageTitle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
.config(
|
.config(
|
||||||
|
|
|
@ -2,34 +2,7 @@
|
||||||
app.controller('MainController', [
|
app.controller('MainController', [
|
||||||
'$rootScope', '$location', '$window', '$timeout','$cookies',
|
'$rootScope', '$location', '$window', '$timeout','$cookies',
|
||||||
function($rootScope, $location, $window, $timeout,$cookies) {
|
function($rootScope, $location, $window, $timeout,$cookies) {
|
||||||
$rootScope.$on("handleStateChange",function(event,args){
|
|
||||||
var cur_path = $location.$$path;
|
|
||||||
if (cur_path.indexOf('login')==-1) {
|
|
||||||
var admin_path = ["settings", "users", "fdd/rule"];
|
|
||||||
var req_admin = false;
|
|
||||||
admin_path.forEach(function(elm){
|
|
||||||
if (cur_path.indexOf(elm) !=-1) {
|
|
||||||
req_admin = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (req_admin) {
|
|
||||||
var currentUser = undefined;
|
|
||||||
if ($window.localStorage.getItem("currentUser")){
|
|
||||||
currentUser = JSON.parse($window.localStorage.getItem("currentUser"));
|
|
||||||
}
|
|
||||||
if (currentUser != undefined && currentUser.is_admin ==true) {
|
|
||||||
$rootScope.pageTitle=args;
|
|
||||||
}else{
|
|
||||||
$window.localStorage.removeItem("currentUser");
|
|
||||||
$location.path('/login');
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
$rootScope.pageTitle=args;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$rootScope.$on("handleReLogin",function(){
|
$rootScope.$on("handleReLogin",function(){
|
||||||
$timeout(function(){
|
$timeout(function(){
|
||||||
$window.localStorage.removeItem("currentUser");
|
$window.localStorage.removeItem("currentUser");
|
||||||
|
|
Loading…
Reference in New Issue