2e140163c71ba1c64c12dbd5eefe959d7da14d7b
[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.*
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  * This page lets the user unfollow another Sone.
13  */
14 @ToadletPath("unfollowSone.html")
15 class UnfollowSonePage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
16                 LoggedInPage("unfollowSone.html", "Page.UnfollowSone.Title", webInterface, loaders, templateRenderer) {
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 }