Skip to content

Commit

Permalink
Merge pull request #185 from SMU-SATTO/feature/#184
Browse files Browse the repository at this point in the history
[Chore] 비밀번호 재설정 api
  • Loading branch information
HyunwooYi authored Aug 29, 2024
2 parents 9934d00 + 330ebe8 commit 95e2d36
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ public BaseResponse<?> publicAccount(@AuthenticationPrincipal Users user) {

@Operation(summary = "비밀번호 재설정")
@PatchMapping("account/pw")
public BaseResponse<?> resetPassword(@RequestBody UsersRequestDTO.UpdateUserPasswordDTO updateUserPasswordDTO, @AuthenticationPrincipal Users user) {
public BaseResponse<?> resetPassword(@RequestBody UsersRequestDTO.UpdateUserPassword2DTO updateUserPassword2DTO, @AuthenticationPrincipal Users user) {
Long userId = user.getUserId();
usersService.resetPassword(updateUserPasswordDTO, userId);
usersService.resetPassword(updateUserPassword2DTO, userId);
return BaseResponse.onSuccess("비밀번호 재설정 완료");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class UsersRequestDTO {
public static class UpdateUserDTO {
private String name;
private String nickname;
private String password;
private String department;
private int grade;
}
Expand All @@ -21,4 +20,10 @@ public static class UpdateUserPasswordDTO {
private String password;
}

@Getter
public static class UpdateUserPassword2DTO {
private String password1;
private String password2;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ public Users updateAccount(UsersRequestDTO.UpdateUserDTO updateUserDTO, Long use

user.setName(updateUserDTO.getName());
user.setNickname(updateUserDTO.getNickname());
user.setPassword(passwordEncoder.encode(updateUserDTO.getPassword()));
user.setDepartment(updateUserDTO.getDepartment());
user.setGrade(updateUserDTO.getGrade());

Expand Down Expand Up @@ -278,6 +277,19 @@ public void deleteProfileImage(String studentId) {
usersRepository.save(user);
}

@Override
public void resetPassword(UsersRequestDTO.UpdateUserPassword2DTO updateUserPassword2DTO, Long userId) {
Users user = usersRepository.findById(userId)
.orElseThrow(() -> new UsersHandler(ErrorStatus._NOT_FOUND_USER));
if (updateUserPassword2DTO.getPassword1().equals(updateUserPassword2DTO.getPassword2())) {
user.setPassword(passwordEncoder.encode(updateUserPassword2DTO.getPassword1()));
usersRepository.save(user);
} else {
throw new UsersHandler(ErrorStatus._INVALID_PW);
}

}

private String extractKeyFromUrl(String url) {
// URL에서 S3 key 추출 (폴더 포함)
return url.substring(url.indexOf(s3Config.getPath2()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ public interface UsersService {

void deleteProfileImage(String studentId);

void resetPassword(UsersRequestDTO.UpdateUserPassword2DTO updateUserPassword2DTO, Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum ErrorStatus implements BaseErrorCode {
// User 에러
_NOT_FOUND_USER(HttpStatus.NOT_FOUND, "USER400", "사용자가 존재하지 않습니다."),
_INVALID_USER(HttpStatus.BAD_REQUEST, "USER401" , "아이디 또는 비밀번호가 틀렸습니다."),
_INVALID_PW(HttpStatus.BAD_REQUEST, "USER402", "입력한 비밀번호가 일치하지 않습니다."),

// Follow 에러
_NOT_FOUND_FOLLOWING_LIST(HttpStatus.NOT_FOUND, "FOLLOW400", "사용자가 존재하지 않습니다."),
Expand Down

0 comments on commit 95e2d36

Please sign in to comment.