From 13ec1e0a241fbf521eb405615126c5c507b2d9d8 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Wed, 11 Oct 2023 14:46:48 +0900 Subject: [PATCH 1/8] =?UTF-8?q?:memo:=20EmailKeyInvalidException=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../miso/domain/auth/exception/EmailKeyInvalidException.kt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/auth/exception/EmailKeyInvalidException.kt diff --git a/src/main/kotlin/andreas311/miso/domain/auth/exception/EmailKeyInvalidException.kt b/src/main/kotlin/andreas311/miso/domain/auth/exception/EmailKeyInvalidException.kt new file mode 100644 index 00000000..07f7af4b --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/auth/exception/EmailKeyInvalidException.kt @@ -0,0 +1,7 @@ +package andreas311.miso.domain.auth.exception + +import andreas311.miso.global.error.exception.ErrorCode +import andreas311.miso.global.error.exception.MisoException + +class EmailKeyInvalidException : MisoException(ErrorCode.EMAIL_KEY_IS_INVALID) { +} \ No newline at end of file From 11c2bcec0b65de764380dd4b827c55a6ad43752f Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Wed, 11 Oct 2023 14:46:54 +0900 Subject: [PATCH 2/8] =?UTF-8?q?:memo:=20EmailCheckRequestDto=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../email/presentation/data/request/EmailCheckRequestDto.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/email/presentation/data/request/EmailCheckRequestDto.kt diff --git a/src/main/kotlin/andreas311/miso/domain/email/presentation/data/request/EmailCheckRequestDto.kt b/src/main/kotlin/andreas311/miso/domain/email/presentation/data/request/EmailCheckRequestDto.kt new file mode 100644 index 00000000..9afe32f4 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/email/presentation/data/request/EmailCheckRequestDto.kt @@ -0,0 +1,5 @@ +package andreas311.miso.domain.email.presentation.data.request + +data class EmailCheckRequestDto( + val randomKey: String +) From f4f0baf891af8f018b759b65d3f1bd0bd4890fb0 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Wed, 11 Oct 2023 14:47:18 +0900 Subject: [PATCH 3/8] =?UTF-8?q?:fire:=20Email=20=EC=97=90=20updateRandomKe?= =?UTF-8?q?y=20=ED=95=A8=EC=88=98=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/andreas311/miso/domain/email/entity/Email.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/kotlin/andreas311/miso/domain/email/entity/Email.kt b/src/main/kotlin/andreas311/miso/domain/email/entity/Email.kt index 82bcd545..22118f3e 100644 --- a/src/main/kotlin/andreas311/miso/domain/email/entity/Email.kt +++ b/src/main/kotlin/andreas311/miso/domain/email/entity/Email.kt @@ -21,9 +21,6 @@ class Email( @Column(name = "authentication") var authentication: Boolean ) { - fun updateRandomKey(randomKey: String) { - this.randomKey = randomKey - } fun updateAuthentication(authentication: Boolean) { this.authentication = authentication From 2ca95d16e30e4f07942ea22c1d2eca07ba39b87a Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Wed, 11 Oct 2023 14:47:38 +0900 Subject: [PATCH 4/8] =?UTF-8?q?:memo:=20EmailRepository=20=EC=97=90=20find?= =?UTF-8?q?ByRandomKey=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../andreas311/miso/domain/email/repository/EmailRepository.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/andreas311/miso/domain/email/repository/EmailRepository.kt b/src/main/kotlin/andreas311/miso/domain/email/repository/EmailRepository.kt index 14d86e94..849fe298 100644 --- a/src/main/kotlin/andreas311/miso/domain/email/repository/EmailRepository.kt +++ b/src/main/kotlin/andreas311/miso/domain/email/repository/EmailRepository.kt @@ -10,4 +10,6 @@ interface EmailRepository : CrudRepository { fun deleteByEmail(email: String) fun existsByEmail(email: String): Boolean + + fun findByRandomKey(randomKey: String): Email? } \ No newline at end of file From 7fb310770192171dec8be7804e54bd8624e9e07e Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Wed, 11 Oct 2023 14:48:09 +0900 Subject: [PATCH 5/8] =?UTF-8?q?:memo:=20ErrorCode=20=EC=97=90=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=EB=B2=88=ED=98=B8=20=ED=99=95=EC=9D=B8=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=97=90=EB=9F=AC=20enum=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/andreas311/miso/global/error/exception/ErrorCode.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/andreas311/miso/global/error/exception/ErrorCode.kt b/src/main/kotlin/andreas311/miso/global/error/exception/ErrorCode.kt index 01fd6436..716ec822 100644 --- a/src/main/kotlin/andreas311/miso/global/error/exception/ErrorCode.kt +++ b/src/main/kotlin/andreas311/miso/global/error/exception/ErrorCode.kt @@ -12,6 +12,7 @@ enum class ErrorCode( EMAIL_SEND_FAIL(500, "사용자를 찾을 수 없습니다."), // USER + EMAIL_KEY_IS_INVALID(401, "이메일 인증번호가 일치하지 않습니다."), EMAIL_IS_NOT_VALID(403, "인증되지 않은 이메일입니다."), USER_NOT_FOUND(404, "사용자를 찾을 수 없습니다."), ROLE_NOT_EXIST(404, "역할이 존재하지 않습니다"), From 3f69661b679642d710a0515077046cc75154d778 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Wed, 11 Oct 2023 14:48:38 +0900 Subject: [PATCH 6/8] =?UTF-8?q?:memo:=20SecurityConfig=20=EC=97=90=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=20=EB=B2=88=ED=98=B8=20=ED=99=95=EC=9D=B8=20?= =?UTF-8?q?api=20=EA=B6=8C=ED=95=9C=20=EC=84=A4=EC=A0=95=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/andreas311/miso/global/security/SecurityConfig.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/andreas311/miso/global/security/SecurityConfig.kt b/src/main/kotlin/andreas311/miso/global/security/SecurityConfig.kt index 2fb983b6..0cb0efa2 100644 --- a/src/main/kotlin/andreas311/miso/global/security/SecurityConfig.kt +++ b/src/main/kotlin/andreas311/miso/global/security/SecurityConfig.kt @@ -41,6 +41,8 @@ class SecurityConfig( .antMatchers(HttpMethod.POST, "/auth").permitAll() .antMatchers(HttpMethod.POST, "/auth/signIn").permitAll() + .antMatchers(HttpMethod.POST, "/email").permitAll() + .anyRequest().denyAll() .and() .exceptionHandling() From 5c062a2d26e54d0f406f2d18a314bc3de4e53d19 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Wed, 11 Oct 2023 14:48:54 +0900 Subject: [PATCH 7/8] =?UTF-8?q?:sparkles:=20=EC=9D=B8=EC=A6=9D=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=ED=99=95=EC=9D=B8=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/email/service/EmailCheckService.kt | 8 +++++++ .../service/impl/EmailCheckServiceImpl.kt | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/email/service/EmailCheckService.kt create mode 100644 src/main/kotlin/andreas311/miso/domain/email/service/impl/EmailCheckServiceImpl.kt diff --git a/src/main/kotlin/andreas311/miso/domain/email/service/EmailCheckService.kt b/src/main/kotlin/andreas311/miso/domain/email/service/EmailCheckService.kt new file mode 100644 index 00000000..253de6e4 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/email/service/EmailCheckService.kt @@ -0,0 +1,8 @@ +package andreas311.miso.domain.email.service + +import andreas311.miso.domain.email.presentation.data.request.EmailCheckRequestDto + +interface EmailCheckService { + + fun execute(emailCheckRequestDto: EmailCheckRequestDto) +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/email/service/impl/EmailCheckServiceImpl.kt b/src/main/kotlin/andreas311/miso/domain/email/service/impl/EmailCheckServiceImpl.kt new file mode 100644 index 00000000..50681e66 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/email/service/impl/EmailCheckServiceImpl.kt @@ -0,0 +1,21 @@ +package andreas311.miso.domain.email.service.impl + +import andreas311.miso.domain.auth.exception.EmailKeyInvalidException +import andreas311.miso.domain.email.presentation.data.request.EmailCheckRequestDto +import andreas311.miso.domain.email.repository.EmailRepository +import andreas311.miso.domain.email.service.EmailCheckService +import andreas311.miso.global.annotation.RollbackService + +@RollbackService +class EmailCheckServiceImpl( + private val emailRepository: EmailRepository +) : EmailCheckService { + + override fun execute(emailCheckRequestDto: EmailCheckRequestDto) { + + val email = emailRepository.findByRandomKey(emailCheckRequestDto.randomKey) + ?: throw EmailKeyInvalidException() + + email.updateAuthentication(true) + } +} \ No newline at end of file From a2f10ff328006a85660c2a619cb7fc1558b7c086 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Wed, 11 Oct 2023 14:49:09 +0900 Subject: [PATCH 8/8] =?UTF-8?q?:sparkles:=20EmailController=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20=EC=9D=B8=EC=A6=9D=20=EB=B2=88=ED=98=B8?= =?UTF-8?q?=20=ED=99=95=EC=9D=B8=20api=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../email/presentation/EmailController.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/email/presentation/EmailController.kt diff --git a/src/main/kotlin/andreas311/miso/domain/email/presentation/EmailController.kt b/src/main/kotlin/andreas311/miso/domain/email/presentation/EmailController.kt new file mode 100644 index 00000000..c0567cfb --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/email/presentation/EmailController.kt @@ -0,0 +1,20 @@ +package andreas311.miso.domain.email.presentation + +import andreas311.miso.domain.email.presentation.data.request.EmailCheckRequestDto +import andreas311.miso.domain.email.service.EmailCheckService +import andreas311.miso.global.annotation.RequestController +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody + +@RequestController("/email") +class EmailController( + private val emailCheckService: EmailCheckService +) { + + @PostMapping + fun emailCheck(@RequestBody emailCheckRequestDto: EmailCheckRequestDto): ResponseEntity = + emailCheckService.execute(emailCheckRequestDto) + .let { ResponseEntity.status(HttpStatus.OK).build() } +} \ No newline at end of file