MCPcopy Index your code
hub / github.com/castello/spring_basic / login

Method login

ch2/LoginController.java:21–49  ·  view source on GitHub ↗
(String id, String pwd, boolean rememberId, HttpServletResponse response)

Source from the content-addressed store, hash-verified

19 }
20
21 @PostMapping("/login")
22 public String login(String id, String pwd, boolean rememberId, HttpServletResponse response) throws Exception {
23 System.out.println("id="+id);
24 System.out.println("pwd="+pwd);
25 System.out.println("rememberId="+rememberId);
26 // 1. id와 pwd를 확인
27 if(!loginCheck(id, pwd)) {
28 // 2-1 일치하지 않으면, loginForm으로 이동
29 String msg = URLEncoder.encode("id 또는 pwd가 일치하지 않습니다.", "utf-8");
30
31 return "redirect:/login/login?msg="+msg;
32 }
33
34 // 2-2. id와 pwd가 일치하면,
35 if(rememberId) {
36 // 1. 쿠키를 생성
37 Cookie cookie = new Cookie("id", id); // ctrl+shift+o 자동 import
38// 2. 응답에 저장
39 response.addCookie(cookie);
40 } else {
41// 1. 쿠키를 삭제
42 Cookie cookie = new Cookie("id", id); // ctrl+shift+o 자동 import
43 cookie.setMaxAge(0); // 쿠키를 삭제
44// 2. 응답에 저장
45 response.addCookie(cookie);
46 }
47// 3. 홈으로 이동
48 return "redirect:/";
49 }
50
51 private boolean loginCheck(String id, String pwd) {
52 return "asdf".equals(id) && "1234".equals(pwd);

Callers

nothing calls this directly

Calls 1

loginCheckMethod · 0.95

Tested by

no test coverage detected