From bd89369b508f30fc987b27cf6b34a22fbc8e5d97 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 5 May 2019 22:27:42 +0200 Subject: Added simple admin interface Co-authored-by: LarsVomMars --- src/main/kotlin/App.kt | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/main/kotlin/App.kt') diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt index 5370f4b..c403b5a 100644 --- a/src/main/kotlin/App.kt +++ b/src/main/kotlin/App.kt @@ -44,20 +44,32 @@ fun main(args: Array) { get( "/css/*", { ctx -> ctx.contentType("text/css") - ctx.result(Thread.currentThread().contextClassLoader.getResourceAsStream("css/" + ctx.splat(0))) + try { + ctx.result(Thread.currentThread().contextClassLoader.getResourceAsStream("css/" + ctx.splat(0))) + } catch (_: Exception) { + ctx.status(404) + } }, roles(Roles.GUEST, Roles.USER) ) get( "/js/*", { ctx -> ctx.contentType("text/javascript") - ctx.result(Thread.currentThread().contextClassLoader.getResourceAsStream("js/" + ctx.splat(0))) + try { + ctx.result(Thread.currentThread().contextClassLoader.getResourceAsStream("js/" + ctx.splat(0))) + } catch (_: Exception) { + ctx.status(404) + } }, roles(Roles.GUEST, Roles.USER) ) get( "/fonts/*", { ctx -> - ctx.result(Thread.currentThread().contextClassLoader.getResourceAsStream("fonts/" + ctx.splat(0))) + try { + ctx.result(Thread.currentThread().contextClassLoader.getResourceAsStream("fonts/" + ctx.splat(0))) + } catch (_: Exception) { + ctx.status(404) + } }, roles(Roles.GUEST, Roles.USER) ) @@ -99,9 +111,13 @@ fun main(args: Array) { /** * Adds part of a new user (username) to database - * TODO: Create post request with admin interface */ - get("/user/add", databaseController::indexUserRegistration, roles(Roles.ADMIN)) + post("/user/add", databaseController::indexUserRegistration, roles(Roles.ADMIN)) + + /** + * Renders the admin interface + */ + get("/admin", userHandler::renderAdmin, roles(Roles.ADMIN)) /** * Renders the setup page (only on initial use) -- cgit v1.2.3