TF-886 Implement GetAuthenticationInfo stored in repository and datasource
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -11,4 +11,8 @@ class AuthenticationInfoCacheManager {
|
||||
AuthenticationInfoCache.keyCacheValue,
|
||||
authenticationInfoCache);
|
||||
}
|
||||
|
||||
Future<AuthenticationInfoCache?> getAuthenticationInfoStored() {
|
||||
return _authenticationInfoCacheClient.getItem(AuthenticationInfoCache.keyCacheValue);
|
||||
}
|
||||
}
|
||||
@@ -32,36 +32,16 @@ class CredentialRepositoryImpl extends CredentialRepository {
|
||||
await sharedPreferences.remove(LoginConstant.keyBaseUrl);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Password> 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<UserName> 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<UserProfile> getUserProfile() async {
|
||||
final json = sharedPreferences.getString(LoginConstant.keyUserProfile) ?? '';
|
||||
@@ -85,4 +65,9 @@ class CredentialRepositoryImpl extends CredentialRepository {
|
||||
Future<void> storeAuthenticationInfo(AuthenticationInfoCache authenticationInfoCache) {
|
||||
return _authenticationInfoCacheManager.storeAuthenticationInfo(authenticationInfoCache);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<AuthenticationInfoCache?> getAuthenticationInfoStored() {
|
||||
return _authenticationInfoCacheManager.getAuthenticationInfoStored();
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,8 @@ abstract class CredentialRepository {
|
||||
|
||||
Future removeUserName();
|
||||
|
||||
Future<UserName> getUserName();
|
||||
|
||||
Future removePassword();
|
||||
|
||||
Future<Password> getPassword();
|
||||
|
||||
Future saveUserProfile(UserProfile userProfile);
|
||||
|
||||
Future removeUserProfile();
|
||||
@@ -23,4 +19,6 @@ abstract class CredentialRepository {
|
||||
Future<UserProfile> getUserProfile();
|
||||
|
||||
Future<void> storeAuthenticationInfo(AuthenticationInfoCache authenticationInfoCache);
|
||||
|
||||
Future<AuthenticationInfoCache?> getAuthenticationInfoStored();
|
||||
}
|
||||
@@ -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<Either<Failure, Success>> 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()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user