import kotlinx.coroutines.Job
import kotlinx.html.*
import net.starshipfights.auth.getUser
-import net.starshipfights.auth.getUserAndSession
import net.starshipfights.auth.receiveValidatedParameters
import net.starshipfights.forbid
-import net.starshipfights.info.csrfToken
import net.starshipfights.info.page
import net.starshipfights.info.standardNavBar
import net.starshipfights.redirect
fun Routing.installAdmin() {
get("/admin") {
- val (sess, user) = call.getUserAndSession()
-
- if (!user.isAdmin)
+ if (!call.getUser().isAdmin)
forbid()
- sess ?: redirect("/login")
- user ?: redirect("/login")
-
call.respondHtml(HttpStatusCode.OK, call.page("Admin Panel", call.standardNavBar()) {
section {
h1 { +"Admin Panel" }
name = "announcement"
required = true
}
- csrfToken(sess.id)
submitInput {
value = "Announce"
}
}
}
+ section {
+ h2 { +"Server Shutdown" }
+ form(action = "/admin/shutdown", method = FormMethod.post) {
+ submitInput(classes = "evil") {
+ value = "Shutdown the Server"
+ }
+ }
+ }
})
}
- get("/admin/shutdown") {
- if (!call.getUser().isAdmin)
- forbid()
-
- shutDown.complete()
-
- call.respond(HttpStatusCode.Gone)
- }
-
post("/admin/announce") {
val user = call.getUser()
user ?: redirect("/login")
sendAdminAnnouncement(announcement)
redirect("/admin")
}
+
+ post("/admin/shutdown") {
+ if (!call.getUser().isAdmin)
+ forbid()
+
+ shutDown.complete()
+
+ call.respond(HttpStatusCode.Gone)
+ }
}
suspend fun awaitShutDown() = shutDown.join()