Add test for DI constructability of MarkAsKnownPage
[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.data.Sone
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 import javax.inject.Inject
10
11 /**
12  * Logs a user out.
13  */
14 class LogoutPage @Inject constructor(template: Template, webInterface: WebInterface):
15                 LoggedInPage("logout.html", template, "Page.Logout.Title", webInterface) {
16
17         override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
18                 setCurrentSone(freenetRequest.toadletContext, null)
19                 throw RedirectException("index.html")
20         }
21
22         override fun isEnabled(toadletContext: ToadletContext): Boolean =
23                         if (webInterface.core.preferences.isRequireFullAccess && !toadletContext.isAllowedFullAccess) {
24                                 false
25                         } else
26                                 getCurrentSone(toadletContext) != null && webInterface.core.localSones.size != 1
27
28 }