Skip to content

Commit

Permalink
Merge pull request #530 from JNU-econovation/be
Browse files Browse the repository at this point in the history
BE 환경에 반영
  • Loading branch information
hwangdaesun authored Oct 9, 2024
2 parents 918b033 + bae1cfb commit 2b1e7e8
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import com.gaebaljip.exceed.adapter.in.member.request.FindPasswordRequest;
import com.gaebaljip.exceed.adapter.in.member.request.SendEmailRequest;
import com.gaebaljip.exceed.adapter.in.member.request.UpdatePasswordRequest;
import com.gaebaljip.exceed.application.port.in.member.CheckCodeUsecase;
import com.gaebaljip.exceed.application.port.in.member.GetCodeUsecase;
import com.gaebaljip.exceed.application.port.in.member.PasswordValidationUsecase;
import com.gaebaljip.exceed.application.port.in.member.UpdatePasswordUsecase;
import com.gaebaljip.exceed.common.ApiResponse;
import com.gaebaljip.exceed.common.ApiResponse.CustomBody;
import com.gaebaljip.exceed.common.ApiResponseGenerator;
import com.gaebaljip.exceed.common.docs.member.UpdatePassword_updatePasswordExceptionDocs;
import com.gaebaljip.exceed.common.docs.member.UpdatePassword_validateEmailExceptionDocs;
import com.gaebaljip.exceed.common.docs.member.FindPassword_updatePasswordExceptionDocs;
import com.gaebaljip.exceed.common.docs.member.FindPassword_validateEmailExceptionDocs;
import com.gaebaljip.exceed.common.swagger.ApiErrorExceptionsExample;

