diff --git a/resources/templates/login.twig b/resources/templates/login.twig index e89bca6..1584498 100644 --- a/resources/templates/login.twig +++ b/resources/templates/login.twig @@ -14,7 +14,7 @@ {{ alerts.warning("Error", error) }} {% endif -%} -
+ {% import "components/forms.html" as forms %} {{ forms.input({ diff --git a/src/controllers/web/NoteController.kt b/src/controllers/web/NoteController.kt index 1a38f6e..6e41031 100644 --- a/src/controllers/web/NoteController.kt +++ b/src/controllers/web/NoteController.kt @@ -46,24 +46,12 @@ class NoteController( suspend fun new(call: ApplicationCall) { val template = templates.get("new.html") - if (call.request.httpMethod == HttpMethod.Get || - !call.request.contentType().withoutParameters().match(MultiPart.FormData) - ) { - call.respondKorte(template) - return - } + if (call.request.httpMethod == HttpMethod.Get) return call.respondKorte(template) - val multipart = call.receiveMultipart() - val part = multipart.readPart() + val params = call.receiveParameters() + val txt = params["markdown"] ?: return call.respondKorte(template) - if (part == null || part !is PartData.FormItem || part.name != "markdown") { - call.respondKorte(templates.get("error.html"), "error" to "null", statusCode = BadRequest) - return - } - - val textAreaValue = part.value - - val result = md.renderDocument(textAreaValue) + val result = md.renderDocument(txt) val doc = when (result) { is Error -> return call.respondKorte( @@ -77,7 +65,7 @@ class NoteController( val note = Note { this.title = doc.meta.title this.tags = doc.meta.tags - this.markdown = textAreaValue + this.markdown = txt this.html = doc.html } diff --git a/src/controllers/web/UserController.kt b/src/controllers/web/UserController.kt index 943571c..3991e4c 100644 --- a/src/controllers/web/UserController.kt +++ b/src/controllers/web/UserController.kt @@ -32,10 +32,14 @@ class UserController( return } - val parts = call.receiveMultipart().readAllParts() + val params = call.receiveParameters() + val username = params["username"] + val password = params["password"] - val username = (parts.find { it.name == "username" } as PartData.FormItem).value - val password = (parts.find { it.name == "password" } as PartData.FormItem).value + if (username == null || password == null) { + call.respondKorte(template) + return + } val user = userRepository.find(username) @@ -89,10 +93,14 @@ class UserController( return } - val parts = call.receiveMultipart().readAllParts() + val params = call.receiveParameters() + val username = params["username"] + val password = params["password"] - val username = (parts.find { it.name == "username" } as PartData.FormItem).value - val password = (parts.find { it.name == "password" } as PartData.FormItem).value + if (username == null || password == null) { + call.respondKorte(template) + return + } val validation = registerValidator.validate( User {