import starshipfights.game.Faction
import starshipfights.info.*
import starshipfights.redirect
-import starshipfights.sfLogger
interface AuthProvider {
fun installAuth(conf: Authentication.Configuration)
val originAddress = request.origin.remoteHost
val userAgent = request.userAgent()
if (userAgent != null && credentials.name.isValidUsername() && credentials.password == TEST_PASSWORD) {
- sfLogger.info("Attempting to find user ${credentials.name}")
val user = User.locate(User::username eq credentials.name)
?: User(username = credentials.name).also {
- sfLogger.info("Attempting to add user with name ${credentials.name}")
User.put(it)
}
- sfLogger.info("Got user ${user.id}")
UserSession(
user = user.id,
import kotlinx.coroutines.flow.Flow
import kotlinx.serialization.SerialName
import org.bson.conversions.Bson
-import org.litote.kmongo.coroutine.CoroutineCollection
import org.litote.kmongo.coroutine.coroutine
import org.litote.kmongo.serialization.IdController
import org.slf4j.Logger
import org.slf4j.LoggerFactory
-import starshipfights.sfLogger
import kotlin.coroutines.CoroutineContext
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1
}
private class DocumentTableImpl<T : DataDocument<T>>(val kclass: KClass<T>, private val initFunc: (DocumentTable<T>) -> Unit) : DocumentTable<T> {
- private var collection: CoroutineCollection<T>? = null
- suspend fun collection() =
- collection
- ?: ConnectionHolder.getDatabase().database.getCollection(kclass.simpleName, kclass.java).coroutine.also {
- collection = it
- }
+ suspend fun collection() = ConnectionHolder.getDatabase().database.getCollection(kclass.simpleName, kclass.java).coroutine
override fun initialize() {
initFunc(this)
}
override suspend fun locate(bson: Bson): T? {
- try {
- return collection().findOne(bson)
- } catch (ex: Exception) {
- sfLogger.error("Got exception from table ${kclass.simpleName}", ex)
- throw ex
- }
+ return collection().findOne(bson)
}
override suspend fun update(where: Bson, set: Bson) {