Replace get post ajax page with Kotlin version
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / LogoutPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import freenet.clients.http.ToadletContext
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  * Logs a user out.
11  */
12 class LogoutPage(template: Template, webInterface: WebInterface):
13                 SoneTemplatePage("logout.html", template, "Page.Logout.Title", webInterface, true) {
14
15         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
16                 setCurrentSone(request.toadletContext, null)
17                 throw RedirectException("index.html")
18         }
19
20         override fun isEnabled(toadletContext: ToadletContext): Boolean =
21                         if (webInterface.core.preferences.isRequireFullAccess && !toadletContext.isAllowedFullAccess) {
22                                 false
23                         } else
24                                 getCurrentSone(toadletContext) != null && webInterface.core.localSones.size != 1
25
26 }