aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/UserHandler.kt
diff options
context:
space:
mode:
authorMarvin Borner2019-04-18 22:08:26 +0200
committerMarvin Borner2019-04-18 22:08:26 +0200
commit551868000825ebbe037b1be494679b24c2f0fcac (patch)
treed280dcd86b3417a7bf3fcfc6b74d5c44484b4f77 /src/main/kotlin/UserHandler.kt
parent8c85eef4dd56b6a2d4a2563c5634dc2c60a35370 (diff)
Added better setup process redirection
Co-authored-by: LarsVomMars <lars@kroenner.eu>
Diffstat (limited to 'src/main/kotlin/UserHandler.kt')
-rw-r--r--src/main/kotlin/UserHandler.kt37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/main/kotlin/UserHandler.kt b/src/main/kotlin/UserHandler.kt
index 8197427..cc9a768 100644
--- a/src/main/kotlin/UserHandler.kt
+++ b/src/main/kotlin/UserHandler.kt
@@ -10,7 +10,7 @@ class UserHandler {
* Checks and verifies users credentials and logs the user in
*/
fun login(ctx: Context) {
- if (getVerifiedUserId(ctx) > 0) ctx.redirect("/")
+ if (getVerifiedUserId(ctx) > 0 || !databaseController.isSetup()) ctx.redirect("/")
val username = ctx.formParam("username").toString()
val password = ctx.formParam("password").toString()
@@ -71,29 +71,24 @@ class UserHandler {
* Sets up the general settings and admin credentials
*/
fun setup(ctx: Context) {
- if (databaseController.isSetup()) ctx.render(
- "setup.rocker.html",
- TemplateUtil.model("message", "Setup process already finished!")
- ) else {
- try {
- val username = ctx.formParam("username").toString()
- val password = ctx.formParam("password").toString()
- val verifyPassword = ctx.formParam("verifyPassword").toString()
- if (password == verifyPassword) {
- if (databaseController.createUser(username, password, "ADMIN")) {
- databaseController.toggleSetup()
- ctx.render("setup.rocker.html", TemplateUtil.model("message", "Setup succeeded!"))
- } else ctx.status(400).render(
- "setup.rocker.html",
- TemplateUtil.model("message", "User already exists!")
- )
+ try {
+ val username = ctx.formParam("username").toString()
+ val password = ctx.formParam("password").toString()
+ val verifyPassword = ctx.formParam("verifyPassword").toString()
+ if (password == verifyPassword) {
+ if (databaseController.createUser(username, password, "ADMIN")) {
+ databaseController.toggleSetup()
+ ctx.redirect("/login")
} else ctx.status(400).render(
"setup.rocker.html",
- TemplateUtil.model("message", "Passwords do not match!")
+ TemplateUtil.model("message", "User already exists!")
)
- } catch (_: Exception) {
- ctx.status(400).render("setup.rocker.html", TemplateUtil.model("message", "An error occurred!"))
- }
+ } else ctx.status(400).render(
+ "setup.rocker.html",
+ TemplateUtil.model("message", "Passwords do not match!")
+ )
+ } catch (_: Exception) {
+ ctx.status(400).render("setup.rocker.html", TemplateUtil.model("message", "An error occurred!"))
}
}