1 package net.pterodactylus.sone.web.ajax
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.utils.ifFalse
5 import net.pterodactylus.sone.utils.parameters
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.FreenetRequest
10 * AJAX page that lets the user rename a profile field.
12 class EditProfileFieldAjaxPage(webInterface: WebInterface) : LoggedInJsonPage("editProfileField.ajax", webInterface) {
14 override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
15 currentSone.profile.let { profile ->
16 request.parameters["field"]!!
17 .let(profile::getFieldById)
19 request.parameters["name"]!!.trim().let { newName ->
20 newName.isBlank().ifFalse {
23 createSuccessJsonObject().also {
24 currentSone.profile = profile
26 } catch (_: IllegalArgumentException) {
27 createErrorJsonObject("duplicate-field-name")
30 } ?: createErrorJsonObject("invalid-parameter-name")
31 } ?: createErrorJsonObject("invalid-field-id")