diff --git a/lib/features/email/domain/usecases/download_attachment_for_web_interactor.dart b/lib/features/email/domain/usecases/download_attachment_for_web_interactor.dart index 6509459e5..784d49540 100644 --- a/lib/features/email/domain/usecases/download_attachment_for_web_interactor.dart +++ b/lib/features/email/domain/usecases/download_attachment_for_web_interactor.dart @@ -46,10 +46,7 @@ class DownloadAttachmentForWebInteractor { if (currentAccount.authenticationType == AuthenticationType.oidc) _authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id) else - ...[ - credentialRepository.getUserName(), - credentialRepository.getPassword() - ] + credentialRepository.getAuthenticationInfoStored() ], eagerError: true).then((List responses) async { AccountRequest accountRequest; diff --git a/lib/features/email/domain/usecases/download_attachments_interactor.dart b/lib/features/email/domain/usecases/download_attachments_interactor.dart index 28a1348be..4b1c56556 100644 --- a/lib/features/email/domain/usecases/download_attachments_interactor.dart +++ b/lib/features/email/domain/usecases/download_attachments_interactor.dart @@ -40,10 +40,7 @@ class DownloadAttachmentsInteractor { if (account.authenticationType == AuthenticationType.oidc) _authenticationOIDCRepository.getStoredTokenOIDC(account.id) else - ...[ - credentialRepository.getUserName(), - credentialRepository.getPassword() - ] + credentialRepository.getAuthenticationInfoStored() ], eagerError: true ).then((List responses) async { AccountRequest accountRequest; diff --git a/lib/features/email/domain/usecases/export_attachment_interactor.dart b/lib/features/email/domain/usecases/export_attachment_interactor.dart index d09e08aae..5710372b6 100644 --- a/lib/features/email/domain/usecases/export_attachment_interactor.dart +++ b/lib/features/email/domain/usecases/export_attachment_interactor.dart @@ -39,10 +39,7 @@ class ExportAttachmentInteractor { if (account.authenticationType == AuthenticationType.oidc) _authenticationOIDCRepository.getStoredTokenOIDC(account.id) else - ...[ - credentialRepository.getUserName(), - credentialRepository.getPassword() - ] + credentialRepository.getAuthenticationInfoStored() ], eagerError: true ).then((List responses) async { AccountRequest accountRequest; diff --git a/lib/features/login/data/local/authentication_info_cache_manager.dart b/lib/features/login/data/local/authentication_info_cache_manager.dart index 15cc374f3..164315955 100644 --- a/lib/features/login/data/local/authentication_info_cache_manager.dart +++ b/lib/features/login/data/local/authentication_info_cache_manager.dart @@ -11,4 +11,8 @@ class AuthenticationInfoCacheManager { AuthenticationInfoCache.keyCacheValue, authenticationInfoCache); } + + Future getAuthenticationInfoStored() { + return _authenticationInfoCacheClient.getItem(AuthenticationInfoCache.keyCacheValue); + } } \ No newline at end of file diff --git a/lib/features/login/data/repository/credential_repository_impl.dart b/lib/features/login/data/repository/credential_repository_impl.dart index 10326698a..46f97dfde 100644 --- a/lib/features/login/data/repository/credential_repository_impl.dart +++ b/lib/features/login/data/repository/credential_repository_impl.dart @@ -32,36 +32,16 @@ class CredentialRepositoryImpl extends CredentialRepository { await sharedPreferences.remove(LoginConstant.keyBaseUrl); } - @override - Future getPassword() async { - return Password(sharedPreferences.getString(LoginConstant.keyPassword) ?? ''); - } - @override Future removePassword() async { await sharedPreferences.remove(LoginConstant.keyPassword); } - @override - Future savePassword(Password password) async { - await sharedPreferences.setString(LoginConstant.keyPassword, password.value); - } - - @override - Future getUserName() async { - return UserName(sharedPreferences.getString(LoginConstant.keyUserName) ?? ''); - } - @override Future removeUserName() async { await sharedPreferences.remove(LoginConstant.keyUserName); } - @override - Future saveUserName(UserName userName) async { - await sharedPreferences.setString(LoginConstant.keyUserName, userName.userName); - } - @override Future getUserProfile() async { final json = sharedPreferences.getString(LoginConstant.keyUserProfile) ?? ''; @@ -85,4 +65,9 @@ class CredentialRepositoryImpl extends CredentialRepository { Future storeAuthenticationInfo(AuthenticationInfoCache authenticationInfoCache) { return _authenticationInfoCacheManager.storeAuthenticationInfo(authenticationInfoCache); } + + @override + Future getAuthenticationInfoStored() { + return _authenticationInfoCacheManager.getAuthenticationInfoStored(); + } } \ No newline at end of file diff --git a/lib/features/login/domain/repository/credential_repository.dart b/lib/features/login/domain/repository/credential_repository.dart index b688a62ab..259c091d6 100644 --- a/lib/features/login/domain/repository/credential_repository.dart +++ b/lib/features/login/domain/repository/credential_repository.dart @@ -10,12 +10,8 @@ abstract class CredentialRepository { Future removeUserName(); - Future getUserName(); - Future removePassword(); - Future getPassword(); - Future saveUserProfile(UserProfile userProfile); Future removeUserProfile(); @@ -23,4 +19,6 @@ abstract class CredentialRepository { Future getUserProfile(); Future storeAuthenticationInfo(AuthenticationInfoCache authenticationInfoCache); + + Future getAuthenticationInfoStored(); } \ No newline at end of file diff --git a/lib/features/login/domain/usecases/get_credential_interactor.dart b/lib/features/login/domain/usecases/get_credential_interactor.dart index d320865d2..50d283fe5 100644 --- a/lib/features/login/domain/usecases/get_credential_interactor.dart +++ b/lib/features/login/domain/usecases/get_credential_interactor.dart @@ -2,6 +2,7 @@ import 'dart:core'; import 'package:core/core.dart'; import 'package:dartz/dartz.dart'; +import 'package:model/model.dart'; import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart'; import 'package:tmail_ui_user/features/login/domain/extensions/uri_extension.dart'; import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart'; @@ -15,10 +16,12 @@ class GetCredentialInteractor { Future> execute() async { try { final baseUrl = await credentialRepository.getBaseUrl(); - final userName = await credentialRepository.getUserName(); - final password = await credentialRepository.getPassword(); - if (isCredentialValid(baseUrl)) { - return Right(GetCredentialViewState(baseUrl, userName, password)); + final authenticationInfo = await credentialRepository.getAuthenticationInfoStored(); + if (isCredentialValid(baseUrl) && authenticationInfo != null) { + return Right(GetCredentialViewState( + baseUrl, + UserName(authenticationInfo.username), + Password(authenticationInfo.password))); } else { return Left(GetCredentialFailure(BadCredentials())); }