LoginController.java
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.daeucna.board.security.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.daeucna.board.security.domain.UserDto;
import com.daeucna.board.security.domain.UserForm;
import com.daeucna.board.security.service.LoginService;
import lombok.extern.slf4j.Slf4j;
@Controller
@RequestMapping("/")
@Slf4j
public class LoginController {
@Autowired
private LoginService loginService;
@GetMapping("/login")
public String getlogin(Model model) {
log.info("로그인 Page");
return "page/login/login";
}
@GetMapping("/info")
@ResponseBody
public String getCurrentUserInfo(HttpSession httpSession) {
try {
Authentication authentication = (Authentication) httpSession.getAttribute("authentication");
UserDto userDto = (UserDto) authentication.getPrincipal();
log.info("user : " + userDto );
return userDto.getUsername() + "은 로그인중입니다";
} catch (Exception e) {
return "먼저 로그인을 하세요";
}
}
@GetMapping("/join")
public String getJoin(Model model) {
log.info("회원가입 Page");
return "page/login/join";
}
@PostMapping("/join_proc")
@ResponseBody
public ResponseEntity procJoin(HttpServletRequest request, HttpServletResponse response, UserForm userForm) {
HttpStatus httpStatus = null;
UserForm resultUserForm = null;
try {
resultUserForm = loginService.procJoin(userForm);
httpStatus = HttpStatus.OK;
} catch (Exception e) {
httpStatus = HttpStatus.BAD_REQUEST;
}
return new ResponseEntity(resultUserForm, httpStatus);
}
}