Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] 비밀번호 재발급 정상 작동 검증 및 로직 개선 #750

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/net/causw/adapter/web/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ public UserResponseDto updateRole(
@PutMapping(value = "/password/find")
@ResponseStatus(value = HttpStatus.OK)
@Operation(summary = "비밀번호 찾기 API (완료)", description = "비밀번호 재설정 이메일 전송 API입니다.")
public UserResponseDto findPassword(@Valid @RequestBody UserFindPasswordRequestDto userFindPasswordRequestDto) {
return this.userService.findPassword(userFindPasswordRequestDto);
public void findPassword(@Valid @RequestBody UserFindPasswordRequestDto userFindPasswordRequestDto) {
this.userService.findPassword(userFindPasswordRequestDto);
}

@PutMapping(value = "/password")
Expand Down
30 changes: 10 additions & 20 deletions src/main/java/net/causw/application/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@
import net.causw.application.uuidFile.UuidFileService;
import net.causw.config.security.JwtTokenProvider;
import net.causw.domain.aop.annotation.MeasureTime;
import net.causw.domain.exceptions.BadRequestException;
import net.causw.domain.exceptions.ErrorCode;
import net.causw.domain.exceptions.InternalServerException;
import net.causw.domain.exceptions.UnauthorizedException;
import net.causw.domain.exceptions.*;
import net.causw.domain.model.enums.circle.CircleMemberStatus;
import net.causw.domain.model.enums.locker.LockerLogAction;
import net.causw.domain.model.enums.user.Role;
Expand Down Expand Up @@ -121,15 +118,15 @@ public class UserService {
private final UserAcademicRecordApplicationAttachImageRepository userAcademicRecordApplicationAttachImageRepository;

@Transactional
public UserResponseDto findPassword(
public void findPassword(
UserFindPasswordRequestDto userFindPasswordRequestDto
) {
User requestUser = userRepository.findByEmailAndNameAndStudentIdAndPhoneNumber(
userFindPasswordRequestDto.getEmail(),
userFindPasswordRequestDto.getName(),
userFindPasswordRequestDto.getStudentId(),
userFindPasswordRequestDto.getPhoneNumber()
).orElseThrow(() -> new BadRequestException(
userFindPasswordRequestDto.getEmail().trim(),
userFindPasswordRequestDto.getName().trim(),
userFindPasswordRequestDto.getStudentId().trim(),
userFindPasswordRequestDto.getPhoneNumber().trim()
).orElseThrow(() -> new NotFoundException(
ErrorCode.ROW_DOES_NOT_EXIST,
MessageUtil.USER_NOT_FOUND
));
Expand All @@ -139,16 +136,9 @@ public UserResponseDto findPassword(
// 메일 전송
this.googleMailSender.sendNewPasswordMail(requestUser.getEmail(), newPassword);

// 비밀번호 변경 (db save)
this.userRepository.findById(requestUser.getId()).map(
srcUser -> {
srcUser.setPassword(passwordEncoder.encode(newPassword));
return this.userRepository.save(srcUser);
}).orElseThrow(() -> new BadRequestException(
ErrorCode.ROW_DOES_NOT_EXIST,
MessageUtil.USER_NOT_FOUND));

return UserDtoMapper.INSTANCE.toUserResponseDto(requestUser, getCircleIdsIfLeader(requestUser), getCircleNamesIfLeader(requestUser));
// 비밀번호 변경
requestUser.setPassword(this.passwordEncoder.encode(newPassword));
// ! dirty cecking 때문에 save 필요 없음
}

// Find process of another user
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.causw.domain.exceptions;

public class NotFoundException extends BaseRuntimeException {
public NotFoundException(ErrorCode errorCode, String message) {
super(errorCode, message);
}
}
Loading