From: TheSaminator Date: Mon, 14 Feb 2022 17:39:12 +0000 (-0500) Subject: Add option to disable IP logging X-Git-Url: https://gitweb.starshipfights.net/?a=commitdiff_plain;h=efb1967a65477fa416994841024c24d22176aeda;p=starship-fights Add option to disable IP logging --- diff --git a/src/jvmMain/kotlin/starshipfights/auth/providers.kt b/src/jvmMain/kotlin/starshipfights/auth/providers.kt index cab29d6..e675c2a 100644 --- a/src/jvmMain/kotlin/starshipfights/auth/providers.kt +++ b/src/jvmMain/kotlin/starshipfights/auth/providers.kt @@ -91,10 +91,20 @@ interface AuthProvider { val newUser = currentUser.copy( showDiscordName = form["showdiscord"] == "yes", showUserStatus = form["showstatus"] == "yes", + logIpAddresses = form["logaddress"] == "yes", profileName = form["name"]?.takeIf { it.isNotBlank() && it.length <= PROFILE_NAME_MAX_LENGTH } ?: redirect("/me/manage?" + parametersOf("error", "Invalid name - must not be blank, must be at most $PROFILE_NAME_MAX_LENGTH characters").formUrlEncode()), profileBio = form["bio"]?.takeIf { it.isNotBlank() && it.length <= PROFILE_BIO_MAX_LENGTH } ?: redirect("/me/manage?" + parametersOf("error", "Invalid bio - must not be blank, must be at most $PROFILE_BIO_MAX_LENGTH characters").formUrlEncode()) ) User.put(newUser) + + if (!newUser.logIpAddresses) + launch { + UserSession.update( + UserSession::user eq currentUser.id, + setValue(UserSession::clientAddresses, emptyList()) + ) + } + redirect("/user/${newUser.id}") } @@ -365,6 +375,7 @@ object TestAuthProvider : AuthProvider { registeredAt = Instant.now(), lastActivity = Instant.now(), showUserStatus = false, + logIpAddresses = false, ).also { User.put(it) } @@ -539,6 +550,7 @@ class ProductionAuthProvider(val discordLogin: DiscordLogin) : AuthProvider { registeredAt = Instant.now(), lastActivity = Instant.now(), showUserStatus = false, + logIpAddresses = false, ) val userSession = UserSession( diff --git a/src/jvmMain/kotlin/starshipfights/auth/utils.kt b/src/jvmMain/kotlin/starshipfights/auth/utils.kt index beabee3..b5e5669 100644 --- a/src/jvmMain/kotlin/starshipfights/auth/utils.kt +++ b/src/jvmMain/kotlin/starshipfights/auth/utils.kt @@ -16,7 +16,12 @@ suspend fun Id.resolve(userAgent: String) = UserSession.get(this)?. suspend fun UserSession.renewed(clientAddress: String) = copy( expiration = Instant.now().plus(1, ChronoUnit.HOURS), - clientAddresses = if (clientAddresses.last() != clientAddress) clientAddresses + clientAddress else clientAddresses + clientAddresses = if (User.get(user)?.logIpAddresses != true) + emptyList() + else if (clientAddresses.lastOrNull() != clientAddress) + clientAddresses + clientAddress + else + clientAddresses ).also { UserSession.put(it) } suspend fun User.updated() = copy( diff --git a/src/jvmMain/kotlin/starshipfights/data/auth/user_sessions.kt b/src/jvmMain/kotlin/starshipfights/data/auth/user_sessions.kt index f53352d..23d60a3 100644 --- a/src/jvmMain/kotlin/starshipfights/data/auth/user_sessions.kt +++ b/src/jvmMain/kotlin/starshipfights/data/auth/user_sessions.kt @@ -28,6 +28,8 @@ data class User( val lastActivity: @Contextual Instant, val showUserStatus: Boolean, + val logIpAddresses: Boolean, + val status: UserStatus = UserStatus.AVAILABLE, ) : DataDocument { val discordAvatarUrl: String diff --git a/src/jvmMain/kotlin/starshipfights/info/views_user.kt b/src/jvmMain/kotlin/starshipfights/info/views_user.kt index 5faf523..cffb1ea 100644 --- a/src/jvmMain/kotlin/starshipfights/info/views_user.kt +++ b/src/jvmMain/kotlin/starshipfights/info/views_user.kt @@ -188,6 +188,16 @@ suspend fun ApplicationCall.manageUserPage(): HTML.() -> Unit { +Entities.nbsp +"Show Online Status" } + br + label { + checkBoxInput { + name = "logaddress" + checked = currentUser.logIpAddresses + value = "yes" + } + +Entities.nbsp + +"Log Session IP Addresses" + } request.queryParameters["error"]?.let { errorMsg -> p { style = "color:#d22"