♻️ Move throwing redirect exception into method
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / EditProfilePage.kt
index b22b6de..93393ba 100644 (file)
@@ -15,8 +15,9 @@ import javax.inject.*
  */
 @MenuName("EditProfile")
 @TemplatePath("/templates/editProfile.html")
+@ToadletPath("editProfile.html")
 class EditProfilePage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
-               LoggedInPage("editProfile.html", "Page.EditProfile.Title", webInterface, loaders, templateRenderer) {
+               LoggedInPage("Page.EditProfile.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                currentSone.profile.let { profile ->
@@ -42,31 +43,31 @@ class EditProfilePage @Inject constructor(webInterface: WebInterface, loaders: L
                                        }
                                        currentSone.profile = profile
                                        soneRequest.core.touchConfiguration()
-                                       throw RedirectException("editProfile.html")
+                                       redirectTo("editProfile.html")
                                } else if (soneRequest.httpRequest.getPartAsStringFailsafe("add-field", 4) == "true") {
                                        val fieldName = soneRequest.httpRequest.getPartAsStringFailsafe("field-name", 100)
                                        try {
                                                profile.addField(fieldName)
                                                currentSone.profile = profile
                                                soneRequest.core.touchConfiguration()
-                                               throw RedirectException("editProfile.html#profile-fields")
+                                               redirectTo("editProfile.html#profile-fields")
                                        } catch (e: DuplicateField) {
                                                templateContext["fieldName"] = fieldName
                                                templateContext["duplicateFieldName"] = true
                                        }
                                } else profile.fields.forEach { field ->
                                        if (soneRequest.httpRequest.getPartAsStringFailsafe("delete-field-${field.id}", 4) == "true") {
-                                               throw RedirectException("deleteProfileField.html?field=${field.id}")
+                                               redirectTo("deleteProfileField.html?field=${field.id}")
                                        } else if (soneRequest.httpRequest.getPartAsStringFailsafe("edit-field-${field.id}", 4) == "true") {
-                                               throw RedirectException("editProfileField.html?field=${field.id}")
+                                               redirectTo("editProfileField.html?field=${field.id}")
                                        } else if (soneRequest.httpRequest.getPartAsStringFailsafe("move-down-field-${field.id}", 4) == "true") {
                                                profile.moveFieldDown(field)
                                                currentSone.profile = profile
-                                               throw RedirectException("editProfile.html#profile-fields")
+                                               redirectTo("editProfile.html#profile-fields")
                                        } else if (soneRequest.httpRequest.getPartAsStringFailsafe("move-up-field-${field.id}", 4) == "true") {
                                                profile.moveFieldUp(field)
                                                currentSone.profile = profile
-                                               throw RedirectException("editProfile.html#profile-fields")
+                                               redirectTo("editProfile.html#profile-fields")
                                        }
                                }
                        }