java
}
-repositories {
- mavenCentral()
-}
-
-dependencies {
-}
-
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
package info.mechyrdia.auth
-import info.mechyrdia.data.DataDocument
-import info.mechyrdia.data.DocumentTable
-import info.mechyrdia.data.Id
-import info.mechyrdia.data.TableHolder
+import info.mechyrdia.data.*
import io.ktor.server.sessions.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class SessionStorageDoc(
- @SerialName("_id")
+ @SerialName(MONGODB_ID_KEY)
override val id: Id<SessionStorageDoc>,
val session: String
) : DataDocument<SessionStorageDoc> {
@Serializable
data class Comment(
- @SerialName("_id")
+ @SerialName(MONGODB_ID_KEY)
override val id: Id<Comment>,
val submittedBy: Id<NationData>,
@Serializable
data class CommentReplyLink(
- @SerialName("_id")
+ @SerialName(MONGODB_ID_KEY)
override val id: Id<CommentReplyLink> = Id(),
val originalPost: Id<Comment>,
}
interface DataDocument<T : DataDocument<T>> {
- @SerialName("_id")
+ @SerialName(MONGODB_ID_KEY)
val id: Id<T>
}
@Serializable
data class NationData(
- @SerialName("_id")
+ @SerialName(MONGODB_ID_KEY)
override val id: Id<NationData>,
val name: String,
val flag: String,
}
suspend fun ApplicationCall.viewCommentRoute(): Nothing {
- val commentId = Id<Comment>(parameters["id"]!!)
+ val commentId = Id<Comment>(parameters.getOrFail("id"))
val comment = Comment.Table.get(commentId)!!
}
suspend fun ApplicationCall.editCommentRoute(): Nothing {
- val commentId = Id<Comment>(parameters["id"]!!)
+ val commentId = Id<Comment>(parameters.getOrFail("id"))
val oldComment = Comment.Table.get(commentId)!!
private suspend fun ApplicationCall.getCommentForDeletion(): Pair<NationData, Comment> {
val currNation = currentNation() ?: redirectWithError("/auth/login", "You must be logged in to delete comments")
- val commentId = Id<Comment>(parameters["id"]!!)
+ val commentId = Id<Comment>(parameters.getOrFail("id"))
val comment = Comment.Table.get(commentId)!!
if (currNation.id != comment.submittedBy && currNation.id != OwnerNationId)
import info.mechyrdia.lore.redirect
import info.mechyrdia.lore.standardNavBar
import io.ktor.server.application.*
+import io.ktor.server.util.*
import kotlinx.coroutines.flow.toList
import kotlinx.html.*
suspend fun ApplicationCall.userPage(): HTML.() -> Unit {
val currNation = currentNation()
- val viewingNation = nationCache.getNation(Id(parameters["id"]!!))
+ val viewingNation = nationCache.getNation(Id(parameters.getOrFail("id")))
val comments = CommentRenderData(
Comment.getCommentsBy(viewingNation.id).toList(),
ownerNationOnly()
verifyCsrfToken()
- val bannedNation = nationCache.getNation(Id(parameters["id"]!!))
+ val bannedNation = nationCache.getNation(Id(parameters.getOrFail("id")))
if (!bannedNation.isBanned)
NationData.Table.set(bannedNation.id, Updates.set(NationData::isBanned.serialName, true))
ownerNationOnly()
verifyCsrfToken()
- val bannedNation = nationCache.getNation(Id(parameters["id"]!!))
+ val bannedNation = nationCache.getNation(Id(parameters.getOrFail("id")))
if (bannedNation.isBanned)
NationData.Table.set(bannedNation.id, Updates.set(NationData::isBanned.serialName, false))
@Serializable
data class PageVisitData(
- @SerialName("_id")
+ @SerialName(MONGODB_ID_KEY)
override val id: Id<PageVisitData> = Id(),
val path: String,
}
),
IMAGE(
- TextParserTagType.Indirect(false) { param, content, builder ->
+ TextParserTagType.Indirect(false) { _, content, builder ->
builder.addImage(imagePathToOpenGraphValue(content))
""
}