c1415b01b4d935c899e583b73feb64f1d7e4ccce
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / BookmarkPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.main.*
4 import net.pterodactylus.sone.utils.isPOST
5 import net.pterodactylus.sone.web.WebInterface
6 import net.pterodactylus.sone.web.page.*
7 import net.pterodactylus.util.template.Template
8 import net.pterodactylus.util.template.TemplateContext
9 import javax.inject.Inject
10
11 /**
12  * Page that lets the user bookmark a post.
13  */
14 class BookmarkPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders)
15         : SoneTemplatePage("bookmark.html", webInterface, loaders, template = template, pageTitleKey = "Page.Bookmark.Title") {
16
17         override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
18                 if (soneRequest.isPOST) {
19                         val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
20                         val postId = soneRequest.httpRequest.getPartAsStringFailsafe("post", 36)
21                         soneRequest.core.getPost(postId)?.let {
22                                 soneRequest.core.bookmarkPost(it)
23                         }
24                         throw RedirectException(returnPage)
25                 }
26         }
27
28 }