Hopefully fix login POSTing (2)
authorTheSaminator <TheSaminator@users.noreply.github.com>
Sun, 6 Feb 2022 21:40:15 +0000 (16:40 -0500)
committerTheSaminator <TheSaminator@users.noreply.github.com>
Sun, 6 Feb 2022 21:40:15 +0000 (16:40 -0500)
src/jvmMain/kotlin/starshipfights/auth/providers.kt
src/jvmMain/kotlin/starshipfights/data/data_documents.kt
src/jvmMain/kotlin/starshipfights/info/views_user.kt

index 80186465ac2a3d0c1ea3b2c2aa86cecdc180e35d..d4edc688b44652a89fe815f3534f2d7cc9dd59c5 100644 (file)
@@ -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(
index 42c0b7e557ab7d2da8d37c03ee9a8ec53d926b8b..cacfb990bd6999da108820ffcb87df6b6ecb955e 100644 (file)
@@ -34,16 +34,6 @@ object DocumentIdController : IdController {
        }
 }
 
-sealed interface FullDocDelta<T : DataDocument<T>> {
-       val doc: T
-}
-
-sealed class DocumentDelta<T : DataDocument<T>> {
-       data class Created<T : DataDocument<T>>(override val doc: T) : DocumentDelta<T>(), FullDocDelta<T>
-       data class Updated<T : DataDocument<T>>(override val doc: T) : DocumentDelta<T>(), FullDocDelta<T>
-       data class Deleted<T : DataDocument<T>>(val id: Id<T>) : DocumentDelta<T>()
-}
-
 interface DocumentTable<T : DataDocument<T>> {
        suspend fun index(vararg properties: KProperty1<T, *>)
        suspend fun unique(vararg properties: KProperty1<T, *>)
@@ -53,6 +43,7 @@ interface DocumentTable<T : DataDocument<T>> {
        suspend fun del(id: Id<T>)
        
        suspend fun select(bson: Bson): Flow<T>
+       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<T : DataDocument<T>>(val kclass: KClass<T>) : 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)
        }
index 76b78bde93eed6344c6d3eaacc55e449895f4fa8..8e64fd6f4d89d594411e0196e3e0f5c73367c314 100644 (file)
@@ -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