BIT-2232: Don't require password for PIN setup for users w/o password (#1252)

This commit is contained in:
Caleb Derosier
2024-04-11 14:11:05 -06:00
committed by Álison Fernandes
parent bc350773be
commit f2301e15b9
5 changed files with 90 additions and 7 deletions

View File

@@ -42,7 +42,9 @@ data class UserState(
* @property isVaultUnlocked Whether or not the user's vault is currently unlocked.
* @property needsPasswordReset If the user needs to reset their password.
* @property needsMasterPassword Indicates whether the user needs to create a password (e.g.
* they logged in using SSO and don't yet have one).
* they logged in using SSO and don't yet have one). NOTE: This should **not** be used to
* determine whether a user has a master password. There are cases in which a user can both
* not have a password but still not need one, such as TDE.
* @property organizations List of [Organization]s the user is associated with, if any.
* @property isBiometricsEnabled Indicates that the biometrics mechanism for unlocking the
* user's vault is enabled.

View File

@@ -206,6 +206,7 @@ fun AccountSecurityScreen(
.padding(horizontal = 16.dp),
)
UnlockWithPinRow(
isUnlockWithPasswordEnabled = state.isUnlockWithPasswordEnabled,
isUnlockWithPinEnabled = state.isUnlockWithPinEnabled,
onUnlockWithPinToggleAction = remember(viewModel) {
{ viewModel.trySendAction(it) }
@@ -400,6 +401,7 @@ private fun UnlockWithBiometricsRow(
@Suppress("LongMethod")
@Composable
private fun UnlockWithPinRow(
isUnlockWithPasswordEnabled: Boolean,
isUnlockWithPinEnabled: Boolean,
onUnlockWithPinToggleAction: (AccountSecurityAction.UnlockWithPinToggle) -> Unit,
modifier: Modifier = Modifier,
@@ -440,10 +442,19 @@ private fun UnlockWithPinRow(
onSubmitClick = {
if (pin.isNotEmpty()) {
shouldShowPinInputDialog = false
shouldShowPinConfirmationDialog = true
onUnlockWithPinToggleAction(
AccountSecurityAction.UnlockWithPinToggle.PendingEnabled,
)
if (isUnlockWithPasswordEnabled) {
shouldShowPinConfirmationDialog = true
onUnlockWithPinToggleAction(
AccountSecurityAction.UnlockWithPinToggle.PendingEnabled,
)
} else {
onUnlockWithPinToggleAction(
AccountSecurityAction.UnlockWithPinToggle.Enabled(
pin = pin,
shouldRequireMasterPasswordOnRestart = false,
),
)
}
} else {
shouldShowPinInputDialog = false
onUnlockWithPinToggleAction(

View File

@@ -50,6 +50,12 @@ class AccountSecurityViewModel @Inject constructor(
fingerprintPhrase = "".asText(), // This will be filled in dynamically
isApproveLoginRequestsEnabled = settingsRepository.isApprovePasswordlessLoginsEnabled,
isUnlockWithBiometricsEnabled = settingsRepository.isUnlockWithBiometricsEnabled,
isUnlockWithPasswordEnabled = authRepository
.userStateFlow
.value
?.activeAccount
?.trustedDevice
?.hasMasterPassword != false,
isUnlockWithPinEnabled = settingsRepository.isUnlockWithPinEnabled,
vaultTimeout = settingsRepository.vaultTimeout,
vaultTimeoutAction = settingsRepository.vaultTimeoutAction,
@@ -357,6 +363,7 @@ data class AccountSecurityState(
val fingerprintPhrase: Text,
val isApproveLoginRequestsEnabled: Boolean,
val isUnlockWithBiometricsEnabled: Boolean,
val isUnlockWithPasswordEnabled: Boolean,
val isUnlockWithPinEnabled: Boolean,
val vaultTimeout: VaultTimeout,
val vaultTimeoutAction: VaultTimeoutAction,