Use Request utility method
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 25 Mar 2017 11:07:09 +0000 (12:07 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 25 Mar 2017 11:07:09 +0000 (12:07 +0100)
14 files changed:
src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.kt
src/main/java/net/pterodactylus/sone/web/CreateReplyPage.kt
src/main/kotlin/net/pterodactylus/sone/web/BookmarkPage.kt
src/main/kotlin/net/pterodactylus/sone/web/CreatePostPage.kt
src/main/kotlin/net/pterodactylus/sone/web/CreateSonePage.kt
src/main/kotlin/net/pterodactylus/sone/web/DeleteAlbumPage.kt
src/main/kotlin/net/pterodactylus/sone/web/DeleteImagePage.kt
src/main/kotlin/net/pterodactylus/sone/web/DeletePostPage.kt
src/main/kotlin/net/pterodactylus/sone/web/DeleteProfileFieldPage.kt
src/main/kotlin/net/pterodactylus/sone/web/DeleteReplyPage.kt
src/main/kotlin/net/pterodactylus/sone/web/DeleteSonePage.kt
src/main/kotlin/net/pterodactylus/sone/web/DistrustPage.kt
src/main/kotlin/net/pterodactylus/sone/web/EditAlbumPage.kt
src/main/kotlin/net/pterodactylus/sone/web/LoginPage.kt

index 5d47641..e91ad37 100644 (file)
@@ -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
index 6e003f0..43fbeaf 100644 (file)
@@ -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
index 47b0d04..5bc21d1 100644 (file)
@@ -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 {
index 8287e13..302fdf5 100644 (file)
@@ -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
index d2b0e4b..673cca3 100644 (file)
@@ -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)
index da75732..7830653 100644 (file)
@@ -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")
                        }
index 9999c3c..00ebc55 100644 (file)
@@ -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}")
                        }
index 40923d3..bbbb897 100644 (file)
@@ -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")
                        }
index b053eab..c957bd7 100644 (file)
@@ -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) }
                        }
index 096ac0d..5a707ce 100644 (file)
@@ -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")
index d69c3ae..1d0f6aa 100644 (file)
@@ -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))
                        }
index 5ef12d1..f3e593e 100644 (file)
@@ -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))
index 8a59c33..85ee17a 100644 (file)
@@ -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") {
index a37431a..302e5e4 100644 (file)
@@ -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)