diff --git a/bookstore-api/.idea/workspace.xml b/bookstore-api/.idea/workspace.xml index d3c9c70..2926fe3 100644 --- a/bookstore-api/.idea/workspace.xml +++ b/bookstore-api/.idea/workspace.xml @@ -80,7 +80,7 @@ - + @@ -90,6 +90,16 @@ + + + + + + + + + + @@ -156,7 +166,6 @@ @@ -1007,12 +1017,12 @@ - + - @@ -1059,7 +1069,7 @@ - @@ -1227,14 +1237,6 @@ - - - - - - - - @@ -1545,5 +1547,13 @@ + + + + + + + + \ No newline at end of file diff --git a/bookstore-api/src/main/java/com/bookstore/resource/LoginResource.java b/bookstore-api/src/main/java/com/bookstore/resource/LoginResource.java index 23fb735..7769d7b 100644 --- a/bookstore-api/src/main/java/com/bookstore/resource/LoginResource.java +++ b/bookstore-api/src/main/java/com/bookstore/resource/LoginResource.java @@ -41,29 +41,33 @@ public class LoginResource { return new ResponseEntity("Logout success.",HttpStatus.OK); } - @RequestMapping(value="login", method = RequestMethod.POST) - public String loginPost(@RequestBody Map json) throws - ServletException { - if(json.get("username") == null || json.get("password") ==null) { - throw new ServletException("Please fill in username and password"); - } - - String username = json.get("username"); - String password = json.get("password"); - - User user= userService.findByUsername(username); - if (user==null) { - throw new ServletException("User name not found."); - } - - String pwd = user.getPassword(); - - if(!password.equals(pwd)) { - throw new ServletException("Invalid login. Please check your name and password"); - } - - return "login success"; - } +// @RequestMapping(value="login", method = RequestMethod.POST) +// public String loginPost( +// @RequestBody Map json, +// HttpServletRequest request +// ) throws +// ServletException { +// if(json.get("username") == null || json.get("password") ==null) { +// throw new ServletException("Please fill in username and password"); +// } +// +// String username = json.get("username"); +// String password = json.get("password"); +// +// User user= userService.findByUsername(username); +// if (user==null) { +// throw new ServletException("User name not found."); +// } +// +// String pwd = user.getPassword(); +// +// if(!password.equals(pwd)) { +// throw new ServletException("Invalid login. Please check your name and password"); +// } +// +// +// return "login success"; +// } @RequestMapping(value = "/user/logout", method = RequestMethod.POST) public String logout() { @@ -90,7 +94,15 @@ public class LoginResource { @RequestMapping("/token") @ResponseBody - public Map token(HttpSession session) { + public Map token(HttpSession session, HttpServletRequest request) { + System.out.println(request.getRemoteHost()); + + String remoteHost = request.getRemoteHost(); + int portNumber = request.getRemotePort(); + + System.out.println(remoteHost+":"+portNumber); + System.out.println(request.getRemoteAddr()); + return Collections.singletonMap("token", session.getId()); } } diff --git a/bookstore-api/target/classes/com/bookstore/resource/LoginResource.class b/bookstore-api/target/classes/com/bookstore/resource/LoginResource.class index 86ab1db..8b93f98 100644 Binary files a/bookstore-api/target/classes/com/bookstore/resource/LoginResource.class and b/bookstore-api/target/classes/com/bookstore/resource/LoginResource.class differ