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)
|
if (currentAccount.authenticationType == AuthenticationType.oidc)
|
||||||
_authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id)
|
_authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id)
|
||||||
else
|
else
|
||||||
...[
|
credentialRepository.getAuthenticationInfoStored()
|
||||||
credentialRepository.getUserName(),
|
|
||||||
credentialRepository.getPassword()
|
|
||||||
]
|
|
||||||
], eagerError: true).then((List responses) async {
|
], eagerError: true).then((List responses) async {
|
||||||
AccountRequest accountRequest;
|
AccountRequest accountRequest;
|
||||||
|
|
||||||
|
|||||||
@@ -40,10 +40,7 @@ class DownloadAttachmentsInteractor {
|
|||||||
if (account.authenticationType == AuthenticationType.oidc)
|
if (account.authenticationType == AuthenticationType.oidc)
|
||||||
_authenticationOIDCRepository.getStoredTokenOIDC(account.id)
|
_authenticationOIDCRepository.getStoredTokenOIDC(account.id)
|
||||||
else
|
else
|
||||||
...[
|
credentialRepository.getAuthenticationInfoStored()
|
||||||
credentialRepository.getUserName(),
|
|
||||||
credentialRepository.getPassword()
|
|
||||||
]
|
|
||||||
], eagerError: true
|
], eagerError: true
|
||||||
).then((List responses) async {
|
).then((List responses) async {
|
||||||
AccountRequest accountRequest;
|
AccountRequest accountRequest;
|
||||||
|
|||||||
@@ -39,10 +39,7 @@ class ExportAttachmentInteractor {
|
|||||||
if (account.authenticationType == AuthenticationType.oidc)
|
if (account.authenticationType == AuthenticationType.oidc)
|
||||||
_authenticationOIDCRepository.getStoredTokenOIDC(account.id)
|
_authenticationOIDCRepository.getStoredTokenOIDC(account.id)
|
||||||
else
|
else
|
||||||
...[
|
credentialRepository.getAuthenticationInfoStored()
|
||||||
credentialRepository.getUserName(),
|
|
||||||
credentialRepository.getPassword()
|
|
||||||
]
|
|
||||||
], eagerError: true
|
], eagerError: true
|
||||||
).then((List responses) async {
|
).then((List responses) async {
|
||||||
AccountRequest accountRequest;
|
AccountRequest accountRequest;
|
||||||
|
|||||||
@@ -11,4 +11,8 @@ class AuthenticationInfoCacheManager {
|
|||||||
AuthenticationInfoCache.keyCacheValue,
|
AuthenticationInfoCache.keyCacheValue,
|
||||||
authenticationInfoCache);
|
authenticationInfoCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<AuthenticationInfoCache?> getAuthenticationInfoStored() {
|
||||||
|
return _authenticationInfoCacheClient.getItem(AuthenticationInfoCache.keyCacheValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -32,36 +32,16 @@ class CredentialRepositoryImpl extends CredentialRepository {
|
|||||||
await sharedPreferences.remove(LoginConstant.keyBaseUrl);
|
await sharedPreferences.remove(LoginConstant.keyBaseUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<Password> getPassword() async {
|
|
||||||
return Password(sharedPreferences.getString(LoginConstant.keyPassword) ?? '');
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future removePassword() async {
|
Future removePassword() async {
|
||||||
await sharedPreferences.remove(LoginConstant.keyPassword);
|
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
|
@override
|
||||||
Future removeUserName() async {
|
Future removeUserName() async {
|
||||||
await sharedPreferences.remove(LoginConstant.keyUserName);
|
await sharedPreferences.remove(LoginConstant.keyUserName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future saveUserName(UserName userName) async {
|
|
||||||
await sharedPreferences.setString(LoginConstant.keyUserName, userName.userName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<UserProfile> getUserProfile() async {
|
Future<UserProfile> getUserProfile() async {
|
||||||
final json = sharedPreferences.getString(LoginConstant.keyUserProfile) ?? '';
|
final json = sharedPreferences.getString(LoginConstant.keyUserProfile) ?? '';
|
||||||
@@ -85,4 +65,9 @@ class CredentialRepositoryImpl extends CredentialRepository {
|
|||||||
Future<void> storeAuthenticationInfo(AuthenticationInfoCache authenticationInfoCache) {
|
Future<void> storeAuthenticationInfo(AuthenticationInfoCache authenticationInfoCache) {
|
||||||
return _authenticationInfoCacheManager.storeAuthenticationInfo(authenticationInfoCache);
|
return _authenticationInfoCacheManager.storeAuthenticationInfo(authenticationInfoCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<AuthenticationInfoCache?> getAuthenticationInfoStored() {
|
||||||
|
return _authenticationInfoCacheManager.getAuthenticationInfoStored();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,12 +10,8 @@ abstract class CredentialRepository {
|
|||||||
|
|
||||||
Future removeUserName();
|
Future removeUserName();
|
||||||
|
|
||||||
Future<UserName> getUserName();
|
|
||||||
|
|
||||||
Future removePassword();
|
Future removePassword();
|
||||||
|
|
||||||
Future<Password> getPassword();
|
|
||||||
|
|
||||||
Future saveUserProfile(UserProfile userProfile);
|
Future saveUserProfile(UserProfile userProfile);
|
||||||
|
|
||||||
Future removeUserProfile();
|
Future removeUserProfile();
|
||||||
@@ -23,4 +19,6 @@ abstract class CredentialRepository {
|
|||||||
Future<UserProfile> getUserProfile();
|
Future<UserProfile> getUserProfile();
|
||||||
|
|
||||||
Future<void> storeAuthenticationInfo(AuthenticationInfoCache authenticationInfoCache);
|
Future<void> storeAuthenticationInfo(AuthenticationInfoCache authenticationInfoCache);
|
||||||
|
|
||||||
|
Future<AuthenticationInfoCache?> getAuthenticationInfoStored();
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ import 'dart:core';
|
|||||||
|
|
||||||
import 'package:core/core.dart';
|
import 'package:core/core.dart';
|
||||||
import 'package:dartz/dartz.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/exceptions/authentication_exception.dart';
|
||||||
import 'package:tmail_ui_user/features/login/domain/extensions/uri_extension.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';
|
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
|
||||||
@@ -15,10 +16,12 @@ class GetCredentialInteractor {
|
|||||||
Future<Either<Failure, Success>> execute() async {
|
Future<Either<Failure, Success>> execute() async {
|
||||||
try {
|
try {
|
||||||
final baseUrl = await credentialRepository.getBaseUrl();
|
final baseUrl = await credentialRepository.getBaseUrl();
|
||||||
final userName = await credentialRepository.getUserName();
|
final authenticationInfo = await credentialRepository.getAuthenticationInfoStored();
|
||||||
final password = await credentialRepository.getPassword();
|
if (isCredentialValid(baseUrl) && authenticationInfo != null) {
|
||||||
if (isCredentialValid(baseUrl)) {
|
return Right(GetCredentialViewState(
|
||||||
return Right(GetCredentialViewState(baseUrl, userName, password));
|
baseUrl,
|
||||||
|
UserName(authenticationInfo.username),
|
||||||
|
Password(authenticationInfo.password)));
|
||||||
} else {
|
} else {
|
||||||
return Left(GetCredentialFailure(BadCredentials()));
|
return Left(GetCredentialFailure(BadCredentials()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user