f1e8ac293555fe2cc42adc558ab568b77e18720c
[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.utils.isPOST
4 import net.pterodactylus.sone.web.pages.SoneTemplatePage
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
10 /**
11  * Page that lets the user bookmark a post.
12  */
13 class BookmarkPage(template: Template, webInterface: WebInterface)
14         : SoneTemplatePage("bookmark.html", template, "Page.Bookmark.Title", webInterface) {
15
16         override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
17                 if (freenetRequest.isPOST) {
18                         val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
19                         val postId = freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36)
20                         webInterface.core.getPost(postId).orNull()?.let {
21                                 webInterface.core.bookmarkPost(it)
22                         }
23                         throw RedirectException(returnPage)
24                 }
25         }
26
27 }