import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -27,8 +27,8 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1")
@Tag(name = "[비밀번호 변경]")
public class UpdatePasswordController {
@Tag(name = "[비밀번호 찾기]")
public class FindPasswordController {

private final PasswordValidationUsecase passwordValidationUsecase;
private final GetCodeUsecase getCodeUsecase;
Expand All @@ -40,18 +40,18 @@ public class UpdatePasswordController {
private final UpdatePasswordUsecase updatePasswordUsecase;

@Operation(
summary = "비밀번호 변경 전 이메일 검증 및 메일 전송",
description = "비밀번호 변경하기 전, 이메일 검증 및 이메일을 재전송한다.")
summary = "비밀번호 찾기 전 이메일 검증 및 메일 전송",
description = "비밀번호 찾기 전, 이메일 검증 및 이메일을 재전송한다.")
@PostMapping("/email")
@ApiErrorExceptionsExample(UpdatePassword_validateEmailExceptionDocs.class)
@ApiErrorExceptionsExample(FindPassword_validateEmailExceptionDocs.class)
public ApiResponse<CustomBody<Void>> validateEmail(
@RequestBody @Valid SendEmailRequest request) {
passwordValidationUsecase.execute(request.email());
return ApiResponseGenerator.success(HttpStatus.OK);
}

@Operation(summary = "링크 클릭시 리다이렉트", description = "AOS는 몰라도 되는 API")
@GetMapping("/updatePassword-redirect")
@GetMapping("/findPassword-redirect")
public void redirect(@RequestParam String email, HttpServletResponse response) {
StringBuilder sb = new StringBuilder();
String code = getCodeUsecase.execute(email);
Expand All @@ -61,13 +61,11 @@ public void redirect(@RequestParam String email, HttpServletResponse response) {
}

@Operation(
summary = "비밀번호 찾기 및 변경",
description = "비밀번호 변경시 사용하고, 비밀번호를 찾을 시에도 무조건 비밀번호를 변경한다.")
@PatchMapping("/members/password")
@ApiErrorExceptionsExample(UpdatePassword_updatePasswordExceptionDocs.class)
public ApiResponse<CustomBody<Void>> updatePassword(
@RequestBody @Valid UpdatePasswordRequest request) {
passwordValidationUsecase.execute(request.email());
summary = "비밀번호 찾기",
description = "비밀번호를 찾을 때 사용한다. 단, 비밀번호 찾기 버튼을 누르는 것이지 실제로는 새로운 비밀번호로 수정한다.")
@PatchMapping("/members/find-password")
@ApiErrorExceptionsExample(FindPassword_updatePasswordExceptionDocs.class)
public ApiResponse<CustomBody<Void>> findPassword(@RequestBody @Valid FindPasswordRequest request) {
checkCodeUsecase.execute(request.email(), request.code());
updatePasswordUsecase.execute(request.email(), request.newPassword());
return ApiResponseGenerator.success(HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

import lombok.Builder;

public record UpdatePasswordRequest(
public record FindPasswordRequest(
@Email(message = ValidationMessage.INVALID_EMAIL) String email,
@Password(message = ValidationMessage.INVALID_PASSWORD) String newPassword,
@NotBlank(message = "인증 코드를 " + ValidationMessage.NOT_BLANK) String code) {

@Builder
public UpdatePasswordRequest {}
public FindPasswordRequest {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

public class MailTemplate {
public static final String SIGN_UP_TEMPLATE = "signup";
public static final String UPDATE_PASSWORD_TEMPLATE = "updatePassword";
public static final String FIND_PASSWORD_TEMPLATE = "findPassword";

public static final String SIGN_UP_TITLE = "Eatceed 회원가입 인증 메일";
public static final String UPDATE_PASSWORD_TITLE = "Eatceed 비밀번호 변경 메일";
public static final String FIND_PASSWORD_TITLE = "Eatceed 비밀번호 찾기 메일";
public static final String SIGN_UP_MAIL_CONTEXT = "signupLink";
public static final String UPDATE_PASSWORD_MAIL_CONTEXT = "updatePasswordLink";
public static final String FIND_PASSWORD_MAIL_CONTEXT = "findPasswordLink";
public static final String SIGN_UP_EMAIL = "email";
public static final String UPDATE_PASSWORD_EMAIL = "email";
public static final String FIND_PASSWORD_EMAIL = "email";
public static final String REPLY_TO_SIGN_UP_MAIL_URL = "/v1/signUp-redirect";
public static final String REPLY_TO_UPDATE_PASSWORD_MAIL_URL = "/v1/updatePassword-redirect";
public static final String REPLY_TO_FIND_PASSWORD_MAIL_URL = "/v1/findPassword-redirect";
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.gaebaljip.exceed.common.swagger.SwaggerExampleExceptions;

@ExceptionDoc
public class UpdatePassword_updatePasswordExceptionDocs implements SwaggerExampleExceptions {
public class FindPassword_updatePasswordExceptionDocs implements SwaggerExampleExceptions {

@ExplainError("회원이 존재하지 않을 때")
public EatCeedException 회원이_존재하지_않을_때 = MemberNotFoundException.EXECPTION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.gaebaljip.exceed.common.swagger.SwaggerExampleExceptions;

@ExceptionDoc
public class UpdatePassword_validateEmailExceptionDocs implements SwaggerExampleExceptions {
public class FindPassword_validateEmailExceptionDocs implements SwaggerExampleExceptions {

@ExplainError("회원이 존재하지 않을 때")
public EatCeedException 회원이_존재하지_않을_때 = MemberNotFoundException.EXECPTION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public void handle(SendEmailEvent event) {
codePort.saveWithExpiration(event.getEmail(), Code.create(), expiredTime);
Context context = new Context();
context.setVariable(
MailTemplate.UPDATE_PASSWORD_MAIL_CONTEXT,
URL + MailTemplate.REPLY_TO_UPDATE_PASSWORD_MAIL_URL);
context.setVariable(MailTemplate.UPDATE_PASSWORD_EMAIL, "?email=" + event.getEmail());
MailTemplate.FIND_PASSWORD_MAIL_CONTEXT,
URL + MailTemplate.REPLY_TO_FIND_PASSWORD_MAIL_URL);
context.setVariable(MailTemplate.FIND_PASSWORD_EMAIL, "?email=" + event.getEmail());
emailPort.sendEmail(
event.getEmail(),
MailTemplate.UPDATE_PASSWORD_TITLE,
MailTemplate.UPDATE_PASSWORD_TEMPLATE,
MailTemplate.FIND_PASSWORD_TITLE,
MailTemplate.FIND_PASSWORD_TEMPLATE,
context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
"/v1/members/email/checked",
"/actuator/**",
"/v1/health",
"/v1//updatePassword-redirect",
"/v1//findPassword-redirect",
"/v1/signUp-redirect")
.permitAll()
.antMatchers(HttpMethod.PUT, "/v1/members/email/confirmed")
.permitAll()
.antMatchers(HttpMethod.PATCH, "/v1/members/checked", "/v1/members/password")
.antMatchers(HttpMethod.PATCH, "/v1/members/checked", "/v1/members/find-password")
.permitAll()
.antMatchers(HttpMethod.POST, "/v1/members", "/v1/email")
.permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Eatceed 비밀번호 변경</title>
<title>Eatceed 비밀번호 찾기</title>
</head>
<body>
<h2>비밀번호 변경</h2>
<p>안녕하세요 체중 증량 어플 Eatceed입니다.</p>
<p>아래의 링크를 클릭해 비밀번호 변경 페이지로 이동해주세요.</p>
<p>아래의 링크를 클릭해 비밀번호 찾기 페이지로 이동해주세요.</p>
<p>인증을 요청하지 않았다면, 이 이메일을 무시하셔도 됩니다.</p>
<a th:href="${updatePasswordLink} + ${email}">비밀번호 변경 링크</a>
<a th:href="${findPasswordLink} + ${email}">비밀번호 변경 링크</a>
<link rel="shortcut icon" type="image/x-icon" href="data:image/x-icon;," >
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void when_login_expected_fail2() throws Exception {
void when_login_expected_success() throws Exception {
LoginRequest loginRequest = new LoginRequest("[email protected]", "Abc@123");
TokenDTO tokenDTO = new TokenDTO("accessToken", "refreshToken");
given(authService.execute(loginRequest)).willReturn(tokenDTO);
given(authService.login(loginRequest)).willReturn(tokenDTO);

ResultActions resultActions =
mockMvc.perform(
Expand Down

0 comments on commit 2b1e7e8

Please sign in to comment.