Skip to content

Commit

Permalink
[FEATURE] 비밀번호 재설정 API (#101)
Browse files Browse the repository at this point in the history
* refactor: 필드명 변경 (#99)

* feat: 비밀번호 재설정 API (#99)
  • Loading branch information
hyunmin0317 authored Nov 12, 2024
1 parent e5e7412 commit deb028f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class AccountController {
private final AccountService accountService;

@PostMapping("/register")
public ResponseEntity<RegisterResponseDto> register(@AuthVerified String verifiedUser, @RequestBody @Valid RegisterRequestDto requestDto) {
RegisterResponseDto responseDto = accountService.register(verifiedUser, requestDto);
public ResponseEntity<RegisterResponseDto> register(@AuthVerified String memberName, @RequestBody @Valid RegisterRequestDto requestDto) {
RegisterResponseDto responseDto = accountService.register(memberName, requestDto);
return ResponseEntity.status(HttpStatus.CREATED).body(responseDto);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class AccountService {
private final PasswordEncoder passwordEncoder;
private final JwtTokenProvider jwtTokenProvider;

public RegisterResponseDto register(String verifiedUser, RegisterRequestDto requestDto) {
validateUser(verifiedUser, requestDto.username());
public RegisterResponseDto register(String memberName, RegisterRequestDto requestDto) {
validateUser(memberName, requestDto.username());
Member member = requestDto.toEntity();
Year year = yearRepository.findByName(requestDto.username().substring(0, 4))
.orElseThrow(() -> new GeneralException(ErrorCode.YEAR_NOT_FOUND));
Expand Down Expand Up @@ -64,8 +64,8 @@ private LoginResponseDto generateToken(Long memberId, MemberRole memberRole) {
return LoginResponseDto.of(memberId, memberRole, accessToken, refreshToken);
}

private void validateUser(String verifiedUser, String username) {
validateVerified(verifiedUser, username);
private void validateUser(String memberName, String username) {
validateVerified(memberName, username);
validateUsername(username);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.smunity.server.domain.member.service.MemberCommandService;
import com.smunity.server.domain.member.service.MemberQueryService;
import com.smunity.server.global.security.annotation.AuthMember;
import com.smunity.server.global.security.annotation.AuthVerified;
import com.smunity.server.global.validation.annotation.PermissionCheck;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -66,4 +67,10 @@ public ResponseEntity<MemberInfoResponseDto> changeDepartment(@AuthMember Long m
MemberInfoResponseDto responseDto = memberCommandService.changeDepartment(memberId, requestDto);
return ResponseEntity.ok(responseDto);
}

@PatchMapping("/password/reset")
public ResponseEntity<MemberInfoResponseDto> changePasswordByAuth(@AuthVerified String memberName, @RequestBody @Valid ChangePasswordRequestDto requestDto) {
MemberInfoResponseDto responseDto = memberCommandService.changePasswordByAuth(memberName, requestDto);
return ResponseEntity.ok(responseDto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ public MemberInfoResponseDto changeDepartment(Long memberId, ChangeDepartmentReq
member.changeDepartment(department);
return MemberInfoResponseDto.from(member);
}

public MemberInfoResponseDto changePasswordByAuth(String username, ChangePasswordRequestDto requestDto) {
Member member = memberRepository.findByUsername(username).orElseThrow(() -> new GeneralException(ErrorCode.MEMBER_NOT_FOUND));
return changePassword(member.getId(), requestDto);
}
}

0 comments on commit deb028f

Please sign in to comment.