Add unlockVaultWithPinAndSync to VaultRepository (#613)

This commit is contained in:
Brian Yencho
2024-01-14 21:08:35 -06:00
committed by Álison Fernandes
parent 18af449e1f
commit 3e28e5cc9b
5 changed files with 375 additions and 202 deletions

View File

@@ -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.

View File

@@ -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,

View File

@@ -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))