mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-06 03:18:23 +00:00
Show the error in the login screen
This commit is contained in:
@@ -127,7 +127,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
|
||||
tryLoginExistingAccount(route, npub)
|
||||
}
|
||||
|
||||
fun isValidKey(key: String, password: String): Boolean {
|
||||
fun isValidKey(key: String, password: String): Pair<Boolean, String> {
|
||||
try {
|
||||
val account =
|
||||
if (key.startsWith("ncryptsec")) {
|
||||
@@ -174,9 +174,9 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
|
||||
didBackup = true,
|
||||
)
|
||||
}
|
||||
return account.signer.keyPair.privKey != null
|
||||
} catch (_: Exception) {
|
||||
return false
|
||||
return Pair(account.signer.keyPair.privKey != null, "")
|
||||
} catch (e: Exception) {
|
||||
return Pair(false, e.message ?: "Unknown error")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -794,12 +794,13 @@ fun LoginPage(
|
||||
}
|
||||
|
||||
if (key.value.text.isNotBlank() && !(needsPassword.value && password.value.text.isBlank())) {
|
||||
if (accountViewModel.isValidKey(key.value.text.toLowerCase(Locale.current).trim(), password.value.text)) {
|
||||
val isValid = accountViewModel.isValidKey(key.value.text.toLowerCase(Locale.current).trim(), password.value.text)
|
||||
if (isValid.first) {
|
||||
scope.launch {
|
||||
pageState.animateScrollToPage(1)
|
||||
}
|
||||
} else {
|
||||
errorMessage = context.getString(R.string.invalid_key)
|
||||
errorMessage = isValid.second
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -869,12 +870,13 @@ fun LoginPage(
|
||||
}
|
||||
|
||||
if (key.value.text.isNotBlank() && !(needsPassword.value && password.value.text.isBlank())) {
|
||||
if (accountViewModel.isValidKey(key.value.text.toLowerCase(Locale.current).trim(), password.value.text)) {
|
||||
val isValid = accountViewModel.isValidKey(key.value.text.toLowerCase(Locale.current).trim(), password.value.text)
|
||||
if (isValid.first) {
|
||||
scope.launch {
|
||||
pageState.animateScrollToPage(1)
|
||||
}
|
||||
} else {
|
||||
errorMessage = context.getString(R.string.invalid_key)
|
||||
errorMessage = isValid.second
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -901,13 +903,14 @@ fun LoginPage(
|
||||
}
|
||||
|
||||
if (key.value.text.isNotBlank() && !(needsPassword.value && password.value.text.isBlank())) {
|
||||
if (accountViewModel.isValidKey(key.value.text.toLowerCase(Locale.current).trim(), password.value.text)) {
|
||||
val isValid = accountViewModel.isValidKey(key.value.text.toLowerCase(Locale.current).trim(), password.value.text)
|
||||
if (isValid.first) {
|
||||
keyboardController?.hide()
|
||||
scope.launch {
|
||||
pageState.animateScrollToPage(1)
|
||||
}
|
||||
} else {
|
||||
errorMessage = context.getString(R.string.invalid_key)
|
||||
errorMessage = isValid.second
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user