1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.main.*
5 import net.pterodactylus.sone.utils.*
6 import net.pterodactylus.sone.web.*
7 import net.pterodactylus.sone.web.page.*
8 import net.pterodactylus.util.template.*
12 * Page that lets the user edit the name of a profile field.
14 @TemplatePath("/templates/editProfileField.html")
15 @ToadletPath("editProfileField.html")
16 class EditProfileFieldPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
17 LoggedInPage("Page.EditProfileField.Title", webInterface, loaders, templateRenderer) {
19 override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
20 currentSone.profile.let { profile ->
21 if (soneRequest.isPOST) {
22 if (soneRequest.httpRequest.getPartAsStringFailsafe("cancel", 4) == "true") {
23 redirectTo("editProfile.html#profile-fields")
25 val field = profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: redirectTo("invalid.html")
26 soneRequest.httpRequest.getPartAsStringFailsafe("name", 256).let { name ->
28 if (name != field.name) {
30 currentSone.profile = profile
32 redirectTo("editProfile.html#profile-fields")
33 } catch (e: IllegalArgumentException) {
34 templateContext["duplicateFieldName"] = true
39 templateContext["field"] = profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: redirectTo("invalid.html")