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

Method login

ch4/LoginController.java:38–71  ·  view source on GitHub ↗
(String id, String pwd, String toURL, boolean rememberId,
                        HttpServletRequest request, HttpServletResponse response)

Source from the content-addressed store, hash-verified

36 }
37
38 @PostMapping("/login")
39 public String login(String id, String pwd, String toURL, boolean rememberId,
40 HttpServletRequest request, HttpServletResponse response) throws Exception {
41
42 // 1. id와 pwd를 확인
43 if(!loginCheck(id, pwd)) {
44 // 2-1 일치하지 않으면, loginForm으로 이동
45 String msg = URLEncoder.encode("id 또는 pwd가 일치하지 않습니다.", "utf-8");
46
47 return "redirect:/login/login?msg="+msg;
48 }
49 // 2-2. id와 pwd가 일치하면,
50 // 세션 객체를 얻어오기
51 HttpSession session = request.getSession();
52 // 세션 객체에 id를 저장
53 session.setAttribute("id", id);
54
55 if(rememberId) {
56 // 1. 쿠키를 생성
57 Cookie cookie = new Cookie("id", id); // ctrl+shift+o 자동 import
58// 2. 응답에 저장
59 response.addCookie(cookie);
60 } else {
61 // 1. 쿠키를 삭제
62 Cookie cookie = new Cookie("id", id); // ctrl+shift+o 자동 import
63 cookie.setMaxAge(0); // 쿠키를 삭제
64// 2. 응답에 저장
65 response.addCookie(cookie);
66 }
67// 3. 홈으로 이동
68 toURL = toURL==null || toURL.equals("") ? "/" : toURL;
69
70 return "redirect:"+toURL;
71 }
72
73 private boolean loginCheck(String id, String pwd) {
74 User user = null;

Callers

nothing calls this directly

Calls 2

loginCheckMethod · 0.95
equalsMethod · 0.45

Tested by

no test coverage detected