From: TheSaminator Date: Sun, 6 Feb 2022 21:40:15 +0000 (-0500) Subject: Hopefully fix login POSTing (2) X-Git-Url: https://gitweb.starshipfights.net/?a=commitdiff_plain;h=3d5bc336924dff7f228beb0b5a088100695e3c73;p=starship-fights Hopefully fix login POSTing (2) --- diff --git a/src/jvmMain/kotlin/starshipfights/auth/providers.kt b/src/jvmMain/kotlin/starshipfights/auth/providers.kt index 8018646..d4edc68 100644 --- a/src/jvmMain/kotlin/starshipfights/auth/providers.kt +++ b/src/jvmMain/kotlin/starshipfights/auth/providers.kt @@ -12,7 +12,6 @@ import io.ktor.routing.* import io.ktor.sessions.* import io.ktor.util.* import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.flow.singleOrNull import kotlinx.coroutines.launch import kotlinx.html.* import org.litote.kmongo.eq @@ -195,7 +194,7 @@ object TestAuthProvider : AuthProvider { val originAddress = request.origin.remoteHost val userAgent = request.userAgent() if (userAgent != null && credentials.name.isValidUsername() && credentials.password == TEST_PASSWORD) { - val user = User.select(User::username eq credentials.name).singleOrNull() + val user = User.locate(User::username eq credentials.name) ?: User(username = credentials.name).also { User.put(it) } UserSession( diff --git a/src/jvmMain/kotlin/starshipfights/data/data_documents.kt b/src/jvmMain/kotlin/starshipfights/data/data_documents.kt index 42c0b7e..cacfb99 100644 --- a/src/jvmMain/kotlin/starshipfights/data/data_documents.kt +++ b/src/jvmMain/kotlin/starshipfights/data/data_documents.kt @@ -34,16 +34,6 @@ object DocumentIdController : IdController { } } -sealed interface FullDocDelta> { - val doc: T -} - -sealed class DocumentDelta> { - data class Created>(override val doc: T) : DocumentDelta(), FullDocDelta - data class Updated>(override val doc: T) : DocumentDelta(), FullDocDelta - data class Deleted>(val id: Id) : DocumentDelta() -} - interface DocumentTable> { suspend fun index(vararg properties: KProperty1) suspend fun unique(vararg properties: KProperty1) @@ -53,6 +43,7 @@ interface DocumentTable> { suspend fun del(id: Id) suspend fun select(bson: Bson): Flow + suspend fun locate(bson: Bson): T? suspend fun update(where: Bson, set: Bson) suspend fun remove(where: Bson) @@ -106,6 +97,10 @@ private class DocumentTableImpl>(val kclass: KClass) : Do return collection().find(bson).toFlow() } + override suspend fun locate(bson: Bson): T? { + return collection().findOne(bson) + } + override suspend fun update(where: Bson, set: Bson) { collection().updateMany(where, set) } diff --git a/src/jvmMain/kotlin/starshipfights/info/views_user.kt b/src/jvmMain/kotlin/starshipfights/info/views_user.kt index 76b78bd..8e64fd6 100644 --- a/src/jvmMain/kotlin/starshipfights/info/views_user.kt +++ b/src/jvmMain/kotlin/starshipfights/info/views_user.kt @@ -3,7 +3,6 @@ package starshipfights.info import io.ktor.application.* import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.flow.singleOrNull import kotlinx.coroutines.flow.toList import kotlinx.html.* import org.litote.kmongo.eq @@ -26,7 +25,7 @@ import java.time.Instant suspend fun ApplicationCall.userPage(): HTML.() -> Unit { val username = parameters["name"]!! - val user = User.select(User::username eq username).singleOrNull()!! + val user = User.locate(User::username eq username)!! val isCurrentUser = user.id == getUserSession()?.user