Skip to content

Commit

Permalink
feat: 이메일 인증 코드 검증 구현 (#54) (KAN-106)
Browse files Browse the repository at this point in the history
  • Loading branch information
ywonchae1 committed Oct 31, 2024
1 parent e65243a commit d30135e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.ioteatime.meonghanyangserver.auth.dto.reponse.RefreshResponse;
import org.ioteatime.meonghanyangserver.auth.dto.request.EmailRequest;
import org.ioteatime.meonghanyangserver.auth.dto.request.LoginRequest;
import org.ioteatime.meonghanyangserver.auth.dto.request.VerifyEmailRequest;
import org.ioteatime.meonghanyangserver.common.api.Api;
import org.ioteatime.meonghanyangserver.user.dto.UserDto;
import org.ioteatime.meonghanyangserver.user.dto.response.UserSimpleResponse;
Expand All @@ -19,7 +20,10 @@ public interface AuthApi {
Api<Object> registerUser(@Valid @RequestBody UserDto userDto);

@Operation(summary = "인증 메일 전송")
Api<?> verifyEmail(@Valid @RequestBody EmailRequest email);
Api<?> sendEmailCode(@Valid @RequestBody EmailRequest email);

@Operation(summary = "메일 인증 코드 검증")
Api<?> verifyEmail(@Valid @RequestBody VerifyEmailRequest verifyEmailRequest);

@Operation(summary = "로그인을 합니다.")
Api<LoginResponse> login(@RequestBody @Valid LoginRequest loginRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.ioteatime.meonghanyangserver.auth.dto.reponse.RefreshResponse;
import org.ioteatime.meonghanyangserver.auth.dto.request.EmailRequest;
import org.ioteatime.meonghanyangserver.auth.dto.request.LoginRequest;
import org.ioteatime.meonghanyangserver.auth.dto.request.VerifyEmailRequest;
import org.ioteatime.meonghanyangserver.auth.service.AuthService;
import org.ioteatime.meonghanyangserver.common.api.Api;
import org.ioteatime.meonghanyangserver.user.dto.UserDto;
Expand All @@ -25,11 +26,17 @@ public Api<Object> registerUser(@Valid @RequestBody UserDto userDto) {
}

@PostMapping("/email-verification")
public Api<?> verifyEmail(@Valid @RequestBody EmailRequest emailReq) {
public Api<?> sendEmailCode(@Valid @RequestBody EmailRequest emailReq) {
authService.send(emailReq.email());
return Api.OK();
}

@PostMapping("/check-verification")
public Api<?> verifyEmail(VerifyEmailRequest verifyEmailRequest) {
authService.verifyEmailCode(verifyEmailRequest.email(), verifyEmailRequest.code());
return Api.OK();
}

// Email 중복 확인
@PostMapping("/check-email")
public Api<UserSimpleResponse> duplicateEmail(@Valid @RequestBody EmailRequest emailReq) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.ioteatime.meonghanyangserver.auth.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotNull;

public record VerifyEmailRequest(
@Email @NotNull @Schema(description = "이메일", example = "[email protected]") String email,
@NotNull @Schema(description = "인증 코드", example = "XV23W1") String code) {}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ public UserSimpleResponse verifyEmail(String email) {
return AuthResponseMapper.from(userEntity.getId(), userEntity.getEmail());
}

public void verifyEmailCode(String email, String code) {
EmailCode emailCode =
emailCodeRepository
.findByEmail(email)
.orElseThrow(
() ->
new ApiExceptionImpl(
ErrorTypeCode.NULL_POINT, "Code not found"));
if (!code.equals(emailCode.getCode())) {
throw new ApiExceptionImpl(ErrorTypeCode.NULL_POINT, "Code not equals");
}
}

public RefreshResponse reissueAccessToken(String authorizationHeader) {
String refreshToken = jwtUtils.extractTokenFromHeader(authorizationHeader);

Expand Down

0 comments on commit d30135e

Please sign in to comment.