Minor formatting and cleanup (#1208)

This commit is contained in:
David Perez 2024-04-02 10:54:47 -05:00 committed by Álison Fernandes
parent 6390fe1ab4
commit 039253ac96
2 changed files with 19 additions and 30 deletions

View file

@ -471,6 +471,7 @@ class AuthRepositoryImpl(
.environment
.environmentUrlData,
)
val userId = userStateJson.activeUserId
// If the user just authenticated with a two-factor code and selected
// the option to remember it, then the API response will return a token
@ -498,7 +499,7 @@ class AuthRepositoryImpl(
password?.let {
if (loginResponse.privateKey != null && loginResponse.key != null) {
vaultRepository.unlockVault(
userId = userStateJson.activeUserId,
userId = userId,
email = userStateJson.activeAccount.profile.email,
kdf = userStateJson.activeAccount.profile.toSdkParams(),
userKey = loginResponse.key,
@ -520,7 +521,7 @@ class AuthRepositoryImpl(
)
.onSuccess { passwordHash ->
authDiskSource.storeMasterPasswordHash(
userId = userStateJson.activeUserId,
userId = userId,
passwordHash = passwordHash,
)
}
@ -535,7 +536,7 @@ class AuthRepositoryImpl(
if (loginResponse.privateKey != null && loginResponse.key != null) {
deviceData?.let { model ->
vaultRepository.unlockVault(
userId = userStateJson.activeUserId,
userId = userId,
email = userStateJson.activeAccount.profile.email,
kdf = userStateJson.activeAccount.profile.toSdkParams(),
privateKey = loginResponse.privateKey,
@ -565,24 +566,19 @@ class AuthRepositoryImpl(
}
authDiskSource.storeAccountTokens(
userId = userStateJson.activeUserId,
userId = userId,
accountTokens = AccountTokensJson(
accessToken = loginResponse.accessToken,
refreshToken = loginResponse.refreshToken,
),
)
authDiskSource.userState = userStateJson
authDiskSource.storeUserKey(
userId = userStateJson.activeUserId,
userKey = loginResponse.key,
)
authDiskSource.storeUserKey(userId = userId, userKey = loginResponse.key)
authDiskSource.storePrivateKey(
userId = userStateJson.activeUserId,
userId = userId,
privateKey = loginResponse.privateKey,
)
settingsRepository.setDefaultsIfNecessary(
userId = userStateJson.activeUserId,
)
settingsRepository.setDefaultsIfNecessary(userId = userId)
vaultRepository.syncIfNecessary()
hasPendingAccountAddition = false
LoginResult.Success

View file

@ -248,8 +248,7 @@ class VaultLockManagerImpl(
private fun storeUserAutoUnlockKeyIfNecessary(userId: String) {
val vaultTimeout = settingsRepository.getVaultTimeoutStateFlow(userId = userId).value
if (
vaultTimeout == VaultTimeout.Never &&
if (vaultTimeout == VaultTimeout.Never &&
authDiskSource.getUserAutoUnlockKey(userId = userId) == null
) {
unconfinedScope.launch {
@ -354,10 +353,9 @@ class VaultLockManagerImpl(
if (isVaultUnlocked(userId = userId)) {
// Get and save the key if necessary
val userAutoUnlockKey =
vaultSdkSource
.getUserEncryptionKey(userId = userId)
.getOrNull()
val userAutoUnlockKey = vaultSdkSource
.getUserEncryptionKey(userId = userId)
.getOrNull()
authDiskSource.storeUserAutoUnlockKey(
userId = userId,
userAutoUnlockKey = userAutoUnlockKey,
@ -367,8 +365,7 @@ class VaultLockManagerImpl(
authDiskSource.getUserAutoUnlockKey(userId = userId)?.let {
val result = unlockVaultForUser(
userId = userId,
initUserCryptoMethod =
InitUserCryptoMethod.DecryptedKey(
initUserCryptoMethod = InitUserCryptoMethod.DecryptedKey(
decryptedUserKey = it,
),
)
@ -410,14 +407,11 @@ class VaultLockManagerImpl(
isAppRestart: Boolean = false,
) {
val currentTimeMillis = elapsedRealtimeMillisProvider()
val lastActiveTimeMillis =
authDiskSource
.getLastActiveTimeMillis(userId = userId)
?: 0
val vaultTimeout =
settingsRepository.getVaultTimeoutStateFlow(userId = userId).value
val vaultTimeoutAction =
settingsRepository.getVaultTimeoutActionStateFlow(userId = userId).value
val lastActiveTimeMillis = authDiskSource.getLastActiveTimeMillis(userId = userId) ?: 0
val vaultTimeout = settingsRepository.getVaultTimeoutStateFlow(userId = userId).value
val vaultTimeoutAction = settingsRepository
.getVaultTimeoutActionStateFlow(userId = userId)
.value
val vaultTimeoutInMinutes = when (vaultTimeout) {
VaultTimeout.Never -> {
@ -470,8 +464,7 @@ class VaultLockManagerImpl(
?: return VaultUnlockResult.InvalidStateError
val privateKey = authDiskSource.getPrivateKey(userId = userId)
?: return VaultUnlockResult.InvalidStateError
val organizationKeys = authDiskSource
.getOrganizationKeys(userId = userId)
val organizationKeys = authDiskSource.getOrganizationKeys(userId = userId)
return unlockVault(
userId = userId,
email = account.profile.email,