♻️ Move throwing redirect exception into method
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / EditProfileFieldPage.kt
index cf23d47..be97e80 100644 (file)
@@ -1,42 +1,42 @@
 package net.pterodactylus.sone.web.pages
 
-import net.pterodactylus.sone.data.Sone
+import net.pterodactylus.sone.data.*
 import net.pterodactylus.sone.main.*
-import net.pterodactylus.sone.utils.isPOST
-import net.pterodactylus.sone.web.WebInterface
+import net.pterodactylus.sone.utils.*
+import net.pterodactylus.sone.web.*
 import net.pterodactylus.sone.web.page.*
-import net.pterodactylus.util.template.Template
-import net.pterodactylus.util.template.TemplateContext
-import javax.inject.Inject
+import net.pterodactylus.util.template.*
+import javax.inject.*
 
 /**
  * Page that lets the user edit the name of a profile field.
  */
 @TemplatePath("/templates/editProfileField.html")
-class EditProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
-               LoggedInPage("editProfileField.html", template, "Page.EditProfileField.Title", webInterface, loaders, templateRenderer) {
+@ToadletPath("editProfileField.html")
+class EditProfileFieldPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
+               LoggedInPage("Page.EditProfileField.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                currentSone.profile.let { profile ->
                        if (soneRequest.isPOST) {
                                if (soneRequest.httpRequest.getPartAsStringFailsafe("cancel", 4) == "true") {
-                                       throw RedirectException("editProfile.html#profile-fields")
+                                       redirectTo("editProfile.html#profile-fields")
                                }
-                               val field = profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
+                               val field = profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: redirectTo("invalid.html")
                                soneRequest.httpRequest.getPartAsStringFailsafe("name", 256).let { name ->
                                        try {
                                                if (name != field.name) {
                                                        field.name = name
                                                        currentSone.profile = profile
                                                }
-                                               throw RedirectException("editProfile.html#profile-fields")
+                                               redirectTo("editProfile.html#profile-fields")
                                        } catch (e: IllegalArgumentException) {
                                                templateContext["duplicateFieldName"] = true
                                                return
                                        }
                                }
                        }
-                       templateContext["field"] = profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
+                       templateContext["field"] = profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: redirectTo("invalid.html")
                }
        }