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

feat: 비밀번호 찾기 기능 추가 #19

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.integrated.techhub.member.application;

import com.integrated.techhub.auth.domain.PasswordEncoder;
import com.integrated.techhub.member.domain.Member;
import com.integrated.techhub.member.domain.repository.MemberRepository;
import com.integrated.techhub.member.dto.MemberChangePasswordRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class MemberService {

private final PasswordEncoder passwordEncoder;
private final MemberRepository memberRepository;

public void changePassword(final MemberChangePasswordRequest request) {
final Member member = memberRepository.getByEmail(request.email());

Copy link
Contributor

Choose a reason for hiding this comment

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

요거 붙이는거 어떤가요??

member.changeEncodedPassword(passwordEncoder, request.newPassword());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public void encodePassword(final PasswordEncoder passwordEncoder) {
this.password = passwordEncoder.encode(this.password);
}

public void changeEncodedPassword(final PasswordEncoder passwordEncoder, final String newPassword) {
Copy link
Contributor

Choose a reason for hiding this comment

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

이게 먼가 좀 헷갈리네요.. 2번 생각해야한달까? changeEncodedPassword라고 하니 기존 패스워드를 변경한다는건지 패스워드를 입력받아서 암호화한다는건지 ㅠ

Copy link
Member Author

Choose a reason for hiding this comment

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

길더라도 encodeAndChangePassword 이런 느낌으로 가야겠꾼여

this.password = passwordEncoder.encode(newPassword);
}

public void validateMatchPassword(final PasswordEncoder passwordEncoder, final String requestPassword) {
if (!passwordEncoder.isMatch(requestPassword, this.password)) {
throw new PasswordNotMatchException();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.integrated.techhub.member.dto;

import com.integrated.techhub.common.exception.ErrorCode;
import com.integrated.techhub.common.exception.TechHubException;

import static org.springframework.http.HttpStatus.BAD_REQUEST;

public record MemberChangePasswordRequest(
String email,
String newPassword,
String checkPassword
) {


public void validateSamePassword() {
if (!newPassword.equals(checkPassword)) {
throw new PasswordRequestNotMatchException();
}
}
Comment on lines +15 to +19
Copy link
Contributor

Choose a reason for hiding this comment

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

비밀번호 검증은 도메인이 하는게 어떨까요?

Copy link
Member Author

Choose a reason for hiding this comment

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

이거 checkPassword라 도메인이 알필요가 잇을까여

Copy link
Contributor

Choose a reason for hiding this comment

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

네네 도메인 예외를 request가 책임질 필요가 전혀 없어보입니다

Copy link
Member Author

Choose a reason for hiding this comment

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

이거 그래서 예외를 도메인 예외 안쓰고 잘보면 request안에 예외를 쓰고 있읍니다


public class PasswordRequestNotMatchException extends TechHubException {

public PasswordRequestNotMatchException() {
super(new ErrorCode(BAD_REQUEST, "비밀번호가 일치하지 않습니다. 같은 비밀번호인지 확인해주세요."));
}

}
Comment on lines +21 to +27
Copy link
Contributor

Choose a reason for hiding this comment

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

요게 왜 여기있죠..?? 클래스로 빼는거 어떤가요

Copy link
Member Author

Choose a reason for hiding this comment

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

이게 request validation이라 여기서만 쓰일꺼 같아서 일단 여기뒀습니당


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import com.integrated.techhub.common.exception.ErrorCode;
import com.integrated.techhub.common.exception.TechHubException;

import static org.springframework.http.HttpStatus.FORBIDDEN;
import static org.springframework.http.HttpStatus.UNAUTHORIZED;

public class PasswordNotMatchException extends TechHubException {

public PasswordNotMatchException() {
super(new ErrorCode(FORBIDDEN, "유저의 비밀번호가 일치하지 않습니다."));
super(new ErrorCode(UNAUTHORIZED, "유저의 비밀번호가 일치하지 않습니다."));
Copy link
Contributor

Choose a reason for hiding this comment

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

비밀번호가 일치하지 않을 때는 403이 맞지 않나요??

Copy link
Member Author

Choose a reason for hiding this comment

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

403은 권한아닌가여? 401이 인증쪽이고

Copy link
Contributor

Choose a reason for hiding this comment

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

ㅇㅎ 401이 맞는 것 같네여

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.integrated.techhub.member.presentation;

import com.integrated.techhub.member.application.MemberService;
import com.integrated.techhub.member.dto.MemberChangePasswordRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/members")
public class MemberController {

private final MemberService memberService;

@PatchMapping("/password")
public ResponseEntity<Void> changePassword(
@RequestBody final MemberChangePasswordRequest request
) {
request.validateSamePassword();
memberService.changePassword(request);
return ResponseEntity.ok().build();
}

}
Loading