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