Skip to content

Commit

Permalink
[#10] Fix: login도 ajax로 통신하는 것을 고려하여 @RequestBody로 변경
Browse files Browse the repository at this point in the history
- 로그인도 /api로 제공하는 경우, 데이터가 json으로 전달되는 것을 고려하여 @RequestBody로 변경함.
- 객체가 비밀번호를 확인하도록 구현
  • Loading branch information
beginin15 authored and ksundong committed Mar 26, 2020
1 parent 84c9ac3 commit 977d5fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public User createUser(@RequestBody User user) {
}

@PostMapping("/login")
public boolean login(@RequestParam String userId, @RequestParam String password, HttpSession session) {
Optional<User> optionalUser = userRepository.findByUserId(userId);
public boolean login(@RequestBody User loginUser, HttpSession session) {
Optional<User> optionalUser = userRepository.findByUserId(loginUser.getUserId());
if (!optionalUser.isPresent())
return false;

User user = optionalUser.get();
if (!user.matchPassword(password))
if (!user.matchPassword(loginUser))
return false;

session.setAttribute(SESSION_USER_KEY, user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public boolean validate() {
return idMatcher.matches() && passwordMatcher.matches() && emailMatcher.matches() && phoneNumberMatcher.matches();
}

public boolean matchPassword(String password) {
return this.password.equals(password);
public boolean matchPassword(User loginUser) {
return this.password.equals(loginUser.password);
}
}

0 comments on commit 977d5fa

Please sign in to comment.