mirror of
https://github.com/bitwarden/android.git
synced 2026-06-07 14:57:41 -05:00
Add unlockVaultWithPinAndSync to VaultRepository (#613)
This commit is contained in:
committed by
Álison Fernandes
parent
18af449e1f
commit
3e28e5cc9b
@@ -108,9 +108,20 @@ interface VaultRepository : VaultLockManager {
|
||||
fun emitTotpCodeResult(totpCodeResult: TotpCodeResult)
|
||||
|
||||
/**
|
||||
* Attempt to unlock the vault and sync the vault data for the currently active user.
|
||||
* Attempt to unlock the vault with the given [masterPassword] and syncs the vault data for the
|
||||
* currently active user.
|
||||
*/
|
||||
suspend fun unlockVaultAndSyncForCurrentUser(masterPassword: String): VaultUnlockResult
|
||||
suspend fun unlockVaultWithMasterPasswordAndSync(
|
||||
masterPassword: String,
|
||||
): VaultUnlockResult
|
||||
|
||||
/**
|
||||
* Attempt to unlock the vault with the given [pin] and syncs the vault data for the currently
|
||||
* active user.
|
||||
*/
|
||||
suspend fun unlockVaultWithPinAndSync(
|
||||
pin: String,
|
||||
): VaultUnlockResult
|
||||
|
||||
/**
|
||||
* Attempt to unlock the vault with the specified user information.
|
||||
|
||||
@@ -284,7 +284,7 @@ class VaultRepositoryImpl(
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
override suspend fun unlockVaultAndSyncForCurrentUser(
|
||||
override suspend fun unlockVaultWithMasterPasswordAndSync(
|
||||
masterPassword: String,
|
||||
): VaultUnlockResult {
|
||||
val userId = activeUserId ?: return VaultUnlockResult.InvalidStateError
|
||||
@@ -304,6 +304,27 @@ class VaultRepositoryImpl(
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
override suspend fun unlockVaultWithPinAndSync(
|
||||
pin: String,
|
||||
): VaultUnlockResult {
|
||||
val userId = activeUserId ?: return VaultUnlockResult.InvalidStateError
|
||||
val pinProtectedUserKey = authDiskSource.getPinProtectedUserKey(userId = userId)
|
||||
?: return VaultUnlockResult.InvalidStateError
|
||||
return unlockVaultForUser(
|
||||
userId = userId,
|
||||
initUserCryptoMethod = InitUserCryptoMethod.Pin(
|
||||
pin = pin,
|
||||
pinProtectedUserKey = pinProtectedUserKey,
|
||||
),
|
||||
)
|
||||
.also {
|
||||
if (it is VaultUnlockResult.Success) {
|
||||
sync()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun unlockVault(
|
||||
userId: String,
|
||||
masterPassword: String,
|
||||
|
||||
@@ -127,7 +127,7 @@ class VaultUnlockViewModel @Inject constructor(
|
||||
private fun handleUnlockClick() {
|
||||
mutableStateFlow.update { it.copy(dialog = VaultUnlockState.VaultUnlockDialog.Loading) }
|
||||
viewModelScope.launch {
|
||||
val vaultUnlockResult = vaultRepo.unlockVaultAndSyncForCurrentUser(
|
||||
val vaultUnlockResult = vaultRepo.unlockVaultWithMasterPasswordAndSync(
|
||||
mutableStateFlow.value.passwordInput,
|
||||
)
|
||||
sendAction(VaultUnlockAction.Internal.ReceiveVaultUnlockResult(vaultUnlockResult))
|
||||
|
||||
Reference in New Issue
Block a user