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

Method login

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

loginCheckMethod · 0.95
equalsMethod · 0.45

Tested by

no test coverage detected