2016-11-08 5 views
0

AngularJSとSpring Securityを使用すると、認証が失敗したときにログインページにerror=trueでリダイレクトされます。ログインページ(AngularJS)にこのエラーを表示する必要があります。私はこれをする方法を知らない。関連付けられたエラーを取得してログインページに表示することができません

以下

ssecurity-context.xmlauthentication-failure-urlの宣言です:

<security:form-login login-page="/login" 
       login-processing-url="/authenticate" 
       authentication-failure-url="/login?error=true" 
       username-parameter="username" password-parameter="password"/> 

いくつかのエラーを取得し、ログインページに表示する方法を教えていただけますか?

JS

angular.module('app.services') 
.service('AuthenticateService'‌​,['$http','$location‌​',function($http,$lo‌​cation) 
{ 
    return 
     {  
     login : function(uname, pword) 
       { 
       var data = "username="+uname+"&password="+pword; 
       return $http.post("authenticate",data, 
         { 
          headers: { "Content-Type": "application/x-www-form-urlencoded" } }) 
          .then(function (response) 
          { 
          console.log(response.status); 
          },function(error) 
          { 
          console.log(error.status); 
          }); 
          } 
        } 
}]); 

答えて

0

ログインの試みが失敗した場合、あなたは次に/login/error/true

にリダイレクトしている、あなたはangularJSにしたい部分HTMLでそのURLへのルートを持っている必要があります表示するには、そのURLに対して適切なアクションを処理するangleJSコントローラを追加します。例えば

、のは、あなたのルートファイルがこれを見ていきますと言ってみましょう:errValueが真か偽:

var myApp = angular.module("myApp", [ "ngRoute" ]); 

myApp.config(function ($routeProvider) { 

    $routeProvider 
     .when("/login/error/:errValue", 
     {controller: "LoginController", templateUrl: "/partials/login.html"}) 
    }); 

今あなたがしなければならないすべては、かどうかLoginControllerにカントーチェックです。とその値に基づいて行動します。

with wrong credentials, I tried checking the value of errValue in the controller, but its says undefined 

    Below are the routes declared 

    $stateProvider 
      .state("/login",{ //this for login page 
      url:'/login', 
      templateUrl:'./resources/js/baseapp/ContactLogin/views/contactLogin.html', 
      controller:'contactLoginCtrl' 
     }) 
     .state("/home",{ 
      url:'/home',  // this is for home page 
      templateUrl:'./resources/js/baseapp/ContactHome/views/ContactHome.html', 
      controller:'contactHomeCtrl' 
     }) 
     .state("/login:error/:errValue",{ // this is for login error page 
      url:'/home', 
      templateUrl:'./resources/js/baseapp/ContactLogin/views/contactLogin.html', 
      controller:'contactLoginCtrl' 
     }) 
      $urlRouterProvider.otherwise("/login"); 
関連する問題