Add page that always requires a logged-in user
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / UnfollowSonePage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.utils.isPOST
5 import net.pterodactylus.sone.utils.parameters
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.FreenetRequest
8 import net.pterodactylus.util.template.Template
9 import net.pterodactylus.util.template.TemplateContext
10
11 /**
12  * This page lets the user unfollow another Sone.
13  */
14 class UnfollowSonePage(template: Template, webInterface: WebInterface):
15                 LoggedInPage("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface) {
16
17         override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
18                 if (freenetRequest.isPOST) {
19                                 freenetRequest.parameters["sone"]!!.split(Regex("[ ,]+"))
20                                                 .forEach { webInterface.core.unfollowSone(currentSone, it) }
21                         throw RedirectException(freenetRequest.parameters["returnPage", 256])
22                 }
23         }
24
25 }