-
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
1 parent
4bd1ad6
commit 775b4c3
Showing
18 changed files
with
158 additions
and
40 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
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
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/com/ohayo/moyamoya/core/PhoneCodeEntity.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,22 @@ | ||
package com.ohayo.moyamoya.core | ||
|
||
import jakarta.persistence.* | ||
|
||
@Entity | ||
@Table(name = "tbl_phone_code") | ||
class PhoneCodeEntity( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Int = 0, | ||
@Column(nullable = false) | ||
val phone: String, | ||
@Column(nullable = false) | ||
val code: String, | ||
@Column(nullable = false) | ||
var isActive: Boolean = true | ||
) { | ||
|
||
fun disable() { | ||
this.isActive = false | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/ohayo/moyamoya/core/PhoneCodeRepository.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,9 @@ | ||
package com.ohayo.moyamoya.core | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Query | ||
|
||
interface PhoneCodeRepository: JpaRepository<PhoneCodeEntity, Int> { | ||
@Query("SELECT m FROM PhoneCodeEntity m WHERE m.isActive = true AND m.phone = :phone AND m.code = :code") | ||
fun findByIsActive(phone: String, code: String): List<PhoneCodeEntity> | ||
} |
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
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
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/com/ohayo/moyamoya/infra/sms/CoolSMSProperties.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,12 @@ | ||
package com.ohayo.moyamoya.infra.sms | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding | ||
import org.springframework.boot.context.properties.bind.ConstructorBinding | ||
|
||
@ConfigurationProperties("coolsms") | ||
class CoolSMSProperties @ConstructorBinding constructor( | ||
val apiKey: String, | ||
val apiSecret: String, | ||
val senderPhone: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.ohayo.moyamoya.infra.sms | ||
|
||
import net.nurigo.java_sdk.api.Message | ||
import net.nurigo.java_sdk.exceptions.CoolsmsException | ||
import org.springframework.stereotype.Component | ||
@Component | ||
class SmsClient( | ||
private val coolSMSProperties: CoolSMSProperties | ||
) { | ||
fun sendAuthorizationCode(phone: String): String { | ||
val authorizationCode = ((Math.random() * (999999 - 100000 + 1)).toInt() + 100000).toString() | ||
val text = "[모야모야]\n인증번호: $authorizationCode\n인증 번호를 입력해주세요." | ||
|
||
sendText(phone = phone, text = text) | ||
|
||
return authorizationCode | ||
} | ||
|
||
private fun sendText(phone: String, text: String) { | ||
val coolsms = Message(coolSMSProperties.apiKey, coolSMSProperties.apiSecret) | ||
try { | ||
coolsms.send( | ||
hashMapOf( | ||
"to" to phone, | ||
"from" to coolSMSProperties.senderPhone, | ||
"type" to "SMS", | ||
"text" to text | ||
) | ||
) | ||
} catch (e: CoolsmsException) { | ||
throw RuntimeException(e) | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ enum class JwtPayloadKey( | |
val key: String | ||
) { | ||
ID("id"), | ||
TEL("email"), | ||
PHONE("phone"), | ||
ROLE("role"); | ||
} |
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