db79d1676500e926354405fd5f35bd748ba54148
[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.utils.isPOST
4 import net.pterodactylus.sone.utils.parameters
5 import net.pterodactylus.sone.web.WebInterface
6 import net.pterodactylus.sone.web.page.FreenetRequest
7 import net.pterodactylus.util.template.Template
8 import net.pterodactylus.util.template.TemplateContext
9 import java.util.regex.Pattern
10
11 /**
12  * This page lets the user unfollow another Sone.
13  */
14 class UnfollowSonePage(template: Template, webInterface: WebInterface):
15                 SoneTemplatePage("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface, true) {
16
17         override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
18                 if (freenetRequest.isPOST) {
19                         getCurrentSone(freenetRequest.toadletContext)!!.also { currentSone ->
20                                 freenetRequest.parameters["sone"]!!.split(Regex("[ ,]+"))
21                                                 .forEach { webInterface.core.unfollowSone(currentSone, it) }
22                         }
23                         throw RedirectException(freenetRequest.parameters["returnPage", 256])
24                 }
25         }
26
27 }