X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FDeleteProfileFieldPage.kt;fp=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FDeleteProfileFieldPage.kt;h=e0dc4bec553a677c4588c3fa20a7d913463b5a40;hp=0000000000000000000000000000000000000000;hb=de7568a82eb4150bf6d2b0553841b7b69f84c968;hpb=9acbc5bdec4ccb752e0856a501568b0bb6161579 diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt new file mode 100644 index 0000000..e0dc4be --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt @@ -0,0 +1,28 @@ +package net.pterodactylus.sone.web.pages + +import net.pterodactylus.sone.utils.isPOST +import net.pterodactylus.sone.web.pages.SoneTemplatePage +import net.pterodactylus.sone.web.WebInterface +import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.util.template.Template +import net.pterodactylus.util.template.TemplateContext + +/** + * Page that lets the user confirm the deletion of a profile field. + */ +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 + if (request.isPOST) { + if (request.httpRequest.getPartAsStringFailsafe("confirm", 4) == "true") { + currentSone.profile = currentSone.profile.apply { removeField(field) } + } + throw RedirectException("editProfile.html#profile-fields") + } + } + +}