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