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
9 import javax.inject.Inject
12 * Page that lets the user edit the name of a profile field.
14 class EditProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface) :
15 LoggedInPage("editProfileField.html", template, "Page.EditProfileField.Title", webInterface) {
17 override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
18 currentSone.profile.let { profile ->
19 if (freenetRequest.isPOST) {
20 if (freenetRequest.httpRequest.getPartAsStringFailsafe("cancel", 4) == "true") {
21 throw RedirectException("editProfile.html#profile-fields")
23 val field = profile.getFieldById(freenetRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
24 freenetRequest.httpRequest.getPartAsStringFailsafe("name", 256).let { name ->
26 if (name != field.name) {
28 currentSone.profile = profile
30 throw RedirectException("editProfile.html#profile-fields")
31 } catch (e: IllegalArgumentException) {
32 templateContext["duplicateFieldName"] = true
37 templateContext["field"] = profile.getFieldById(freenetRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")