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: 이메일 인증 코드 검증 구현 #55

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
@@ -1,10 +1,8 @@
package org.ioteatime.meonghanyangserver.auth.dto.request;

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

public record EmailRequest(
@Valid @Email @NotNull @Schema(description = "이메일", example = "[email protected]")
String email) {}
@Email @NotNull @Schema(description = "이메일", example = "[email protected]") String email) {}
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
Loading