Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix case where PIN could be bypassed if server is down #520

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ class MainFragment :
}

viewModel.currentServer.observe(viewLifecycleOwner) { newServer ->
if (newServer == null) {
Log.w(TAG, "Null server")
viewModel.navigationManager.navigate(Destination.ManageServers(true))
return@observe
}
if (dataFetchedFor == newServer) {
return@observe
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ class RootActivity :
serverViewModel.serverConnection.observe(this) { result ->
when (result) {
is ServerViewModel.ServerConnection.Failure -> {
Log.w(TAG, "Exception connecting to server", result.ex)
Log.w(TAG, "Exception connecting to server", result.exception)
Toast
.makeText(
this,
"Error connecting to ${currentServer.url}",
"Error connecting to ${result.server.url}",
Toast.LENGTH_LONG,
).show()
navigationManager.navigate(Destination.ManageServers(true))
if (!appHasPin) {
navigationManager.navigate(Destination.ManageServers(true))
}
}

ServerViewModel.ServerConnection.NotConfigured -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ data class StashServer(
return serverPreferences
}

override fun toString(): String = "StashServer(url=$url, apiKey?=${apiKey.isNotNullOrBlank()})"

companion object {
private const val SERVER_PREF_PREFIX = "server_"
private const val SERVER_APIKEY_PREF_PREFIX = "apikey_"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.damontecres.stashapp.views.models

import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.preference.PreferenceManager
Expand All @@ -21,8 +22,7 @@ open class ServerViewModel : ViewModel() {
private val _currentServer = EqualityMutableLiveData<StashServer?>()
val currentServer: LiveData<StashServer?> = _currentServer

private val _serverConnection =
EqualityMutableLiveData<ServerConnection>(ServerConnection.Pending)
private val _serverConnection = MutableLiveData<ServerConnection>(ServerConnection.Pending)
val serverConnection: LiveData<ServerConnection> = _serverConnection

fun requireServer(): StashServer = currentServer.value!!
Expand All @@ -42,11 +42,12 @@ open class ServerViewModel : ViewModel() {
_currentServer.value = newServer
_serverConnection.value = ServerConnection.Success
} catch (ex: Exception) {
_serverConnection.value = ServerConnection.Failure(ex)
_currentServer.setValueNoCheck(null)
_serverConnection.value = ServerConnection.Failure(newServer, ex)
}
}
} else {
_currentServer.value = null
_currentServer.setValueNoCheck(null)
_serverConnection.value = ServerConnection.NotConfigured
}
}
Expand Down Expand Up @@ -123,7 +124,8 @@ open class ServerViewModel : ViewModel() {
data object Success : ServerConnection

data class Failure(
val ex: Exception,
val server: StashServer,
val exception: Exception,
) : ServerConnection

data object NotConfigured : ServerConnection
Expand Down
Loading