Skip to content

Commit

Permalink
Feat : 내 정보 조회 비밀번호 인증 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Suhun0331 committed Aug 1, 2024
1 parent 6c1b36b commit 78cc1e2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import umc.kkijuk.server.member.controller.response.MemberFieldResponse;
import umc.kkijuk.server.member.controller.response.MemberInfoResponse;
import umc.kkijuk.server.member.domain.Member;
import umc.kkijuk.server.member.dto.MemberFieldDto;
import umc.kkijuk.server.member.dto.MemberInfoChangeDto;
import umc.kkijuk.server.member.dto.MemberJoinDto;
import umc.kkijuk.server.member.dto.MemberPasswordChangeDto;
import umc.kkijuk.server.member.dto.*;
import umc.kkijuk.server.member.service.MemberService;
import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -88,12 +85,24 @@ public ResponseEntity<Boolean> postField(@RequestBody MemberFieldDto memberField
summary = "비밀번호 변경",
description = "비밀번호를 변경합니다.")
@PostMapping("myPage/password")
public ResponseEntity<Boolean> changePassword(@RequestBody @Valid MemberPasswordChangeDto memberPasswordChangeDto){
public ResponseEntity<Boolean> changeMemberPassword(@RequestBody @Valid MemberPasswordChangeDto memberPasswordChangeDto){
Long loginUser = LoginUser.get().getId();
memberService.changeMemberPassword(loginUser, memberPasswordChangeDto);
return ResponseEntity.ok(Boolean.TRUE);
}

@Operation(
summary = "내정보 조회용 비밀번호 인증",
description = "내 정보를 조회하기 위해 비밀번호를 인증합니다.")
@PostMapping("/myPage")
public ResponseEntity<Boolean> myPagePasswordAuth(@RequestBody @Valid MyPagePasswordAuthDto myPagePasswordAuthDto){{
Long loginUser = LoginUser.get().getId();
memberService.myPagePasswordAuth(loginUser, myPagePasswordAuthDto);
return ResponseEntity.ok(Boolean.TRUE);
}

}



}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package umc.kkijuk.server.member.dto;

import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class MyPagePasswordAuthDto {

@NotNull
private String currentPassword;

public MyPagePasswordAuthDto(String currentPassword) {
this.currentPassword = currentPassword;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public interface MemberService {
Member updateMemberField(Long memberId, MemberFieldDto memberFieldDto);
Member updateMemberInfo(Long memberId, MemberInfoChangeDto memberInfoChangeDto);
Member changeMemberPassword(Long memberId, MemberPasswordChangeDto memberPasswordChangeDto);
Member myPagePasswordAuth(Long memberId, MyPagePasswordAuthDto myPagePasswordAuthDto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ public Member changeMemberPassword(Long memberId, MemberPasswordChangeDto member
return member;
}

@Override
@Transactional
public Member myPagePasswordAuth(Long memberId, MyPagePasswordAuthDto myPagePasswordAuthDto) {
Member member = this.getById(memberId);

if(!passwordEncoder.matches(myPagePasswordAuthDto.getCurrentPassword(), member.getPassword())){
throw new CurrentPasswordMismatchException();
}

return member;
}

}

0 comments on commit 78cc1e2

Please sign in to comment.