2017-07-11 5 views
0

enter image description here角度js-1(loginCtrl):角度応答は春の応答を反映しません。問題は...あなたは途中で角度と春安らか-WSJava Spring 4.0はステータスコード200で応答しますが、角度Jは応答のエラーブロックを実行します(不正なログインに)

app.controller('loginCtrl', function($scope,$http,$window){ 

      $scope.login = function(email,password) { 
      var myData = { 
      email: $scope.email, 
      password: $scope.password 
      }; 

      $http.post(customerURL,JSON.stringify(myData)).then(function(response){ 
       if(response.data) 
       console.log(response.data); 
       $scope.msg = "SUCCESSFULLY LOGGED IN"; 
       $scope.status = response.status; 
       $scope.statusText = response.statusText; 
       console.log($scope.msg);  
       },function(response){ 
       //console.log(response.status); 

       $scope.msg = "ERROR LOGIN IN"; 

       console.log($scope.msg); 


      }); 
     };                          
     }); 

Javaの春4.0に新しいです、支援してください可能性があります...メールを検索し、正しく(checkpwを使用して)、パスワードをハッシュ化

@RequestMapping(value="",method = RequestMethod.POST) 
    public ResponseEntity LoginCustomer(@RequestBody String json) throws CustomerNotFoundException 
    { 
     try { 
      ObjectMapper mapper = new ObjectMapper(); 
      final JsonNode data = mapper.readTree(json); 

      String email = data.get("email").asText(); 
      String password = data.get("password").asText(); 


      if(services.findByName(email) != null && services.findByPw(password) != null){ 
      logger.info("received correct user details in :json String " + json); 
      System.out.println("Successfull!!"); 
      return new ResponseEntity(HttpStatus.OK); 

      }else{ 
       System.out.println("Error!!"); 
       return new ResponseEntity(HttpStatus.BAD_REQUEST); 
      } 
     } catch (IOException ex){ 
     throw new RuntimeException(ex); 
     } 

    } 

私の現在のカスタマーコントローラ...

コントローラクラス前
/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package com.product.Controller; 

import com.product.Exceptions.CustomerNotFoundException; 
import com.product.Services.CustomerServices; 
import com.product.Product.Customer; 

import com.fasterxml.jackson.databind.JsonNode; 
import com.fasterxml.jackson.databind.ObjectMapper; 


import java.io.IOException; 
import java.io.Serializable; 
import java.util.List; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.http.HttpStatus; 
import org.springframework.http.ResponseEntity; 
import org.springframework.security.crypto.bcrypt.BCrypt; 
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.PathVariable; 
import org.springframework.web.bind.annotation.RequestBody; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.RestController; 
import org.springframework.web.servlet.ModelAndView; 

/* 
* 
* @author HP 
*/ 
@RestController 
@RequestMapping("/customer") 
public class CustomerController{ 
    /////////members //////////////////////////////////////////////////////////////////////////////////// 
    private static final Logger logger = LoggerFactory.getLogger(CustomerController.class);   // 
    @Autowired                      // 
    private CustomerServices services; 
    private BCryptPasswordEncoder pe;// 
    /////////////////////////////////////////////////////////////////////////////////////////////////// 

    @RequestMapping(value="",method = RequestMethod.PUT) 
    public ResponseEntity createCustomer(@RequestBody String json) throws CustomerNotFoundException 
    { 
     try { 
      ObjectMapper mapper = new ObjectMapper(); 
      final JsonNode data = mapper.readTree(json); 
      logger.info("recived json String " + json); 
      String email = data.get("email").asText(); 
      String password = data.get("password").asText(); 
      String firstname = data.get("firstname").asText(); 
      String surname = data.get("surname").asText(); 

      //brypt hashing 
      String pw_hash = BCrypt.hashpw(password,BCrypt.gensalt(10)); 

       Customer c = new Customer(firstname, surname, email, pw_hash); 


      ///////create customer ///////// 
      services.createCustomer(c); 
      ///return if try was succesful 
      //loginService.createLogin(u); 
      return new ResponseEntity(HttpStatus.CREATED); 

     } catch (IOException ex){ 
     throw new RuntimeException(ex); 
     } 

    } 

    @RequestMapping(value="",method = RequestMethod.POST) 
    public ResponseEntity LoginCustomer(@RequestBody String json) throws CustomerNotFoundException 
    { 
     try { 
      ObjectMapper mapper = new ObjectMapper(); 
      final JsonNode data = mapper.readTree(json); 

      String email = data.get("email").asText(); 
      String password = data.get("password").asText(); 


      if(services.findByName(email) != null && services.findByPw(password) != null){ 
      logger.info("received correct user details in :json String " + json); 
      System.out.println("Successfull!!"); 
      return new ResponseEntity(HttpStatus.OK); 

      }else{ 
       System.out.println("Error!!"); 
       return new ResponseEntity(HttpStatus.BAD_REQUEST); 
      } 
     } catch (IOException ex){ 
     throw new RuntimeException(ex); 
     } 

    } 



     @RequestMapping(value = "", method = RequestMethod.GET) 
    public ResponseEntity<List<Customer>> getAllCustomers() { 

     List<Customer> customerList = services.getCustomerList(); 
     if(customerList != null) { 
      return new ResponseEntity<>(customerList, HttpStatus.OK); 
     }else{ 
      return new ResponseEntity<>(HttpStatus.BAD_REQUEST); 
     } 
    } 

    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) 
    public ResponseEntity<CustomerController> Delete(@PathVariable long id) throws CustomerNotFoundException { 
    services.DeleteCustomer(id); 
    return new ResponseEntity<>(HttpStatus.BAD_REQUEST); 
    } 
} 
+0

あなたはどんな反応を得ましたか? –

答えて

0

使用蛇腹注釈:クラス

@RequestMapping(value = "", method = RequestMethod.POST, produces = "application/json", consumes = "application/json") 
    public ResponseEntity save(@RequestBody LoginView loginView) { 


} 

LoginView

@RestController 
@RequestMapping("/login") 

使用は、JSONとそのセッターゲッターメソッドに使用するのと同じ変数を含むクラスです。

package com.test; 



public class LoginView { 


private String email; 

private String password; 

public String getEmail() { 
    return email; 
} 

public void setEmail(String email) { 
    this.email = email; 
} 

public String getPassword() { 
    return password; 
} 

public void setPassword(String password) { 
    this.password = password; 
} 

} 
0

は、私はこの問題を解決することができたため、究極の問題は、ステータスコードが常に頼られた、ということでした私のポストを経たあなたの人々は、ポストは、音のための明確であり、時間のためにあなたに感謝します200にもURLが存在しない場合でも、私はクライアント側のデフォルトと伝播を阻止し、その要求はキャンセルされなくなりました...これが誰かを助けてくれることを願っています、これは私の最初の安らぎのアプリです...私は幸せです地球上の人...;)

関連する問題