✨ Add @ToadletPath annotation
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / DeleteProfileFieldPage.kt
1 package net.pterodactylus.sone.web.pages
2
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.*
9 import javax.inject.*
10
11 /**
12  * Page that lets the user confirm the deletion of a profile field.
13  */
14 @TemplatePath("/templates/deleteProfileField.html")
15 @ToadletPath("deleteProfileField.html")
16 class DeleteProfileFieldPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
17                 LoggedInPage("deleteProfileField.html", "Page.DeleteProfileField.Title", webInterface, loaders, templateRenderer) {
18
19         override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
20                 if (soneRequest.isPOST) {
21                         val field = currentSone.profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
22                         if (soneRequest.httpRequest.getPartAsStringFailsafe("confirm", 4) == "true") {
23                                 currentSone.profile = currentSone.profile.apply { removeField(field) }
24                         }
25                         throw RedirectException("editProfile.html#profile-fields")
26                 }
27                 val field = currentSone.profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
28                 templateContext["field"] = field
29         }
30
31 }