Skip to content

Commit

Permalink
merge 2
Browse files Browse the repository at this point in the history
  • Loading branch information
knh0113 committed Sep 26, 2023
2 parents f4c5f35 + 011fe80 commit baff53f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public String showLoginForm(HttpSession session, HttpServletRequest request) {
}


/*
/*
* 로그인 기능 구현
*
* @param requestDto
Expand Down Expand Up @@ -125,43 +125,24 @@ public String showSignUpForm() {
* @param requestDto
* @return
*/

@PostMapping("/signup")
public String signUp(SignUpRequestDto requestDto, HttpSession session) {
setSessionLoginUser(session, userService.signUp(requestDto));
return "redirect:/";
}


private void setSessionLoginUser(HttpSession session, User user) {
session.setAttribute("loginUser", user);
}

/**
* 회원가입 처리 로직
*
* @param requestDto
* @return
*/
@PostMapping("/signup")
public String signUp(SignUpRequestDto requestDto, HttpSession session) {
setSessionLoginUser(session, userService.signUp(requestDto));
return "redirect:/";
}
private void setSessionLoginUser(HttpSession session, User user) {
session.setAttribute("loginUser", user);
}

@ResponseBody
@PostMapping("/session-info")
public Map<String, Long> paymentSessionInfoRtn(HttpSession session) {
User temp = (User)session.getAttribute("loginUser");
Long userId = userService.findUserById(temp.getId()).orElseThrow(
() -> UserNotFoundException.EXCEPTION
).getId();
return new HashMap<String, Long>(){{
put("userId", userId);
}};
}

@ResponseBody
@PostMapping("/session-info")
public Map<String, Long> paymentSessionInfoRtn(HttpSession session) {
User temp = (User)session.getAttribute("loginUser");
Long userId = userService.findUserById(temp.getId()).orElseThrow(
() -> UserNotFoundException.EXCEPTION
).getId();
return new HashMap<String, Long>(){{
put("userId", userId);
}};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public User signUp(SignUpRequestDto userDto) {
throw EmailErrorException.EXCEPTION; // 중복 이메일 체크
}

return userRepository.save(User.builder()
return userRepository.save(User.builder()
.email(userDto.getEmail())
.password(userDto.getPassword())
.nickName(userDto.getNickName())
Expand Down Expand Up @@ -58,14 +58,15 @@ public Optional<User> findUserById(Long id) {
return userRepository.findById(id);
}


//??
public Optional<User> findUserByIdAndEmail(Long userId, String email) {
return userRepository.findByIdAndEmail(userId, email);
}

public Optional<User> findUserByEmail(String email) {
return userRepository.findByEmail(email);
}

public Optional<User> findById(Long userId) {
return userRepository.findById(userId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;
import picasso.server.common.dto.ErrorDetail;

import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.UNAUTHORIZED;
import static org.springframework.http.HttpStatus.*;

@Getter
@AllArgsConstructor
Expand Down

0 comments on commit baff53f

Please sign in to comment.