2017-02-09 34 views
-1

如果鍵入的用戶名或密碼錯誤一次和URL手動更改到我家GUI,我可以訪問它沒有任何身份驗證。可以通過登錄頁面與錯誤的密碼/用戶名AngularJS

我無法解釋爲什麼:/

這是我的app.js,所有的路由發生,我的控制器小提琴和我的HTML數據:

(function() { 
    'use strict'; 

    // declare modules 
    angular.module('Authentication', []); 
    angular.module('Home', ['naif.base64', 'ngFileSaver']); 

    //dependecies of the module 
    angular.module('JMeterGui', ['Authentication','Home','ngRoute', 'ngCookies']) 
    //configure the module 
    .config(config) 
    //configure the start of the module 
    .run(run); 

    //dependencies of the config module 
    config.$inject = ['$routeProvider', '$locationProvider', '$qProvider']; 
    //configure routing depends on the actual URL 
    function config($routeProvider, $locationProvider, $qProvider) { 

     $routeProvider 
      .when('/', { 
       controller: 'HomeController', 
       templateUrl: 'modules/home/views/home.html' 
      }) 

      .when('/login', { 
       controller: 'LoginController', 
       templateUrl: 'modules/authentication/views/login.html' 
      }) 

      .otherwise({ redirectTo: '/login' }); 
    } 

    //dependecies of the run module 
     run.$inject = ['$rootScope', '$location', '$cookies', '$http']; 
     function run($rootScope, $location, $cookies, $http) { 
      // keep user logged in after page refresh 
      $rootScope.globals = $cookies.getObject('globals') || {}; 
      if ($rootScope.globals.currentUser) { 
       $http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata; 
      } 

      $rootScope.$on('$locationChangeStart', function (event, next, current) { 
       // redirect to login page if not logged in 
       var restrictedPage = $.inArray($location.path(), ['/login']) === -1; 
       var loggedIn = $rootScope.globals.currentUser; 
       if (restrictedPage && !loggedIn) { 
        $location.path('/login'); 
       } 
      }); 
     } 
})() 

my fiddle with controller and html

任何人都知道這是爲什麼?

+0

您對小提琴鏈接不起作用。 – Korte

+0

@Korte對不起,我有解決它 – Kanissell

回答

0

嘗試添加:

if (restrictedPage && !loggedIn) { 
    //Prevent default 
    event.preventDefault(); 
    $location.path('/login'); 
} 
+0

首先感謝,我嘗試它,並通知你 – Kanissell

+0

喜, 我有嘗試,但仍然問題:/ – Kanissell

+0

我無法解釋的是,只有當我鍵入用戶名或密碼錯了,我可以訪問我的家桂..如果我嘗試手動更改URL,而不輸入用戶名或密碼,一切工作正常 – Kanissell

相關問題