Skip to content

Commit

Permalink
Merge pull request #102 from DEPthes/develop
Browse files Browse the repository at this point in the history
V.4.1.0 Deploy
  • Loading branch information
phonil authored Aug 17, 2024
2 parents c09cc68 + 773cc4c commit 8741991
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class AuthServiceImpl implements AuthService{
@Transactional
public SuccessResponse<Message> join(JoinReq joinReq) {
String email = joinReq.getEmail();
checkVerify(joinReq.getEmail());
checkJoinVerify(joinReq.getEmail());

if (memberRepository.existsByEmail(email))
throw new IllegalArgumentException("이미 가입된 이메일입니다.");
Expand Down Expand Up @@ -152,7 +152,7 @@ public SuccessResponse<EmailDuplicateCheckRes> checkEmailDuplicate(String email)
@Transactional
public SuccessResponse<Message> modifyPassword(ModifyPasswordReq modifyPasswordReq) {
String email = modifyPasswordReq.getEmail();
checkVerify(email);
checkPasswordEmailVerify(email);

memberRepository.findByEmail(email)
.ifPresentOrElse(
Expand All @@ -169,10 +169,16 @@ public SuccessResponse<Message> modifyPassword(ModifyPasswordReq modifyPasswordR
return SuccessResponse.of(message);
}

private void checkVerify(String email) {
private void checkJoinVerify(String email) {
String data = redisUtil.getData(email + "_verify");
if (data == null)
throw new IllegalArgumentException("인증이 필요한 이메일입니다.");
redisUtil.deleteData(email + "_verify");
}

private void checkPasswordEmailVerify(String email) {
String data = redisUtil.getData(email + "_verify");
if (data != null)
throw new IllegalArgumentException("인증이 필요한 이메일입니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ ResponseEntity<SuccessResponse<EmailDuplicateCheckRes>> checkEmailDuplicate (
content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}
)
})

@PutMapping(value = "/password")
ResponseEntity<SuccessResponse<Message>> modifyPassword (
@Parameter(description = "비밀번호를 변경할 계정의 이메일을 입력해주세요.", required = true) @Valid @RequestBody ModifyPasswordReq modifyPasswordReq
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mvp/deplog/global/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class SecurityConfig {

private static final String[] WHITE_LIST = {
"/swagger", "/swagger-ui.html", "/swagger-ui/**", "/v3/api-docs/**",
"/auth/**",
"/auth/**", "/auth/password",
"/comments/**",
"/mails/**", "/verification-email",
"/posts/**",
Expand All @@ -45,7 +45,7 @@ public class SecurityConfig {
};

private static final String[] NEED_TOKEN = {
"/auth/reissue", "/auth/password",
"/auth/reissue",
"/likes/**",
"/members/**",
"/scraps/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mvp.deplog.global.common.SuccessResponse;
import mvp.deplog.infrastructure.mail.dto.MailCodeRes;
import mvp.deplog.infrastructure.mail.MailUtil;
import mvp.deplog.infrastructure.mail.dto.MailVerifyRes;
import mvp.deplog.infrastructure.redis.RedisUtil;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -50,4 +51,18 @@ public String verifyCode(String code) {
redisUtil.setDataExpire(email + VERIFY_SUFFIX, String.valueOf(true), 60 * 60L);
return "success";
}

public SuccessResponse<MailVerifyRes> checkVerify(String email) {
String data = redisUtil.getData(email + "_verify");
boolean verified = data != null;

if (verified)
redisUtil.deleteData(email + "_verify");

MailVerifyRes mailVerifyRes = MailVerifyRes.builder()
.verified(verified)
.build();

return SuccessResponse.of(mailVerifyRes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package mvp.deplog.infrastructure.mail.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class MailVerifyRes {

@Schema(type = "boolean", example = "true", description = "이메일 인증 여부를 출력합니다. 메일로 받은 링크 클릭 후라면 true 입니다.")
private boolean verified;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import mvp.deplog.global.common.SuccessResponse;
import mvp.deplog.global.exception.ErrorResponse;
import mvp.deplog.infrastructure.mail.dto.MailCodeRes;
import mvp.deplog.infrastructure.mail.dto.MailVerifyRes;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand Down Expand Up @@ -56,4 +57,20 @@ String verify(
@Parameter(description = "메일 발송 시 응답받은 코드를 사용해주세요.", required = true) @RequestParam String code,
HttpServletResponse response
) throws IOException;

@Operation(summary = "메일 인증 확인 API", description = "메일 인증 여부를 확인합니다.")
@ApiResponses(value = {
@ApiResponse(
responseCode = "200", description = "메일 인증 여부 확인 성공",
content = {@Content(mediaType = "application/json", schema = @Schema(implementation = MailVerifyRes.class))}
),
@ApiResponse(
responseCode = "400", description = "메일 인증 여부 확인 실패",
content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}
)
})
@GetMapping
ResponseEntity<SuccessResponse<MailVerifyRes>> checkVerify(
@Parameter(description = "이메일을 입력해주세요.", required = true) @RequestParam String email
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import mvp.deplog.global.common.SuccessResponse;
import mvp.deplog.infrastructure.mail.dto.MailCodeRes;
import mvp.deplog.infrastructure.mail.application.MailService;
import mvp.deplog.infrastructure.mail.dto.MailVerifyRes;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
Expand All @@ -30,4 +31,10 @@ public ResponseEntity<SuccessResponse<MailCodeRes>> sendMail(@RequestParam Strin
public String verify(@RequestParam String code, HttpServletResponse response) throws IOException {
return mailService.verifyCode(code);
}

@Override
@GetMapping("/verified")
public ResponseEntity<SuccessResponse<MailVerifyRes>> checkVerify(@RequestParam String email) {
return ResponseEntity.ok(mailService.checkVerify(email));
}
}

0 comments on commit 8741991

Please sign in to comment.