Actually differentiate between GET and POST parameters
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / DeleteProfileFieldPage.kt
index e0dc4be..5c1abdf 100644 (file)
@@ -14,15 +14,16 @@ class DeleteProfileFieldPage(template: Template, webInterface: WebInterface):
                SoneTemplatePage("deleteProfileField.html", template, "Page.DeleteProfileField.Title", webInterface, true) {
 
        override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
-               val currentSone = getCurrentSone(request.toadletContext)
-               val field = currentSone.profile.getFieldById(request.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
-               templateContext["field"] = field
+               val currentSone = getCurrentSone(request.toadletContext)!!
                if (request.isPOST) {
+                       val field = currentSone.profile.getFieldById(request.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
                        if (request.httpRequest.getPartAsStringFailsafe("confirm", 4) == "true") {
                                currentSone.profile = currentSone.profile.apply { removeField(field) }
                        }
                        throw RedirectException("editProfile.html#profile-fields")
                }
+               val field = currentSone.profile.getFieldById(request.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
+               templateContext["field"] = field
        }
 
 }