-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
93 additions
and
67 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/config/RedisConfig.kt
This file contains 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.wafflestudio.toyproject.memoWithTags.config | ||
|
||
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.GenericJackson2JsonRedisSerializer | ||
import org.springframework.data.redis.serializer.StringRedisSerializer | ||
|
||
@Configuration | ||
class RedisConfig( | ||
@Value("\${spring.data.redis.host}") private val host: String, | ||
@Value("\${spring.data.redis.port}") private val port: Int | ||
) { | ||
@Bean | ||
fun redisConnectionFactory(): RedisConnectionFactory = LettuceConnectionFactory(host, port) | ||
|
||
@Bean | ||
fun redisTemplate(factory: RedisConnectionFactory): RedisTemplate<String, Any> { | ||
val template = RedisTemplate<String, Any>() | ||
template.connectionFactory = factory | ||
template.keySerializer = StringRedisSerializer() | ||
template.valueSerializer = GenericJackson2JsonRedisSerializer() | ||
return template | ||
} | ||
} |
13 changes: 4 additions & 9 deletions
13
src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/mail/EmailVerification.kt
This file contains 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 |
---|---|---|
@@ -1,26 +1,21 @@ | ||
package com.wafflestudio.toyproject.memoWithTags.mail | ||
|
||
import com.wafflestudio.toyproject.memoWithTags.mail.persistence.EmailVerificationEntity | ||
import java.time.LocalDateTime | ||
|
||
class EmailVerification( | ||
val id: Long, | ||
val email: String, | ||
val code: String, | ||
val expiryTime: LocalDateTime | ||
val code: String | ||
) { | ||
companion object { | ||
fun fromEntity(entity: EmailVerificationEntity): EmailVerification { | ||
return EmailVerification( | ||
id = entity.id!!, | ||
email = entity.email, | ||
code = entity.code, | ||
expiryTime = entity.expiryTime | ||
email = entity.id, | ||
code = entity.code | ||
) | ||
} | ||
} | ||
|
||
override fun toString(): String { | ||
return "{id: $id, email: $email, code: $code, expiryTime: $expiryTime}" | ||
return "{email: $email, code: $code}" | ||
} | ||
} |
39 changes: 21 additions & 18 deletions
39
...tlin/com/wafflestudio/toyproject/memoWithTags/mail/persistence/EmailVerificationEntity.kt
This file contains 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 |
---|---|---|
@@ -1,23 +1,26 @@ | ||
package com.wafflestudio.toyproject.memoWithTags.mail.persistence | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import java.time.LocalDateTime | ||
import org.springframework.data.redis.core.RedisHash | ||
import org.springframework.data.redis.core.TimeToLive | ||
import org.springframework.data.redis.core.index.Indexed | ||
|
||
@Entity(name = "emails") | ||
class EmailVerificationEntity( | ||
@RedisHash(value = "email_verification") | ||
data class EmailVerificationEntity( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long? = null, | ||
@Column(name = "email", nullable = false) | ||
val email: String, | ||
@Column(name = "code", nullable = false) | ||
val code: String, | ||
@Column(name = "verified", nullable = false) | ||
var verified: Boolean = false, | ||
@Column(name = "expiryTime", nullable = false) | ||
val expiryTime: LocalDateTime | ||
) | ||
val id: String, // email ([email protected]) | ||
|
||
@Indexed | ||
val code: String, // verification code (000000) | ||
|
||
var verified: Boolean // default: false, verified user: true | ||
) { | ||
@TimeToLive | ||
fun getTimeToLive(): Long { | ||
return if (verified) { | ||
86400 // 메일 인증이 확인된 인증 정보는 TTL 24시간으로 설정 | ||
} else { | ||
300 // 메일 인증을 완료하지 않은 인증 정보는 TTL 5분으로 설정 | ||
} | ||
} | ||
} |
10 changes: 3 additions & 7 deletions
10
.../com/wafflestudio/toyproject/memoWithTags/mail/persistence/EmailVerificationRepository.kt
This file contains 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 |
---|---|---|
@@ -1,11 +1,7 @@ | ||
package com.wafflestudio.toyproject.memoWithTags.mail.persistence | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import java.time.LocalDateTime | ||
import org.springframework.data.repository.CrudRepository | ||
|
||
interface EmailVerificationRepository : JpaRepository<EmailVerificationEntity, Long> { | ||
fun deleteByExpiryTimeBefore(expiryTime: LocalDateTime) | ||
fun deleteAllByEmail(email: String) | ||
fun findByEmail(email: String): EmailVerificationEntity? | ||
fun findByEmailAndCode(email: String, code: String): EmailVerificationEntity? | ||
interface EmailVerificationRepository : CrudRepository<EmailVerificationEntity, String> { | ||
fun deleteAllById(id: String) | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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