Skip to content

Commit 0df8236

Browse files
committed
🔖 2.1.3 - enforce expires_at
1 parent 324420a commit 0df8236

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = "net.azisaba"
8-
version = "2.1.2"
8+
version = "2.1.3"
99

1010
repositories {
1111
mavenCentral()

src/main/kotlin/net/azisaba/guildchatdiscord/commands/LinkCommand.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ object LinkCommand : CommandHandler {
4141
defer.respond { content = "コードが無効です。" }
4242
return
4343
}
44-
val discordId = DatabaseManager.query("SELECT `discord_id` FROM `users` WHERE `link_code` = ?") { stmt ->
44+
val discordIdAndExpiresAt = DatabaseManager.query("SELECT `discord_id`, `expires_at` FROM `users` WHERE `link_code` = ?") { stmt ->
4545
stmt.setString(1, code)
4646
stmt.executeQuery().use { rs ->
4747
if (rs.next()) {
48-
rs.getLong("discord_id")
48+
Pair(rs.getLong("discord_id"), rs.getLong("expires_at"))
4949
} else {
50-
-1L
50+
Pair(-1L, 0L)
5151
}
5252
}
5353
}
54-
if (discordId != -1L) {
55-
// already linked
54+
if (discordIdAndExpiresAt.first != -1L || discordIdAndExpiresAt.second < System.currentTimeMillis()) {
55+
// already linked or expired
5656
defer.respond { content = "コードが無効です。" }
5757
return
5858
}

src/main/kotlin/net/azisaba/guildchatdiscord/util/DatabaseManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ object DatabaseManager {
2020
`minecraft_uuid` VARCHAR(36) NOT NULL UNIQUE,
2121
`minecraft_name` VARCHAR(16) NOT NULL,
2222
`link_code` VARCHAR(8) NOT NULL UNIQUE,
23+
`expires_at` BIGINT NOT NULL DEFAULT 0,
2324
PRIMARY KEY (`id`)
2425
)
2526
""".trimIndent()) { it.executeUpdate() }

0 commit comments

Comments
 (0)