package net.pterodactylus.sone.web.pages
import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.text.TextFilter
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
* Page that lets the user create a new album.
*/
class CreateAlbumPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface, true) {
+ LoggedInPage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
val name = freenetRequest.httpRequest.getPartAsStringFailsafe("name", 64).trim()
if (name.isEmpty()) {
return
}
val description = freenetRequest.httpRequest.getPartAsStringFailsafe("description", 256).trim()
- val currentSone = webInterface.getCurrentSoneCreatingSession(freenetRequest.toadletContext)
val parentId = freenetRequest.httpRequest.getPartAsStringFailsafe("parent", 36)
val parent = if (parentId == "") currentSone.rootAlbum else webInterface.core.getAlbum(parentId)
val album = webInterface.core.createAlbum(currentSone, parent)
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.text.TextFilter
import net.pterodactylus.sone.utils.asOptional
import net.pterodactylus.sone.utils.isPOST
* This page lets the user create a new [Post].
*/
class CreatePostPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("createPost.html", template, "Page.CreatePost.Title", webInterface, true) {
+ LoggedInPage("createPost.html", template, "Page.CreatePost.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
templateContext["returnPage"] = returnPage
if (freenetRequest.isPOST) {
templateContext["errorTextEmpty"] = true
return
}
- val sender = webInterface.core.getLocalSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: getCurrentSone(freenetRequest.toadletContext)
+ val sender = webInterface.core.getLocalSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: currentSone
val recipient = webInterface.core.getSone(freenetRequest.httpRequest.getPartAsStringFailsafe("recipient", 43))
webInterface.core.createPost(sender, recipient.asOptional(), TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), text))
throw RedirectException(returnPage)
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.text.TextFilter
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
* This page lets the user post a reply to a post.
*/
class CreateReplyPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("createReply.html", template, "Page.CreateReply.Title", webInterface, true) {
+ LoggedInPage("createReply.html", template, "Page.CreateReply.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
val postId = freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36).apply { templateContext["postId"] = this }
val text = freenetRequest.httpRequest.getPartAsStringFailsafe("text", 65536).trim().apply { templateContext["text"] = this }
val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256).apply { templateContext["returnPage"] = this }
return
}
val post = webInterface.core.getPost(postId) ?: throw RedirectException("noPermission.html")
- val sender = webInterface.core.getLocalSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: getCurrentSone(freenetRequest.toadletContext)
+ val sender = webInterface.core.getLocalSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: currentSone
webInterface.core.createReply(sender, post, TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), text))
throw RedirectException(returnPage)
}
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
import net.pterodactylus.sone.web.page.FreenetRequest
* Page that lets the user delete an {@link Album}.
*/
class DeleteAlbumPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface, true) {
+ LoggedInPage("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
val album = webInterface.core.getAlbum(freenetRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
if (!album.sone.isLocal) {
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
import net.pterodactylus.sone.web.page.FreenetRequest
* Page that lets the user delete an {@link Image}.
*/
class DeleteImagePage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("deleteImage.html", template, "Page.DeleteImage.Title", webInterface, true) {
+ LoggedInPage("deleteImage.html", template, "Page.DeleteImage.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
val image = webInterface.core.getImage(freenetRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
if (!image.sone.isLocal) {
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
import net.pterodactylus.sone.web.page.FreenetRequest
* Lets the user delete a post they made.
*/
class DeletePostPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("deletePost.html", template, "Page.DeletePost.Title", webInterface, true) {
+ LoggedInPage("deletePost.html", template, "Page.DeletePost.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
val post = webInterface.core.getPost(freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36)) ?: throw RedirectException("noPermission.html")
val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
import net.pterodactylus.sone.web.page.FreenetRequest
* Page that lets the user confirm the deletion of a profile field.
*/
class DeleteProfileFieldPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("deleteProfileField.html", template, "Page.DeleteProfileField.Title", webInterface, true) {
+ LoggedInPage("deleteProfileField.html", template, "Page.DeleteProfileField.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- val currentSone = getCurrentSone(freenetRequest.toadletContext)!!
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
val field = currentSone.profile.getFieldById(freenetRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
if (freenetRequest.httpRequest.getPartAsStringFailsafe("confirm", 4) == "true") {
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
import net.pterodactylus.sone.web.page.FreenetRequest
* This page lets the user delete a reply.
*/
class DeleteReplyPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface, true) {
+ LoggedInPage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
val replyId = freenetRequest.httpRequest.getPartAsStringFailsafe("reply", 36)
val reply = webInterface.core.getPostReply(replyId) ?: throw RedirectException("noPermission.html")
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
import net.pterodactylus.sone.web.page.FreenetRequest
* installation.
*/
class DeleteSonePage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("deleteSone.html", template, "Page.DeleteSone.Title", webInterface, true) {
+ LoggedInPage("deleteSone.html", template, "Page.DeleteSone.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
if (freenetRequest.httpRequest.isPartSet("deleteSone")) {
- webInterface.core.deleteSone(getCurrentSone(freenetRequest.toadletContext))
+ webInterface.core.deleteSone(currentSone)
}
throw RedirectException("index.html")
}
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
import net.pterodactylus.sone.web.page.FreenetRequest
* @see net.pterodactylus.sone.core.Core#distrustSone(Sone, Sone)
*/
class DistrustPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("distrust.html", template, "Page.Distrust.Title", webInterface, true) {
+ LoggedInPage("distrust.html", template, "Page.Distrust.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
webInterface.core.getSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sone", 44))
- ?.run { webInterface.core.distrustSone(getCurrentSone(freenetRequest.toadletContext), this) }
+ ?.run { webInterface.core.distrustSone(currentSone, this) }
throw RedirectException(freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
}
}
package net.pterodactylus.sone.web.pages
import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
import net.pterodactylus.sone.web.page.FreenetRequest
* Page that lets the user edit the name and description of an album.
*/
class EditAlbumPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface, true) {
+ LoggedInPage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
val album = webInterface.core.getAlbum(freenetRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
album.takeUnless { it.sone.isLocal }?.run { throw RedirectException("noPermission.html") }
package net.pterodactylus.sone.web.pages
import net.pterodactylus.sone.data.Image.Modifier.ImageTitleMustNotBeEmpty
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.text.TextFilter
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
* Page that lets the user edit title and description of an {@link Image}.
*/
class EditImagePage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("editImage.html", template, "Page.EditImage.Title", webInterface, true) {
+ LoggedInPage("editImage.html", template, "Page.EditImage.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
val image = webInterface.core.getImage(freenetRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
if (!image.sone.isLocal) {
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
import net.pterodactylus.sone.web.page.FreenetRequest
* Page that lets the user edit the name of a profile field.
*/
class EditProfileFieldPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("editProfileField.html", template, "Page.EditProfileField.Title", webInterface, true) {
+ LoggedInPage("editProfileField.html", template, "Page.EditProfileField.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- sessionProvider.getCurrentSone(freenetRequest.toadletContext)!!.let { currentSone ->
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
currentSone.profile.let { profile ->
if (freenetRequest.isPOST) {
if (freenetRequest.httpRequest.getPartAsStringFailsafe("cancel", 4) == "true") {
}
templateContext["field"] = profile.getFieldById(freenetRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
}
- }
}
}
package net.pterodactylus.sone.web.pages
import net.pterodactylus.sone.data.Profile.DuplicateField
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.text.TextFilter
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
/**
* This page lets the user edit her profile.
*/
-class EditProfilePage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("editProfile.html", template, "Page.EditProfile.Title", webInterface, true) {
+class EditProfilePage(template: Template, webInterface: WebInterface) :
+ LoggedInPage("editProfile.html", template, "Page.EditProfile.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- freenetRequest.currentSone!!.profile.let { profile ->
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
+ currentSone.profile.let { profile ->
templateContext["firstName"] = profile.firstName
templateContext["middleName"] = profile.middleName
templateContext["lastName"] = profile.lastName
val fieldName = freenetRequest.httpRequest.getPartAsStringFailsafe("field-name", 100)
try {
profile.addField(fieldName)
- freenetRequest.currentSone!!.profile = profile
+ currentSone.profile = profile
webInterface.core.touchConfiguration()
throw RedirectException("editProfile.html#profile-fields")
} catch (e: DuplicateField) {
throw RedirectException("editProfileField.html?field=${field.id}")
} else if (freenetRequest.httpRequest.getPartAsStringFailsafe("move-down-field-${field.id}", 4) == "true") {
profile.moveFieldDown(field)
- freenetRequest.currentSone!!.profile = profile
+ currentSone.profile = profile
throw RedirectException("editProfile.html#profile-fields")
} else if (freenetRequest.httpRequest.getPartAsStringFailsafe("move-up-field-${field.id}", 4) == "true") {
profile.moveFieldUp(field)
- freenetRequest.currentSone!!.profile = profile
+ currentSone.profile = profile
throw RedirectException("editProfile.html#profile-fields")
}
}
}
}
- private val FreenetRequest.currentSone get() = sessionProvider.getCurrentSone(toadletContext)
-
}
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
import net.pterodactylus.sone.web.page.FreenetRequest
* This page lets the user follow another Sone.
*/
class FollowSonePage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("followSone.html", template, "Page.FollowSone.Title", webInterface, true) {
+ LoggedInPage("followSone.html", template, "Page.FollowSone.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
freenetRequest.httpRequest.getPartAsStringFailsafe("sone", 1200).split(Regex("[ ,]+"))
.map { it to webInterface.core.getSone(it) }
.filterNot { it.second == null }
.forEach { sone ->
- webInterface.core.followSone(freenetRequest.currentSone, sone.first)
+ webInterface.core.followSone(currentSone, sone.first)
webInterface.core.markSoneKnown(sone.second)
}
throw RedirectException(freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
}
}
- private val FreenetRequest.currentSone get() = sessionProvider.getCurrentSone(toadletContext)
-
}
* The image browser page is the entry page for the image management.
*/
class ImageBrowserPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, true) {
+ LoggedInPage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if ("album" in freenetRequest.parameters) {
templateContext["albumRequested"] = true
templateContext["album"] = webInterface.core.getAlbum(freenetRequest.parameters["album"]!!)
}
} else {
templateContext["soneRequested"] = true
- templateContext["sone"] = webInterface.core.getSone(freenetRequest.httpRequest.getParam("sone")) ?: getCurrentSone(freenetRequest.toadletContext)
+ templateContext["sone"] = webInterface.core.getSone(freenetRequest.httpRequest.getParam("sone")) ?: currentSone
}
}
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.notify.PostVisibilityFilter
import net.pterodactylus.sone.utils.Pagination
import net.pterodactylus.sone.utils.parameters
* of all friends of the current user.
*/
class IndexPage(template: Template, webInterface: WebInterface, private val postVisibilityFilter: PostVisibilityFilter):
- SoneTemplatePage("index.html", template, "Page.Index.Title", webInterface, true) {
+ LoggedInPage("index.html", template, "Page.Index.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- getCurrentSone(freenetRequest.toadletContext)!!.let { currentSone ->
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
(currentSone.posts +
currentSone.friends
.mapNotNull(webInterface.core::getSone)
templateContext["posts"] = pagination.items
}
}
- }
}
}
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
/**
* Page that lets the user like [net.pterodactylus.sone.data.Post]s and [net.pterodactylus.sone.data.Reply]s.
*/
-class LikePage(template: Template, webInterface: WebInterface)
- : SoneTemplatePage("like.html", template, "Page.Like.Title", webInterface, true) {
+class LikePage(template: Template, webInterface: WebInterface) :
+ LoggedInPage("like.html", template, "Page.Like.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
- getCurrentSone(freenetRequest.toadletContext)!!.let { currentSone ->
freenetRequest.parameters["type", 16]?.also { type ->
when(type) {
"post" -> currentSone.addLikedPostId(freenetRequest.parameters["post", 36]!!)
}
}
throw RedirectException(freenetRequest.parameters["returnPage", 256]!!)
- }
}
}
--- /dev/null
+package net.pterodactylus.sone.web.pages
+
+import net.pterodactylus.sone.data.Sone
+import net.pterodactylus.sone.web.WebInterface
+import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.util.template.Template
+import net.pterodactylus.util.template.TemplateContext
+
+/**
+ * Base class for [SoneTemplatePage] implementations that require a logged in user.
+ */
+abstract class LoggedInPage(path: String, template: Template, pageTitleKey: String, webInterface: WebInterface) :
+ SoneTemplatePage(path, template, pageTitleKey, webInterface, true) {
+
+ final override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ handleRequest(freenetRequest, getCurrentSone(freenetRequest.toadletContext, false)!!, templateContext)
+ }
+
+ protected abstract fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext)
+
+}
package net.pterodactylus.sone.web.pages
import freenet.clients.http.ToadletContext
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.web.WebInterface
import net.pterodactylus.sone.web.page.FreenetRequest
import net.pterodactylus.util.template.Template
* Logs a user out.
*/
class LogoutPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("logout.html", template, "Page.Logout.Title", webInterface, true) {
+ LoggedInPage("logout.html", template, "Page.Logout.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
setCurrentSone(freenetRequest.toadletContext, null)
throw RedirectException("index.html")
}
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
* Page that lets the user control the rescue mode for a Sone.
*/
class RescuePage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("rescue.html", template, "Page.Rescue.Title", webInterface, true) {
+ LoggedInPage("rescue.html", template, "Page.Rescue.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- val soneRescuer = webInterface.core.getSoneRescuer(getCurrentSone(freenetRequest.toadletContext)!!)
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
+ val soneRescuer = webInterface.core.getSoneRescuer(currentSone)
templateContext["soneRescuer"] = soneRescuer
if (freenetRequest.isPOST) {
freenetRequest.parameters["edition", 9]?.toIntOrNull()?.also {
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
* amount of trust to an identity.
*/
class TrustPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("trust.html", template, "Page.Trust.Title", webInterface, true) {
+ LoggedInPage("trust.html", template, "Page.Trust.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
- getCurrentSone(freenetRequest.toadletContext)?.also { currentSone ->
webInterface.core.getSone(freenetRequest.parameters["sone"]!!)?.let { sone ->
webInterface.core.trustSone(currentSone, sone)
}
- }
throw RedirectException(freenetRequest.parameters["returnPage", 256])
}
}
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
* This page lets the user unfollow another Sone.
*/
class UnfollowSonePage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface, true) {
+ LoggedInPage("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
- getCurrentSone(freenetRequest.toadletContext)!!.also { currentSone ->
freenetRequest.parameters["sone"]!!.split(Regex("[ ,]+"))
.forEach { webInterface.core.unfollowSone(currentSone, it) }
- }
throw RedirectException(freenetRequest.parameters["returnPage", 256])
}
}
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
* Page that lets the user unlike a [net.pterodactylus.sone.data.Post] or [net.pterodactylus.sone.data.Reply].
*/
class UnlikePage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("unlike.html", template, "Page.Unlike.Title", webInterface, true) {
+ LoggedInPage("unlike.html", template, "Page.Unlike.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
when (freenetRequest.parameters["type"]) {
- "post" -> getCurrentSone(freenetRequest.toadletContext)!!.removeLikedPostId(freenetRequest.parameters["post"]!!)
- "reply" -> getCurrentSone(freenetRequest.toadletContext)!!.removeLikedReplyId(freenetRequest.parameters["reply"]!!)
+ "post" -> currentSone.removeLikedPostId(freenetRequest.parameters["post"]!!)
+ "reply" -> currentSone.removeLikedReplyId(freenetRequest.parameters["reply"]!!)
}
throw RedirectException(freenetRequest.parameters["returnPage", 256])
}
package net.pterodactylus.sone.web.pages
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
* assignments for an identity.
*/
class UntrustPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("untrust.html", template, "Page.Untrust.Title", webInterface, true) {
+ LoggedInPage("untrust.html", template, "Page.Untrust.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
- getCurrentSone(freenetRequest.toadletContext)!!.also { currentSone ->
freenetRequest.parameters["sone", 44]!!
.let(webInterface.core::getSone)
?.also { webInterface.core.untrustSone(currentSone, it) }
- }
throw RedirectException(freenetRequest.parameters["returnPage", 256])
}
}
package net.pterodactylus.sone.web.pages
import freenet.support.api.Bucket
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.text.TextFilter
import net.pterodactylus.sone.utils.emptyToNull
import net.pterodactylus.sone.utils.headers
* Page implementation that lets the user upload an image.
*/
class UploadImagePage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("uploadImage.html", template, "Page.UploadImage.Title", webInterface, true) {
+ LoggedInPage("uploadImage.html", template, "Page.UploadImage.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
val parentAlbum = freenetRequest.parameters["parent"]!!.let(webInterface.core::getAlbum) ?: throw RedirectException("noPermission.html")
- if (parentAlbum.sone != getCurrentSone(freenetRequest.toadletContext)) {
+ if (parentAlbum.sone != currentSone) {
throw RedirectException("noPermission.html")
}
val title = freenetRequest.parameters["title", 200].emptyToNull ?: throw RedirectException("emptyImageTitle.html")
}
val temporaryImage = webInterface.core.createTemporaryImage(bytes.mimeType, bytes)
- webInterface.core.createImage(getCurrentSone(freenetRequest.toadletContext), parentAlbum, temporaryImage).modify().apply {
+ webInterface.core.createImage(currentSone, parentAlbum, temporaryImage).modify().apply {
setWidth(bufferedImage.width)
setHeight(bufferedImage.height)
setTitle(title)