Add clear-expired-sessions feature
authorTheSaminator <TheSaminator@users.noreply.github.com>
Sun, 13 Feb 2022 22:29:57 +0000 (17:29 -0500)
committerTheSaminator <TheSaminator@users.noreply.github.com>
Sun, 13 Feb 2022 22:29:57 +0000 (17:29 -0500)
src/jvmMain/kotlin/starshipfights/auth/providers.kt
src/jvmMain/kotlin/starshipfights/info/endpoints_info.kt
src/jvmMain/kotlin/starshipfights/info/views_user.kt

index e942760719acf5676968381657d776fb6e27a08d..e8d5f49a3cba5bd524e99c5b6372856b29190d10 100644 (file)
@@ -300,6 +300,29 @@ interface AuthProvider {
                                        redirect("/me/manage")
                                }
                                
+                               get("/clear-expired/{id}") {
+                                       val id = Id<UserSession>(call.parameters.getOrFail("id"))
+                                       call.getUserSession()?.let { sess ->
+                                               launch {
+                                                       val now = Instant.now()
+                                                       UserSession.remove(and(UserSession::id eq id, UserSession::user eq sess.user, UserSession::expiration lte now))
+                                               }
+                                       }
+                                       
+                                       redirect("/me/manage")
+                               }
+                               
+                               get("/clear-all-expired/") {
+                                       call.getUserSession()?.let { sess ->
+                                               launch {
+                                                       val now = Instant.now()
+                                                       UserSession.remove(and(UserSession::user eq sess.user, UserSession::expiration lte now))
+                                               }
+                                       }
+                                       
+                                       redirect("/me/manage")
+                               }
+                               
                                currentProvider.installRouting(this)
                        }
                }
index d9645aa208ce25e5511ef4113c8c0c64ccbbb0b5..c2e71c860e5ef1747f0f0393df852278f2b9b8f3 100644 (file)
@@ -34,7 +34,7 @@ fun Routing.installPages() {
        
        // Random name generation
        get("/generate-name/{flavor}/{gender}") {
-               val flavor = call.parameters["flavor"]?.let { flavor -> AdmiralNameFlavor.values().singleOrNull { it.toUrlSlug() == flavor.lowercase() } }!!
+               val flavor = call.parameters["flavor"]?.let { flavor -> AdmiralNameFlavor.values().singleOrNull { it.toUrlSlug().equals(flavor, ignoreCase = true) } }!!
                val isFemale = call.parameters["gender"]?.startsWith('f', ignoreCase = true) ?: false
                
                call.respondText(AdmiralNames.randomName(flavor, isFemale), ContentType.Text.Plain)
index 5944177b71529e0b3af06653566f76e0f6338fcb..e0539258982a34b0646456cdd9708a5e7ceacd5f 100644 (file)
@@ -200,7 +200,7 @@ suspend fun ApplicationCall.manageUserPage(): HTML.() -> Unit {
                        }
                }
                section {
-                       h2 { +"Other Sessions" }
+                       h2 { +"Logged-In Sessions" }
                        table {
                                tr {
                                        th { +"User-Agent" }
@@ -253,9 +253,17 @@ suspend fun ApplicationCall.manageUserPage(): HTML.() -> Unit {
                                                                style = "display:none"
                                                                +session.expiration.toEpochMilli().toString()
                                                        }
+                                                       br
+                                                       a(href = "/clear-expired/${session.id}") { +"Clear" }
                                                }
                                        }
                                }
+                               tr {
+                                       td {
+                                               colSpan = "3"
+                                               a(href = "/clear-all-expired") { +"Clear All Expired Sessions" }
+                                       }
+                               }
                        }
                }
        }