1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.utils.isPOST
5 import net.pterodactylus.sone.web.WebInterface
6 import net.pterodactylus.sone.web.page.FreenetRequest
7 import net.pterodactylus.util.template.Template
8 import net.pterodactylus.util.template.TemplateContext
11 * Page that lets the user confirm the deletion of a profile field.
13 class DeleteProfileFieldPage(template: Template, webInterface: WebInterface):
14 LoggedInPage("deleteProfileField.html", template, "Page.DeleteProfileField.Title", webInterface) {
16 override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
17 if (freenetRequest.isPOST) {
18 val field = currentSone.profile.getFieldById(freenetRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
19 if (freenetRequest.httpRequest.getPartAsStringFailsafe("confirm", 4) == "true") {
20 currentSone.profile = currentSone.profile.apply { removeField(field) }
22 throw RedirectException("editProfile.html#profile-fields")
24 val field = currentSone.profile.getFieldById(freenetRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
25 templateContext["field"] = field