Use method from JsonPage
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / DeleteProfileFieldPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.utils.isPOST
4 import net.pterodactylus.sone.web.WebInterface
5 import net.pterodactylus.sone.web.page.FreenetRequest
6 import net.pterodactylus.util.template.Template
7 import net.pterodactylus.util.template.TemplateContext
8
9 /**
10  * Page that lets the user confirm the deletion of a profile field.
11  */
12 class DeleteProfileFieldPage(template: Template, webInterface: WebInterface):
13                 SoneTemplatePage("deleteProfileField.html", template, "Page.DeleteProfileField.Title", webInterface, true) {
14
15         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
16                 val currentSone = getCurrentSone(request.toadletContext)!!
17                 if (request.isPOST) {
18                         val field = currentSone.profile.getFieldById(request.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
19                         if (request.httpRequest.getPartAsStringFailsafe("confirm", 4) == "true") {
20                                 currentSone.profile = currentSone.profile.apply { removeField(field) }
21                         }
22                         throw RedirectException("editProfile.html#profile-fields")
23                 }
24                 val field = currentSone.profile.getFieldById(request.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
25                 templateContext["field"] = field
26         }
27
28 }