Skip to content

🔀 Profile Modify#38

Merged
ohyuchan123 merged 4 commits intodevelopfrom
feature/profile-modify
Jan 15, 2025
Merged

🔀 Profile Modify#38
ohyuchan123 merged 4 commits intodevelopfrom
feature/profile-modify

Conversation

@ohyuchan123
Copy link
Member

@ohyuchan123 ohyuchan123 commented Jan 15, 2025

📌 관련 이슈

#32 사용자 프로필 수정

✨ 과제 내용

사요자는 자신의 프로필을 수정할 수 있습니다.

추가적으로 구현해야 되는 부분

  • 사용자 프로필 이미지 등록 및 수정
  • 사용자가 비밀번호를 변경했을 경우 경고 문구와 함께 강제 로그아웃

📸 스크린샷(선택)

image image

📚 레퍼런스 (또는 새로 알게 된 내용) 혹은 궁금한 사항들

Summary by CodeRabbit

  • 새로운 기능

    • 사용자 프로필 업데이트 기능 추가
    • 사용자 비밀번호 변경 기능 추가
  • 보안 개선

    • /api/profile/** 경로에 대한 접근 권한 설정 업데이트
  • 기타 변경사항

    • 프로필 및 비밀번호 변경을 위한 새로운 데이터 전송 객체(DTO) 생성
    • 사용자 정보 관리 서비스 개선

@ohyuchan123 ohyuchan123 added 🔨 Refactor 코드 리팩토링 ✨ Feature 기능 개발 labels Jan 15, 2025
@ohyuchan123 ohyuchan123 self-assigned this Jan 15, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2025

Warning

Rate limit exceeded

@ohyuchan123 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 40 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3297bf8 and 63cfeb7.

📒 Files selected for processing (4)
  • src/main/java/com/mycom/socket/go_socket/controller/ProfileController.java (1 hunks)
  • src/main/java/com/mycom/socket/go_socket/dto/request/PasswordUpdateRequest.java (1 hunks)
  • src/main/java/com/mycom/socket/go_socket/dto/request/ProfileUpdateRequest.java (1 hunks)
  • src/main/java/com/mycom/socket/go_socket/service/MemberService.java (2 hunks)

워크스루

이 풀 리퀘스트는 사용자 프로필 및 비밀번호 업데이트 기능을 추가하는 변경 사항을 포함합니다. 보안 구성에서 /api/profile/** 경로에 대한 접근 권한을 허용하도록 수정되었으며, 프로필 컨트롤러에 새로운 메서드가 도입되었습니다. 사용자 프로필 및 비밀번호 업데이트를 위한 요청 DTO와 서비스 로직이 구현되었습니다.

변경 사항

파일 변경 요약
SecurityConfig.java /api/profile/** 경로에 대한 인증 없는 접근 허용
ProfileController.java 프로필 및 비밀번호 업데이트 메서드 추가
PasswordUpdateRequest.java 비밀번호 업데이트 요청 DTO 생성
ProfileUpdateRequest.java 프로필 업데이트 요청 DTO 생성
Member.java 프로필 및 비밀번호 업데이트 메서드 추가
MemberService.java 프로필 및 비밀번호 업데이트 서비스 로직 구현

시퀀스 다이어그램

sequenceDiagram
    participant Client
    participant ProfileController
    participant MemberService
    participant MemberRepository
    participant Member

    Client->>ProfileController: 프로필 업데이트 요청
    ProfileController->>MemberService: updateProfile(email, nickname, intro)
    MemberService->>MemberRepository: findByEmail(email)
    MemberRepository-->>MemberService: Member 객체
    MemberService->>Member: updateProfile(nickname, intro)
    Member-->>MemberService: 업데이트된 Member
    MemberService-->>ProfileController: 업데이트된 Member
    ProfileController-->>Client: 프로필 응답
Loading

관련 가능성 있는 PR

토끼의 시

🐰 프로필 수정의 춤

보안 문 열리고
새로운 기능 반짝여
닉네임과 비밀번호
자유롭게 바꾸네
코드의 토끼 춤추자! 🕺


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

🧹 Nitpick comments (1)
src/main/java/com/mycom/socket/go_socket/entity/Member.java (1)

59-61: 비밀번호 업데이트 시 유효성 검증 추가

비밀번호 업데이트 시 인코딩된 비밀번호가 null이 아닌지 검증이 필요합니다.

     public void updatePassword(String encodedPassword) {
+        if (encodedPassword == null || encodedPassword.isBlank()) {
+            throw new IllegalArgumentException("비밀번호는 null이거나 빈 값일 수 없습니다.");
+        }
         this.password = encodedPassword;
     }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22fa66a and 3297bf8.

📒 Files selected for processing (6)
  • src/main/java/com/mycom/socket/auth/config/SecurityConfig.java (1 hunks)
  • src/main/java/com/mycom/socket/go_socket/controller/ProfileController.java (1 hunks)
  • src/main/java/com/mycom/socket/go_socket/dto/request/PasswordUpdateRequest.java (1 hunks)
  • src/main/java/com/mycom/socket/go_socket/dto/request/ProfileUpdateRequest.java (1 hunks)
  • src/main/java/com/mycom/socket/go_socket/entity/Member.java (1 hunks)
  • src/main/java/com/mycom/socket/go_socket/service/MemberService.java (2 hunks)

Comment on lines 3 to 6
public record ProfileUpdateRequest(
String nickname,
String intro
) {} No newline at end of file
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

필드 유효성 검증 추가 필요

프로필 업데이트 요청 DTO에 다음과 같은 유효성 검증 어노테이션을 추가하는 것이 좋습니다:

 public record ProfileUpdateRequest(
+        @NotBlank(message = "닉네임은 필수입니다")
+        @Size(min = 2, max = 20, message = "닉네임은 2자 이상 20자 이하여야 합니다")
         String nickname,
+        @Size(max = 100, message = "자기소개는 100자를 초과할 수 없습니다")
         String intro
 ) {}

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 3 to 6
public record PasswordUpdateRequest(
String currentPassword,
String newPassword
) {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

비밀번호 유효성 검증 및 보안 규칙 추가 필요

비밀번호 업데이트 요청 DTO에 다음과 같은 보안 검증을 추가해야 합니다:

 public record PasswordUpdateRequest(
+        @NotBlank(message = "현재 비밀번호는 필수입니다")
         String currentPassword,
+        @NotBlank(message = "새 비밀번호는 필수입니다")
+        @Pattern(
+            regexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[@$!%*#?&])[A-Za-z\\d@$!%*#?&]{8,}$",
+            message = "비밀번호는 8자 이상이며, 영문자, 숫자, 특수문자를 포함해야 합니다"
+        )
         String newPassword
 ) {}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public record PasswordUpdateRequest(
String currentPassword,
String newPassword
) {}
public record PasswordUpdateRequest(
@NotBlank(message = "현재 비밀번호는 필수입니다")
String currentPassword,
@NotBlank(message = "새 비밀번호는 필수입니다")
@Pattern(
regexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[@$!%*#?&])[A-Za-z\\d@$!%*#?&]{8,}$",
message = "비밀번호는 8자 이상이며, 영문자, 숫자, 특수문자를 포함해야 합니다"
)
String newPassword
) {}

Comment on lines 33 to 35
if (!passwordEncoder.matches(currentPassword, member.getPassword())) {
throw new NotFoundException("사용자를 찾을 수 없습니다.");
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

보안 개선: 비밀번호 오류와 사용자 없음에 대한 예외 구분 필요

현재 구현은 사용자를 찾을 수 없는 경우와 비밀번호가 일치하지 않는 경우에 동일한 예외를 발생시킵니다. 이는 보안상 좋지 않은 방식입니다.

-        if (!passwordEncoder.matches(currentPassword, member.getPassword())) {
-            throw new NotFoundException("사용자를 찾을 수 없습니다.");
-        }
+        if (!passwordEncoder.matches(currentPassword, member.getPassword())) {
+            throw new InvalidPasswordException("현재 비밀번호가 일치하지 않습니다.");
+        }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 28 to 38
@Transactional
public void updatePassword(String email, String currentPassword, String newPassword) {
Member member = memberRepository.findByEmail(email)
.orElseThrow(() -> new NotFoundException("사용자를 찾을 수 없습니다."));

if (!passwordEncoder.matches(currentPassword, member.getPassword())) {
throw new NotFoundException("사용자를 찾을 수 없습니다.");
}

member.updatePassword(passwordEncoder.encode(newPassword));
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

신규 비밀번호 검증 로직 추가 필요

현재 비밀번호와 동일한 새 비밀번호를 허용하는 문제가 있습니다. 또한 이전 비밀번호 재사용에 대한 검증이 없습니다.

     @Transactional
     public void updatePassword(String email, String currentPassword, String newPassword) {
         Member member = memberRepository.findByEmail(email)
                 .orElseThrow(() -> new NotFoundException("사용자를 찾을 수 없습니다."));
 
         if (!passwordEncoder.matches(currentPassword, member.getPassword())) {
-            throw new NotFoundException("사용자를 찾을 수 없습니다.");
+            throw new InvalidPasswordException("현재 비밀번호가 일치하지 않습니다.");
         }
 
+        if (passwordEncoder.matches(newPassword, member.getPassword())) {
+            throw new InvalidPasswordException("새 비밀번호는 현재 비밀번호와 달라야 합니다.");
+        }
+
         member.updatePassword(passwordEncoder.encode(newPassword));
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Transactional
public void updatePassword(String email, String currentPassword, String newPassword) {
Member member = memberRepository.findByEmail(email)
.orElseThrow(() -> new NotFoundException("사용자를 찾을 수 없습니다."));
if (!passwordEncoder.matches(currentPassword, member.getPassword())) {
throw new NotFoundException("사용자를 찾을 수 없습니다.");
}
member.updatePassword(passwordEncoder.encode(newPassword));
}
@Transactional
public void updatePassword(String email, String currentPassword, String newPassword) {
Member member = memberRepository.findByEmail(email)
.orElseThrow(() -> new NotFoundException("사용자를 찾을 수 없습니다."));
if (!passwordEncoder.matches(currentPassword, member.getPassword())) {
throw new InvalidPasswordException("현재 비밀번호가 일치하지 않습니다.");
}
if (passwordEncoder.matches(newPassword, member.getPassword())) {
throw new InvalidPasswordException("새 비밀번호는 현재 비밀번호와 달라야 합니다.");
}
member.updatePassword(passwordEncoder.encode(newPassword));
}

Comment on lines +54 to +57
public void updateProfile(String nickname, String intro) {
this.nickname = nickname;
this.intro = intro;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

프로필 이미지 URL 업데이트 메소드 누락

프로필 이미지 URL 필드가 존재하지만 업데이트 메소드가 누락되었습니다.

     public void updateProfile(String nickname, String intro) {
         this.nickname = nickname;
         this.intro = intro;
     }
+
+    public void updateProfileImage(String profileImgUrl) {
+        this.profileImgUrl = profileImgUrl;
+    }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 25 to 36
@PutMapping
public ProfileResponse updateProfile(
@AuthenticationPrincipal MemberDetails memberDetails,
@RequestBody ProfileUpdateRequest request
) {
Member updatedMember = memberService.updateProfile(
memberDetails.getMember().getEmail(),
request.nickname(),
request.intro()
);
return ProfileResponse.of(updatedMember);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

프로필 업데이트 엔드포인트의 유효성 검증 추가 필요

프로필 업데이트 메서드에 입력값 유효성 검증이 누락되어 있습니다. 닉네임의 길이 제한이나 특수문자 제한 등의 검증이 필요합니다.

다음과 같이 수정하는 것을 제안합니다:

    @PutMapping
    public ProfileResponse updateProfile(
            @AuthenticationPrincipal MemberDetails memberDetails,
-           @RequestBody ProfileUpdateRequest request
+           @RequestBody @Valid ProfileUpdateRequest request
    ) {

ProfileUpdateRequest에 다음과 같은 제약조건을 추가하세요:

public record ProfileUpdateRequest(
    @NotBlank(message = "닉네임은 필수입니다")
    @Size(min = 2, max = 20, message = "닉네임은 2-20자 사이여야 합니다")
    @Pattern(regexp = "^[a-zA-Z0-9가-힣]*$", message = "닉네임은 한글, 영문, 숫자만 가능합니다")
    String nickname,
    
    @Size(max = 200, message = "자기소개는 200자를 초과할 수 없습니다")
    String intro
) {}

Comment on lines 38 to 48
@PutMapping("/password")
public void updatePassword(
@AuthenticationPrincipal MemberDetails memberDetails,
@RequestBody PasswordUpdateRequest request
) {
memberService.updatePassword(
memberDetails.getMember().getEmail(),
request.currentPassword(),
request.newPassword()
);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

비밀번호 변경 엔드포인트의 보안 강화 필요

비밀번호 변경 로직에 다음과 같은 보안 개선이 필요합니다:

  1. 비밀번호 복잡도 검증
  2. 이전 비밀번호와 동일한지 확인
  3. 응답 상태 코드 명시

다음과 같이 수정을 제안합니다:

    @PutMapping("/password")
+   @ResponseStatus(HttpStatus.NO_CONTENT)
    public void updatePassword(
            @AuthenticationPrincipal MemberDetails memberDetails,
-           @RequestBody PasswordUpdateRequest request
+           @RequestBody @Valid PasswordUpdateRequest request
    ) {

PasswordUpdateRequest에 다음과 같은 제약조건을 추가하세요:

public record PasswordUpdateRequest(
    @NotBlank(message = "현재 비밀번호는 필수입니다")
    String currentPassword,

    @NotBlank(message = "새 비밀번호는 필수입니다")
    @Pattern(
        regexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[@$!%*#?&])[A-Za-z\\d@$!%*#?&]{8,}$",
        message = "비밀번호는 8자 이상이며, 영문자, 숫자, 특수문자를 포함해야 합니다"
    )
    String newPassword
) {}

.authorizeHttpRequests(auth -> auth
.requestMatchers(
"/","/api/auth/**", "/swagger-ui/**", "/v3/api-docs/**"
"/","/api/auth/**", "/api/profile/**", "/swagger-ui/**", "/v3/api-docs/**"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

보안 설정 변경 필요: 프로필 엔드포인트 인증 필수

프로필 관련 엔드포인트(/api/profile/**)를 인증 없이 접근 가능하도록 설정한 것은 보안상 위험합니다. 프로필 수정은 인증된 사용자만 가능해야 합니다.

다음과 같이 수정을 제안합니다:

                .requestMatchers(
-                       "/","/api/auth/**", "/api/profile/**", "/swagger-ui/**", "/v3/api-docs/**"
+                       "/","/api/auth/**", "/swagger-ui/**", "/v3/api-docs/**"
                ).permitAll()

추가로 특정 프로필 엔드포인트에 대한 세분화된 권한 설정이 필요합니다:

.requestMatchers(HttpMethod.GET, "/api/profile/**").authenticated()
.requestMatchers(HttpMethod.PUT, "/api/profile/**").authenticated()

@ohyuchan123 ohyuchan123 merged commit aa3dcfa into develop Jan 15, 2025
2 checks passed
@ohyuchan123 ohyuchan123 changed the title Profile Modify 🔀 Profile Modify Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ Feature 기능 개발 🔨 Refactor 코드 리팩토링

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant