-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor #75 signup #82
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
Open
LimiteDiTempo
wants to merge
7
commits into
main
Choose a base branch
from
refactor-#75-signup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5697cab
feat: 의존성 및 yml 설정
LimiteDiTempo 9d99429
feat: 이메일 인증 코드 api 개발
LimiteDiTempo 2ae662e
feat: 이메일 코드 저장 api 개발
LimiteDiTempo a275e20
refactor: 코드 리뷰 반영
LimiteDiTempo 8faf295
feat: 회원가입 시 이메일 인증 확인 로직 추가
LimiteDiTempo 1b6dcf0
remove: remove runblocking
LimiteDiTempo 2020af1
fix: redis 및 ses 변수 설정 이슈 해결
LimiteDiTempo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| kotlin version: 2.0.20 | ||
| error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: 0. The daemon process output: | ||
| 1. Kotlin compile daemon is ready | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...cation/src/main/kotlin/com/daegusw/apply/applicant/application/port/in/web/SmtpUseCase.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.daegusw.apply.applicant.application.port.`in`.web | ||
|
|
||
| interface SmtpUseCase { | ||
| suspend fun verify(email: String, code: String): String | ||
| suspend fun send(email: String): String | ||
| } |
7 changes: 7 additions & 0 deletions
7
...ation/src/main/kotlin/com/daegusw/apply/applicant/application/port/out/redis/RedisPort.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.daegusw.apply.applicant.application.port.out.redis | ||
|
|
||
| interface RedisPort { | ||
| fun save(key: String, value: String, expiration: Long) | ||
| fun delete(key: String) | ||
| fun get(key: String): String? | ||
| } |
5 changes: 5 additions & 0 deletions
5
...ication/src/main/kotlin/com/daegusw/apply/applicant/application/port/out/smtp/SmtpPort.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.daegusw.apply.applicant.application.port.out.smtp | ||
|
|
||
| interface SmtpPort { | ||
| suspend fun send(e: String) : String | ||
| } |
28 changes: 28 additions & 0 deletions
28
...pplication/src/main/kotlin/com/daegusw/apply/applicant/application/service/SmtpService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.daegusw.apply.applicant.application.service | ||
|
|
||
| import com.daegusw.apply.applicant.application.port.`in`.web.SmtpUseCase | ||
| import com.daegusw.apply.applicant.application.port.out.redis.RedisPort | ||
| import com.daegusw.apply.applicant.application.port.out.smtp.SmtpPort | ||
| import org.springframework.stereotype.Service | ||
|
|
||
| @Service | ||
| class SmtpService( | ||
| private val stmpPort: SmtpPort, | ||
| private val redisPort: RedisPort, | ||
| ) : SmtpUseCase { | ||
|
|
||
| override suspend fun verify(email: String, code: String): String { | ||
| val value = redisPort.get(email) | ||
| if((value != null) && value == code){ | ||
| return "verified" | ||
| } | ||
| throw RuntimeException("Smtp verification failed") | ||
| } | ||
|
|
||
| override suspend fun send(email: String): String { | ||
| val code = stmpPort.send(email) | ||
| redisPort.save(email,code,3L) //3분 | ||
| return "smtp success" | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| dependencies { | ||
| implementation("org.springframework.boot:spring-boot-starter-data-redis") | ||
| implementation(project(":applicant:applicant-application")) | ||
| } |
37 changes: 37 additions & 0 deletions
37
...t-redis-adapter/src/main/kotlin/com/daegusw/apply/applicant/redis/adapter/RedisAdapter.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.daegusw.apply.applicant.redis.adapter | ||
|
|
||
| import com.daegusw.apply.applicant.application.port.out.redis.RedisPort | ||
| import org.springframework.data.redis.core.RedisTemplate | ||
| import org.springframework.stereotype.Component | ||
| import java.time.Duration | ||
|
|
||
| @Component | ||
| class RedisAdapter( | ||
| private val redisTemplate: RedisTemplate<String, String>, | ||
| ) : RedisPort { | ||
| override fun save(key: String, value: String, expiration: Long) { | ||
| try{ | ||
| redisTemplate.opsForValue().set(key, value, Duration.ofMinutes(expiration)) | ||
|
|
||
| }catch(e:Exception){ | ||
| throw e | ||
| } | ||
| } | ||
|
|
||
| override fun delete(key: String) { | ||
| try{ | ||
| redisTemplate.delete(key) | ||
| }catch(e:Exception){ | ||
| throw e | ||
| } | ||
| } | ||
|
|
||
| override fun get(key: String): String? { | ||
| try { | ||
| return redisTemplate.opsForValue().get(key) | ||
| }catch(e:Exception){ | ||
| throw e | ||
| } | ||
| } | ||
|
|
||
| } |
38 changes: 38 additions & 0 deletions
38
...s-adapter/src/main/kotlin/com/daegusw/apply/applicant/redis/adapter/common/RedisConfig.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.daegusw.apply.applicant.redis.adapter.common | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value | ||
| import org.springframework.context.annotation.Bean | ||
| import org.springframework.context.annotation.Configuration | ||
| import org.springframework.data.redis.connection.RedisConnectionFactory | ||
| import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory | ||
| import org.springframework.data.redis.core.RedisTemplate | ||
| import org.springframework.data.redis.serializer.StringRedisSerializer | ||
| import org.springframework.transaction.PlatformTransactionManager | ||
| import org.springframework.transaction.TransactionManager | ||
|
|
||
|
|
||
| @Configuration | ||
| class RedisConfig( | ||
| @Value("\${spring.redis.host}") | ||
| val host: String, | ||
|
|
||
| @Value("\${spring.redis.port}") | ||
| val port: Int, | ||
| ) { | ||
|
|
||
| @Bean | ||
| fun redisConnectionFactory(): RedisConnectionFactory { | ||
| return LettuceConnectionFactory(host, port) | ||
| } | ||
|
|
||
| @Bean | ||
| fun redisTemplate(): RedisTemplate<*, *> { | ||
| return RedisTemplate<Any, Any>().apply { | ||
| this.setConnectionFactory(redisConnectionFactory()) | ||
| // 불편한 값 삭제 | ||
| this.keySerializer = StringRedisSerializer() | ||
| this.hashKeySerializer = StringRedisSerializer() | ||
| this.valueSerializer = StringRedisSerializer() | ||
| } | ||
| } | ||
| } |
4 changes: 4 additions & 0 deletions
4
applicant/applicant-redis-adapter/src/main/resources/application.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| spring: | ||
| redis: | ||
| host: localhost | ||
| port: 6379 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| dependencies { | ||
| implementation("org.springframework.boot:spring-boot-starter-thymeleaf") | ||
| implementation("aws.sdk.kotlin:ses:0.16.0") | ||
| implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4") | ||
| implementation ("org.springframework.boot:spring-boot-starter-mail") | ||
| implementation(project(":applicant:applicant-application")) | ||
| } |
59 changes: 59 additions & 0 deletions
59
...cant-smtp-adapter/src/main/kotlin/com/daegusw/apply/applicant/smtp/adapter/SmtpAdapter.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package com.daegusw.apply.applicant.smtp.adapter | ||
|
|
||
| import aws.sdk.kotlin.runtime.auth.credentials.StaticCredentialsProvider | ||
| import aws.sdk.kotlin.services.ses.SesClient | ||
| import aws.sdk.kotlin.services.ses.model.* | ||
| import com.daegusw.apply.applicant.application.port.out.smtp.SmtpPort | ||
| import com.daegusw.apply.applicant.smtp.adapter.common.ApplicantStmpProperties | ||
| import org.springframework.stereotype.Component | ||
| import org.thymeleaf.context.Context | ||
| import org.thymeleaf.spring5.SpringTemplateEngine | ||
|
|
||
| @Component | ||
| class SmtpAdapter( | ||
| private val applicantStmpProperties: ApplicantStmpProperties, | ||
| private val templateEngine: SpringTemplateEngine, | ||
| ) : SmtpPort { | ||
| override suspend fun send(e: String) : String { | ||
| try{ | ||
| val code = (1..5).map { (0..9).random() }.joinToString("") | ||
| val context = Context() | ||
| context.setVariable("code", code) | ||
|
|
||
| val emailRequest = SendEmailRequest { | ||
| destination = Destination { | ||
| toAddresses = listOf(e) | ||
| } | ||
|
|
||
| message = Message { | ||
| subject = Content { | ||
| data = "인증 번호" | ||
| } | ||
|
|
||
| body = Body { | ||
| html = Content { | ||
| data = templateEngine.process("code", context) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| source = applicantStmpProperties.sendEmail | ||
| } | ||
|
|
||
| SesClient { | ||
| region = applicantStmpProperties.region | ||
|
|
||
| credentialsProvider = StaticCredentialsProvider { | ||
| accessKeyId = applicantStmpProperties.accessKey | ||
| secretAccessKey = applicantStmpProperties.secretKey | ||
| } | ||
| }.use { | ||
| it.sendEmail(emailRequest) | ||
| } | ||
| return code | ||
| }catch (e:Exception){ | ||
| throw RuntimeException() | ||
| } | ||
| } | ||
|
|
||
| } |
14 changes: 14 additions & 0 deletions
14
...rc/main/kotlin/com/daegusw/apply/applicant/smtp/adapter/common/ApplicantStmpProperties.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.daegusw.apply.applicant.smtp.adapter.common | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value | ||
| import org.springframework.context.annotation.PropertySource | ||
| import org.springframework.stereotype.Component | ||
|
|
||
| @Component | ||
| @PropertySource("classpath:application.yml") | ||
| class ApplicantStmpProperties ( | ||
| @Value("\${cloud.aws.credentials.access-key:access-key}") val accessKey : String, | ||
| @Value("\${cloud.aws.credentials.secret-key:secret-key}") val secretKey : String, | ||
| @Value("\${cloud.aws.region}") val region : String, | ||
| @Value("\${cloud.aws.credentials.send-mail-to}") val sendEmail : String, | ||
| ) |
15 changes: 15 additions & 0 deletions
15
applicant/applicant-smtp-adapter/src/main/resources/application.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| spring: | ||
| thymeleaf: | ||
| prefix: classpath:/templates | ||
| suffix: .html | ||
| mode: HTML | ||
| encoding: UTF-8 | ||
| check-template-location: true | ||
| cache: false | ||
| cloud: | ||
| aws: | ||
| credentials: | ||
| access-key: ${aws.credentials.accessKey} | ||
| secret-key: ${aws.credentials.secretKey} | ||
| send-mail-to: dgswcns@gmail.com | ||
| region: ap-northeast-2 |
27 changes: 27 additions & 0 deletions
27
applicant/applicant-smtp-adapter/src/main/resources/templates/stmp.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <!DOCTYPE html> | ||
| <html xmlns:th="http://www.thymeleaf.org"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | ||
| </head> | ||
| <body> | ||
| <div style="font-family: 'Apple SD Gothic Neo', 'sans-serif' !important; width: 540px; height: 600px; border-top: 4px solid #2A7AF3; margin: 100px auto; padding: 30px 0; box-sizing: border-box;"> | ||
| <h1 style="margin: 0; padding: 0 5px; font-size: 28px; font-weight: 400;"> | ||
| <span style="color: #2A7AF3">IDA 인증번호</span> 안내입니다. | ||
| </h1> | ||
| <p style="font-size: 16px; line-height: 26px; margin-top: 20px; padding: 0 5px;"> | ||
| 아래 <b style="color: #2A7AF3">인증번호</b>를 <b>3분내로</b> 입력해주세요. | ||
| </p> | ||
|
|
||
| <div style="color: #FFF; text-decoration: none; text-align: center;"> | ||
| <p style="display: inline-block; width: 210px; height: 45px; margin: 30px 5px 40px; background: #2A7AF3; line-height: 45px; vertical-align: middle; font-size: 16px;" th:text="${code}"></p> | ||
| </div> | ||
|
|
||
| <div style="border-top: 1px solid #DDD; padding: 5px;"> | ||
| <p style="font-size: 13px; line-height: 21px; color: #555;"> | ||
| 아무에게도 이 번호를 공유하지마세요. 회원 정보가 유출되는 문제가 발생 할 수 있습니다.<br/> | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...web-adapter/src/main/kotlin/com/daegusw/apply/applicant/web/adapter/api/SmtpController.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.daegusw.apply.applicant.web.adapter.api | ||
|
|
||
| import com.daegusw.apply.applicant.application.port.`in`.web.SmtpUseCase | ||
| import com.daegusw.apply.applicant.web.adapter.api.request.SmtpRequest | ||
| import com.daegusw.apply.applicant.web.adapter.api.response.SmtpResponse | ||
| import kotlinx.coroutines.runBlocking | ||
| import org.springframework.http.HttpStatus | ||
| import org.springframework.web.bind.annotation.* | ||
| import javax.validation.Valid | ||
| import javax.validation.constraints.NotEmpty | ||
|
|
||
| @RestController | ||
| @RequestMapping("/applicant/stmp") | ||
| class SmtpController( | ||
| private val smtpUseCase: SmtpUseCase | ||
| ) { | ||
| @ResponseStatus(HttpStatus.OK) | ||
| @GetMapping | ||
| fun send(@NotEmpty(message = "email is required")@RequestParam email: String) : SmtpResponse { | ||
| return runBlocking { | ||
LimiteDiTempo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| SmtpResponse( | ||
| smtpUseCase.send(email) + "로 전송 완료" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @ResponseStatus(HttpStatus.OK) | ||
| @PostMapping | ||
| fun verify(@Valid @RequestBody smtpRequest: SmtpRequest) : SmtpResponse { | ||
| return runBlocking { | ||
| SmtpResponse( | ||
| smtpUseCase.verify(smtpRequest.email,smtpRequest.code) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| } | ||
11 changes: 11 additions & 0 deletions
11
...dapter/src/main/kotlin/com/daegusw/apply/applicant/web/adapter/api/request/SmtpRequest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.daegusw.apply.applicant.web.adapter.api.request | ||
|
|
||
| import javax.validation.constraints.Email | ||
| import javax.validation.constraints.NotEmpty | ||
|
|
||
| data class SmtpRequest( | ||
| @field:Email(message = "email is required") | ||
| val email: String, | ||
| @field:NotEmpty(message = "code is required") | ||
| val code: String, | ||
| ) |
5 changes: 5 additions & 0 deletions
5
...pter/src/main/kotlin/com/daegusw/apply/applicant/web/adapter/api/response/SmtpResponse.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.daegusw.apply.applicant.web.adapter.api.response | ||
|
|
||
| data class SmtpResponse( | ||
| val message : String, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 파일은 뭔가요..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 모르겠어요..