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 class EditProfileFieldPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
16 LoggedInPage("editProfileField.html", "Page.EditProfileField.Title", webInterface, loaders, templateRenderer) {
18 override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
19 currentSone.profile.let { profile ->
20 if (soneRequest.isPOST) {
21 if (soneRequest.httpRequest.getPartAsStringFailsafe("cancel", 4) == "true") {
22 throw RedirectException("editProfile.html#profile-fields")
24 val field = profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
25 soneRequest.httpRequest.getPartAsStringFailsafe("name", 256).let { name ->
27 if (name != field.name) {
29 currentSone.profile = profile
31 throw RedirectException("editProfile.html#profile-fields")
32 } catch (e: IllegalArgumentException) {
33 templateContext["duplicateFieldName"] = true
38 templateContext["field"] = profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")