->Spring Security이용해서 암호화되어있는 데이터를 비교하는 방법(설명)은 Spring 설정 카테고리란에 작성돼있습니다.
#UserController.java
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
package com.example.login.controller;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import com.example.login.service.LoginService;
import com.example.login.vo.UserVO;
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
LoginService service;
//회원등록
@PostMapping("/")
public String join(@RequestBody UserVO vo) {
service.insert(vo);
System.out.println(vo);
return "joinSuccess";
}
//아이디 중복확인
@PostMapping("/check")
public String check(@RequestBody String id) {
String result = null;
int num = service.checkId(id);
System.out.println(num);
//변수 num이 1일경우 아이디 중복 0일경우 아이디 등록가능
if(num == 1) {
System.out.println("아이디가 중복됨");
result="Fail";
}else {
System.out.println("아이디사용가능");
result="Success";
}
return result;
}
//회원조회
@GetMapping("/{id}")
public UserVO selectUser(@PathVariable String id) {
return service.getUser(id);
}
//회원탈퇴
@DeleteMapping("/{id}")
public String delete(@PathVariable String id) {
service.delete(id);
return "deleteSuccess";
}
//로그인구현
@PostMapping("/loginCheck")
public String login(@RequestBody UserVO input , HttpSession session ) {
BCryptPasswordEncoder encode = new BCryptPasswordEncoder();
System.out.println(input);
String result = null;
UserVO db = service.getUser(input.getId());
if(db != null) {
if(encode.matches(input.getPassword(),db.getPassword())) {
session.setAttribute("login",db);
result = "loginSuccess";
}else {
result = "pwFail";
}
}else {
result = "idFail";
}
System.out.println(result);
return result;
}
//로그아웃처리
@PostMapping("/logout")
public ModelAndView logout(HttpSession session) {
if(session.getAttribute("login") != null) {
session.removeAttribute("login");
session.invalidate();
}
return new ModelAndView("redirect:/");
}
}
|
cs |
'Spring Boot 개인 프로젝트 > 회원관리 REST-API서버 구축' 카테고리의 다른 글
(7 - 1)(자동로그인 구현) 자동로그인 로직과 동작 과정 (0) | 2021.09.22 |
---|---|
(6) 지금까지 구축한 REST API가 잘 작동하는지 Postman을 사용하여 테스트 해보기 (0) | 2021.09.20 |
(4) ILoginService인터페이스와 LoginService클래스 생성 그리고 Controller에서 전달받게될 비밀번호 Spring Security이용해서 암호화한다음 Mapper한테 전달 (0) | 2021.09.20 |
(3) IUserMapper 인터페이스 와 UserMapper.xml 생성 (0) | 2021.09.20 |
(2) UserVO클래스 생성 (0) | 2021.09.20 |