3eac0aa1700ea129c13297e1c74aadd2cd88fdc9
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / BookmarkPage.kt
1 package net.pterodactylus.sone.web
2
3 import net.pterodactylus.sone.web.page.FreenetRequest
4 import net.pterodactylus.util.template.Template
5 import net.pterodactylus.util.template.TemplateContext
6 import net.pterodactylus.util.web.Method.POST
7
8 /**
9  * Page that lets the user bookmark a post.
10  */
11 class BookmarkPage(template: Template, webInterface: WebInterface)
12         : SoneTemplatePage("bookmark.html", template, "Page.Bookmark.Title", webInterface) {
13
14         override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
15                 if (freenetRequest.method == POST) {
16                         val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
17                         val postId = freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36)
18                         webInterface.core.getPost(postId).orNull()?.let {
19                                 webInterface.core.bookmarkPost(it)
20                         }
21                         throw RedirectException(returnPage)
22                 }
23         }
24
25 }