11d456c2fdaf01686acaa81910268070623e1804
[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.*
8 import net.pterodactylus.util.template.Template
9 import net.pterodactylus.util.template.TemplateContext
10 import javax.inject.Inject
11
12 /**
13  * This page lets the user unfollow another Sone.
14  */
15 class UnfollowSonePage @Inject constructor(template: Template, webInterface: WebInterface) :
16                 LoggedInPage("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface) {
17
18         override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
19                 if (soneRequest.isPOST) {
20                         soneRequest.parameters["sone"]!!.split(Regex("[ ,]+"))
21                                         .forEach { soneRequest.core.unfollowSone(currentSone, it) }
22                         throw RedirectException(soneRequest.parameters["returnPage", 256])
23                 }
24         }
25
26 }