From ddc708d5b4cbebb3121fb000f44745f55b786e13 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 25 Mar 2017 12:07:09 +0100 Subject: [PATCH] Use Request utility method --- src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.kt | 4 ++-- src/main/java/net/pterodactylus/sone/web/CreateReplyPage.kt | 4 ++-- src/main/kotlin/net/pterodactylus/sone/web/BookmarkPage.kt | 6 ++---- src/main/kotlin/net/pterodactylus/sone/web/CreatePostPage.kt | 4 ++-- src/main/kotlin/net/pterodactylus/sone/web/CreateSonePage.kt | 4 ++-- src/main/kotlin/net/pterodactylus/sone/web/DeleteAlbumPage.kt | 4 ++-- src/main/kotlin/net/pterodactylus/sone/web/DeleteImagePage.kt | 4 ++-- src/main/kotlin/net/pterodactylus/sone/web/DeletePostPage.kt | 4 ++-- .../kotlin/net/pterodactylus/sone/web/DeleteProfileFieldPage.kt | 4 ++-- src/main/kotlin/net/pterodactylus/sone/web/DeleteReplyPage.kt | 4 ++-- src/main/kotlin/net/pterodactylus/sone/web/DeleteSonePage.kt | 4 ++-- src/main/kotlin/net/pterodactylus/sone/web/DistrustPage.kt | 4 ++-- src/main/kotlin/net/pterodactylus/sone/web/EditAlbumPage.kt | 4 ++-- src/main/kotlin/net/pterodactylus/sone/web/LoginPage.kt | 4 ++-- 14 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.kt b/src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.kt index 5d47641..e91ad37 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.kt +++ b/src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.kt @@ -2,10 +2,10 @@ package net.pterodactylus.sone.web import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty import net.pterodactylus.sone.text.TextFilter +import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext -import net.pterodactylus.util.web.Method.POST /** * Page that lets the user create a new album. @@ -14,7 +14,7 @@ class CreateAlbumPage(template: Template, webInterface: WebInterface): SoneTemplatePage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface, true) { override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - if (request.method == POST) { + if (request.isPOST) { val name = request.httpRequest.getPartAsStringFailsafe("name", 64).trim() if (name.isEmpty()) { templateContext["nameMissing"] = true diff --git a/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.kt b/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.kt index 6e003f0..43fbeaf 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.kt +++ b/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.kt @@ -1,10 +1,10 @@ package net.pterodactylus.sone.web import net.pterodactylus.sone.text.TextFilter +import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext -import net.pterodactylus.util.web.Method.POST /** * This page lets the user post a reply to a post. @@ -16,7 +16,7 @@ class CreateReplyPage(template: Template, webInterface: WebInterface): val postId = request.httpRequest.getPartAsStringFailsafe("post", 36).apply { templateContext["postId"] = this } val text = request.httpRequest.getPartAsStringFailsafe("text", 65536).trim().apply { templateContext["text"] = this } val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256).apply { templateContext["returnPage"] = this } - if (request.method == POST) { + if (request.isPOST) { if (text == "") { templateContext["errorTextEmpty"] = true return diff --git a/src/main/kotlin/net/pterodactylus/sone/web/BookmarkPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/BookmarkPage.kt index 47b0d04..5bc21d1 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/BookmarkPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/BookmarkPage.kt @@ -1,11 +1,9 @@ package net.pterodactylus.sone.web +import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext -import net.pterodactylus.util.web.Method.POST -import javax.inject.Inject -import javax.inject.Singleton /** * Page that lets the user bookmark a post. @@ -14,7 +12,7 @@ class BookmarkPage(template: Template, webInterface: WebInterface) : SoneTemplatePage("bookmark.html", template, "Page.Bookmark.Title", webInterface) { override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { - if (freenetRequest.method == POST) { + if (freenetRequest.isPOST) { val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) val postId = freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36) webInterface.core.getPost(postId).orNull()?.let { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/CreatePostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/CreatePostPage.kt index 8287e13..302fdf5 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/CreatePostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/CreatePostPage.kt @@ -1,10 +1,10 @@ package net.pterodactylus.sone.web import net.pterodactylus.sone.text.TextFilter +import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext -import net.pterodactylus.util.web.Method.POST /** * This page lets the user create a new [Post]. @@ -15,7 +15,7 @@ class CreatePostPage(template: Template, webInterface: WebInterface): override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256) templateContext["returnPage"] = returnPage - if (request.method == POST) { + if (request.isPOST) { val text = request.httpRequest.getPartAsStringFailsafe("text", 65536).trim() if (text == "") { templateContext["errorTextEmpty"] = true diff --git a/src/main/kotlin/net/pterodactylus/sone/web/CreateSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/CreateSonePage.kt index d2b0e4b..673cca3 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/CreateSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/CreateSonePage.kt @@ -2,10 +2,10 @@ package net.pterodactylus.sone.web import freenet.clients.http.ToadletContext import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext -import net.pterodactylus.util.web.Method.POST import java.util.logging.Level import java.util.logging.Logger @@ -20,7 +20,7 @@ class CreateSonePage(template: Template, webInterface: WebInterface): override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { templateContext["sones"] = webInterface.core.localSones.sortedWith(Sone.NICE_NAME_COMPARATOR) templateContext["identitiesWithoutSone"] = webInterface.core.identityManager.allOwnIdentities.filterNot { "Sone" in it.contexts }.sortedBy { "${it.nickname}@${it.id}".toLowerCase() } - if (request.method == POST) { + if (request.isPOST) { val identity = request.httpRequest.getPartAsStringFailsafe("identity", 43) webInterface.core.identityManager.allOwnIdentities.firstOrNull { it.id == identity }?.let { ownIdentity -> val sone = webInterface.core.createSone(ownIdentity) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/DeleteAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/DeleteAlbumPage.kt index da75732..7830653 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/DeleteAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/DeleteAlbumPage.kt @@ -1,9 +1,9 @@ package net.pterodactylus.sone.web +import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext -import net.pterodactylus.util.web.Method.POST /** * Page that lets the user delete an {@link Album}. @@ -14,7 +14,7 @@ class DeleteAlbumPage(template: Template, webInterface: WebInterface): override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { val album = webInterface.core.getAlbum(request.httpRequest.getPartAsStringFailsafe("album", 36)) templateContext["album"] = album ?: throw RedirectException("invalid.html") - if (request.method == POST) { + if (request.isPOST) { if (!album.sone.isLocal) { throw RedirectException("noPermission.html") } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/DeleteImagePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/DeleteImagePage.kt index 9999c3c..00ebc55 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/DeleteImagePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/DeleteImagePage.kt @@ -1,9 +1,9 @@ package net.pterodactylus.sone.web +import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext -import net.pterodactylus.util.web.Method.POST /** * Page that lets the user delete an {@link Image}. @@ -16,7 +16,7 @@ class DeleteImagePage(template: Template, webInterface: WebInterface): if (!image.sone.isLocal) { throw RedirectException("noPermission.html") } - if (request.method == POST) { + if (request.isPOST) { if (request.httpRequest.isPartSet("abortDelete")) { throw RedirectException("imageBrowser.html?image=${image.id}") } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/DeletePostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/DeletePostPage.kt index 40923d3..bbbb897 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/DeletePostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/DeletePostPage.kt @@ -1,9 +1,9 @@ package net.pterodactylus.sone.web +import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext -import net.pterodactylus.util.web.Method.POST /** * Lets the user delete a post they made. @@ -14,7 +14,7 @@ class DeletePostPage(template: Template, webInterface: WebInterface): override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { val post = webInterface.core.getPost(request.httpRequest.getPartAsStringFailsafe("post", 36)).orNull() ?: throw RedirectException("noPermission.html") val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256) - if (request.method == POST) { + if (request.isPOST) { if (!post.sone.isLocal) { throw RedirectException("noPermission.html") } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/DeleteProfileFieldPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/DeleteProfileFieldPage.kt index b053eab..c957bd7 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/DeleteProfileFieldPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/DeleteProfileFieldPage.kt @@ -1,9 +1,9 @@ package net.pterodactylus.sone.web +import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext -import net.pterodactylus.util.web.Method.POST /** * Page that lets the user confirm the deletion of a profile field. @@ -15,7 +15,7 @@ class DeleteProfileFieldPage(template: Template, webInterface: WebInterface): val currentSone = getCurrentSone(request.toadletContext) val field = currentSone.profile.getFieldById(request.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html") templateContext["field"] = field - if (request.method == POST) { + if (request.isPOST) { if (request.httpRequest.getPartAsStringFailsafe("confirm", 4) == "true") { currentSone.profile = currentSone.profile.apply { removeField(field) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/DeleteReplyPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/DeleteReplyPage.kt index 096ac0d..5a707ce 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/DeleteReplyPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/DeleteReplyPage.kt @@ -1,9 +1,9 @@ package net.pterodactylus.sone.web +import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext -import net.pterodactylus.util.web.Method.POST /** * This page lets the user delete a reply. @@ -16,7 +16,7 @@ class DeleteReplyPage(template: Template, webInterface: WebInterface): templateContext["reply"] = replyId val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256) templateContext["returnPage"] = returnPage - if (request.method == POST) { + if (request.isPOST) { val reply = webInterface.core.getPostReply(replyId).orNull() ?: throw RedirectException("noPermission.html") if (!reply.sone.isLocal) { throw RedirectException("noPermission.html") diff --git a/src/main/kotlin/net/pterodactylus/sone/web/DeleteSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/DeleteSonePage.kt index d69c3ae..1d0f6aa 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/DeleteSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/DeleteSonePage.kt @@ -1,9 +1,9 @@ package net.pterodactylus.sone.web +import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext -import net.pterodactylus.util.web.Method.POST /** * Lets the user delete a Sone. Of course the Sone is not really deleted from @@ -14,7 +14,7 @@ class DeleteSonePage(template: Template, webInterface: WebInterface): SoneTemplatePage("deleteSone.html", template, "Page.DeleteSone.Title", webInterface, true) { override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - if (request.method == POST) { + if (request.isPOST) { if (request.httpRequest.isPartSet("deleteSone")) { webInterface.core.deleteSone(getCurrentSone(request.toadletContext)) } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/DistrustPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/DistrustPage.kt index 5ef12d1..f3e593e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/DistrustPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/DistrustPage.kt @@ -1,9 +1,9 @@ package net.pterodactylus.sone.web +import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext -import net.pterodactylus.util.web.Method.POST /** * Page that lets the user distrust another Sone. This will assign a @@ -15,7 +15,7 @@ class DistrustPage(template: Template, webInterface: WebInterface): SoneTemplatePage("distrust.html", template, "Page.Distrust.Title", webInterface, true) { override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - if (request.method == POST) { + if (request.isPOST) { val sone = webInterface.core.getSone(request.httpRequest.getPartAsStringFailsafe("sone", 44)).orNull() sone?.run { webInterface.core.distrustSone(getCurrentSone(request.toadletContext), this) } throw RedirectException(request.httpRequest.getPartAsStringFailsafe("returnPage", 256)) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/EditAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/EditAlbumPage.kt index 8a59c33..85ee17a 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/EditAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/EditAlbumPage.kt @@ -1,10 +1,10 @@ package net.pterodactylus.sone.web import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty +import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext -import net.pterodactylus.util.web.Method.POST /** * Page that lets the user edit the name and description of an album. @@ -13,7 +13,7 @@ class EditAlbumPage(template: Template, webInterface: WebInterface): SoneTemplatePage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface, true) { override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - if (request.method == POST) { + if (request.isPOST) { val album = webInterface.core.getAlbum(request.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html") album.takeUnless { it.sone.isLocal }?.run { throw RedirectException("noPermission.html") } if (request.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/LoginPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/LoginPage.kt index a37431a..302e5e4 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/LoginPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/LoginPage.kt @@ -2,10 +2,10 @@ package net.pterodactylus.sone.web import freenet.clients.http.ToadletContext import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext -import net.pterodactylus.util.web.Method.POST /** * The login page lets the user log in. @@ -14,7 +14,7 @@ class LoginPage(template: Template, webInterface: WebInterface): SoneTemplatePage("login.html", template, "Page.Login.Title", webInterface) { override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - if (request.method == POST) { + if (request.isPOST) { val soneId = request.httpRequest.getPartAsStringFailsafe("sone-id", 43) webInterface.core.getLocalSone(soneId)?.let { sone -> setCurrentSone(request.toadletContext, sone) -- 2.7.4