Replace delete profile field page with Kotlin version
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / DeleteProfileFieldPage.kt
1 package net.pterodactylus.sone.web
2
3 import net.pterodactylus.sone.web.page.FreenetRequest
4 import net.pterodactylus.util.template.Template
5 import net.pterodactylus.util.template.TemplateContext
6 import net.pterodactylus.util.web.Method.POST
7
8 /**
9  * Page that lets the user confirm the deletion of a profile field.
10  */
11 class DeleteProfileFieldPage(template: Template, webInterface: WebInterface):
12                 SoneTemplatePage("deleteProfileField.html", template, "Page.DeleteProfileField.Title", webInterface, true) {
13
14         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
15                 val currentSone = getCurrentSone(request.toadletContext)
16                 val field = currentSone.profile.getFieldById(request.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
17                 templateContext["field"] = field
18                 if (request.method == POST) {
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         }
25
26 }