2017-02-09 26 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

相关问题