TF-1074 Handle go to path /login

This commit is contained in:
dab246
2022-10-25 14:25:12 +07:00
committed by Dat H. Pham
parent a32bfe35de
commit 0ee990262f
21 changed files with 315 additions and 171 deletions
@@ -2,6 +2,14 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
class AuthenticateOidcOnBrowserLoading extends LoadingState {
AuthenticateOidcOnBrowserLoading();
@override
List<Object> get props => [];
}
class AuthenticateOidcOnBrowserSuccess extends UIState {
AuthenticateOidcOnBrowserSuccess();
@@ -1,17 +1,24 @@
import 'package:core/core.dart';
import 'package:model/model.dart';
class AuthenticationUserViewState extends UIState {
class AuthenticationUserLoading extends LoadingState {
AuthenticationUserLoading();
@override
List<Object> get props => [];
}
class AuthenticationUserSuccess extends UIState {
final UserProfile userProfile;
AuthenticationUserViewState(this.userProfile);
AuthenticationUserSuccess(this.userProfile);
@override
List<Object> get props => [userProfile];
}
class AuthenticationUserFailure extends FeatureFailure {
final exception;
final dynamic exception;
AuthenticationUserFailure(this.exception);
@@ -1,6 +1,15 @@
import 'package:core/core.dart';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:model/oidc/response/oidc_response.dart';
class CheckOIDCIsAvailableLoading extends LoadingState {
CheckOIDCIsAvailableLoading();
@override
List<Object> get props => [];
}
class CheckOIDCIsAvailableSuccess extends UIState {
final OIDCResponse oidcResponse;
@@ -2,6 +2,14 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
class GetAuthenticationInfoLoading extends LoadingState {
GetAuthenticationInfoLoading();
@override
List<Object> get props => [];
}
class GetAuthenticationInfoSuccess extends UIState {
GetAuthenticationInfoSuccess();
@@ -1,6 +1,14 @@
import 'package:core/core.dart';
import 'package:model/model.dart';
class GetOIDCConfigurationLoading extends LoadingState {
GetOIDCConfigurationLoading();
@override
List<Object> get props => [];
}
class GetOIDCConfigurationSuccess extends UIState {
final OIDCConfiguration oidcConfiguration;
@@ -0,0 +1,29 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:model/oidc/response/oidc_response.dart';
class GetOIDCIsAvailableLoading extends LoadingState {
GetOIDCIsAvailableLoading();
@override
List<Object> get props => [];
}
class GetOIDCIsAvailableSuccess extends UIState {
final OIDCResponse oidcResponse;
GetOIDCIsAvailableSuccess(this.oidcResponse);
@override
List<Object> get props => [oidcResponse];
}
class GetOIDCIsAvailableFailure extends FeatureFailure {
final dynamic exception;
GetOIDCIsAvailableFailure(this.exception);
@override
List<Object> get props => [exception];
}
@@ -2,6 +2,14 @@ import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:model/oidc/oidc_configuration.dart';
class GetStoredOidcConfigurationLoading extends LoadingState {
GetStoredOidcConfigurationLoading();
@override
List<Object?> get props => [];
}
class GetStoredOidcConfigurationSuccess extends UIState {
final OIDCConfiguration oidcConfiguration;
@@ -1,14 +1,23 @@
import 'package:core/core.dart';
import 'package:model/model.dart';
class GetTokenOIDCLoading extends LoadingState {
GetTokenOIDCLoading();
@override
List<Object> get props => [];
}
class GetTokenOIDCSuccess extends UIState {
final TokenOIDC tokenOIDC;
final OIDCConfiguration configuration;
GetTokenOIDCSuccess(this.tokenOIDC);
GetTokenOIDCSuccess(this.tokenOIDC, this.configuration);
@override
List<Object> get props => [tokenOIDC];
List<Object> get props => [tokenOIDC, configuration];
}
class GetTokenOIDCFailure extends FeatureFailure {
@@ -14,17 +14,18 @@ class AuthenticateOidcOnBrowserInteractor {
AuthenticateOidcOnBrowserInteractor(this.authenticationOIDCRepository);
Future<Either<Failure, Success>> execute(Uri baseUrl, OIDCConfiguration config) async {
Stream<Either<Failure, Success>> execute(Uri baseUrl, OIDCConfiguration config) async* {
try {
yield Right<Failure, Success>(AuthenticateOidcOnBrowserLoading());
await authenticationOIDCRepository.authenticateOidcOnBrowser(
config.clientId,
config.redirectUrl,
config.discoveryUrl,
config.scopes);
return Right<Failure, Success>(AuthenticateOidcOnBrowserSuccess());
yield Right<Failure, Success>(AuthenticateOidcOnBrowserSuccess());
} catch (e) {
logError('AuthenticateOidcOnBrowserInteractor::execute(): $e');
return Left<Failure, Success>(AuthenticateOidcOnBrowserFailure(e));
yield Left<Failure, Success>(AuthenticateOidcOnBrowserFailure(e));
}
}
}
@@ -12,11 +12,15 @@ class AuthenticationInteractor {
final CredentialRepository credentialRepository;
final AccountRepository _accountRepository;
AuthenticationInteractor(this.authenticationRepository, this.credentialRepository, this._accountRepository);
AuthenticationInteractor(
this.authenticationRepository,
this.credentialRepository,
this._accountRepository
);
Future<Either<Failure, Success>> execute(Uri baseUrl, UserName userName, Password password) async {
Stream<Either<Failure, Success>> execute(Uri baseUrl, UserName userName, Password password) async* {
try {
log('AuthenticationInteractor::execute(): $_accountRepository');
yield Right(AuthenticationUserLoading());
final user = await authenticationRepository.authenticationUser(baseUrl, userName, password);
await Future.wait([
credentialRepository.saveBaseUrl(baseUrl),
@@ -28,10 +32,10 @@ class AuthenticationInteractor {
isSelected: true
))
]);
return Right(AuthenticationUserViewState(user));
yield Right(AuthenticationUserSuccess(user));
} catch (e) {
logError('AuthenticationInteractor::execute(): $e');
return Left(AuthenticationUserFailure(e));
yield Left(AuthenticationUserFailure(e));
}
}
}
@@ -1,6 +1,7 @@
import 'package:core/core.dart';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:model/model.dart';
import 'package:model/oidc/request/oidc_request.dart';
import 'package:tmail_ui_user/features/login/domain/repository/authentication_oidc_repository.dart';
import 'package:tmail_ui_user/features/login/domain/state/check_oidc_is_available_state.dart';
@@ -9,14 +10,13 @@ class CheckOIDCIsAvailableInteractor {
CheckOIDCIsAvailableInteractor(this._oidcRepository);
Future<Either<Failure, Success>> execute(OIDCRequest oidcRequest) async {
Stream<Either<Failure, Success>> execute(OIDCRequest oidcRequest) async* {
try {
yield Right<Failure, Success>(CheckOIDCIsAvailableLoading());
final result = await _oidcRepository.checkOIDCIsAvailable(oidcRequest);
log('CheckOIDCIsAvailableInteractor::execute(): result: $result');
return Right<Failure, Success>(CheckOIDCIsAvailableSuccess(result));
yield Right<Failure, Success>(CheckOIDCIsAvailableSuccess(result));
} catch (e) {
log('CheckOIDCIsAvailableInteractor::execute(): ERROR: $e');
return Left<Failure, Success>(CheckOIDCIsAvailableFailure(e));
yield Left<Failure, Success>(CheckOIDCIsAvailableFailure(e));
}
}
}
@@ -10,18 +10,19 @@ class GetAuthenticationInfoInteractor {
GetAuthenticationInfoInteractor(this._oidcRepository);
Future<Either<Failure, Success>> execute() async {
Stream<Either<Failure, Success>> execute() async* {
try {
yield Right<Failure, Success>(GetAuthenticationInfoLoading());
final result = await _oidcRepository.getAuthenticationInfo();
log('GetAuthenticationInfoInteractor::execute(): result: $result');
if (result?.isNotEmpty == true) {
return Right<Failure, Success>(GetAuthenticationInfoSuccess());
yield Right<Failure, Success>(GetAuthenticationInfoSuccess());
} else {
return Left<Failure, Success>(GetAuthenticationInfoFailure(null));
yield Left<Failure, Success>(GetAuthenticationInfoFailure(null));
}
} catch (e) {
log('GetAuthenticationInfoInteractor::execute(): ERROR: $e');
return Left<Failure, Success>(GetAuthenticationInfoFailure(e));
yield Left<Failure, Success>(GetAuthenticationInfoFailure(e));
}
}
}
@@ -1,6 +1,8 @@
import 'package:core/core.dart';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:core/utils/app_logger.dart';
import 'package:dartz/dartz.dart';
import 'package:model/model.dart';
import 'package:model/oidc/response/oidc_response.dart';
import 'package:tmail_ui_user/features/login/domain/repository/authentication_oidc_repository.dart';
import 'package:tmail_ui_user/features/login/domain/state/get_oidc_configuration_state.dart';
@@ -9,15 +11,15 @@ class GetOIDCConfigurationInteractor {
GetOIDCConfigurationInteractor(this._oidcRepository);
Future<Either<Failure, Success>> execute(OIDCResponse oidcResponse) async {
Stream<Either<Failure, Success>> execute(OIDCResponse oidcResponse) async* {
try {
yield Right<Failure, Success>(GetOIDCConfigurationLoading());
final oidcConfiguration = await _oidcRepository.getOIDCConfiguration(oidcResponse);
log('GetOIDCConfigurationInteractor::execute(): oidcConfiguration: $oidcConfiguration');
await _oidcRepository.persistAuthorityOidc(oidcConfiguration.authority);
return Right<Failure, Success>(GetOIDCConfigurationSuccess(oidcConfiguration));
yield Right<Failure, Success>(GetOIDCConfigurationSuccess(oidcConfiguration));
} catch (e) {
log('GetOIDCConfigurationInteractor::execute(): ERROR: $e');
return Left<Failure, Success>(GetOIDCConfigurationFailure(e));
yield Left<Failure, Success>(GetOIDCConfigurationFailure(e));
}
}
}
@@ -0,0 +1,22 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:model/oidc/request/oidc_request.dart';
import 'package:tmail_ui_user/features/login/domain/repository/authentication_oidc_repository.dart';
import 'package:tmail_ui_user/features/login/domain/state/get_oidc_is_available_state.dart';
class GetOIDCIsAvailableInteractor {
final AuthenticationOIDCRepository _oidcRepository;
GetOIDCIsAvailableInteractor(this._oidcRepository);
Stream<Either<Failure, Success>> execute(OIDCRequest oidcRequest) async* {
try {
yield Right<Failure, Success>(GetOIDCIsAvailableLoading());
final result = await _oidcRepository.checkOIDCIsAvailable(oidcRequest);
yield Right<Failure, Success>(GetOIDCIsAvailableSuccess(result));
} catch (e) {
yield Left<Failure, Success>(GetOIDCIsAvailableFailure(e));
}
}
}
@@ -10,14 +10,14 @@ class GetStoredOidcConfigurationInteractor {
GetStoredOidcConfigurationInteractor(this._authenticationOIDCRepository);
Future<Either<Failure, Success>> execute() async {
Stream<Either<Failure, Success>> execute() async* {
try {
yield Right(GetStoredOidcConfigurationLoading());
final config = await _authenticationOIDCRepository.getStoredOidcConfiguration();
log('GetStoredOidcConfigurationInteractor::execute(): oidcConfiguration: $config');
return Right(GetStoredOidcConfigurationSuccess(config));
yield Right(GetStoredOidcConfigurationSuccess(config));
} catch (e) {
log('GetStoredOidcConfigurationInteractor::execute(): $e');
return Left(GetStoredOidcConfigurationFailure(e));
yield Left(GetStoredOidcConfigurationFailure(e));
}
}
}
@@ -21,11 +21,14 @@ class GetTokenOIDCInteractor {
GetTokenOIDCInteractor(this._credentialRepository, this.authenticationOIDCRepository, this._accountRepository);
Future<Either<Failure, Success>> execute(Uri baseUrl, OIDCConfiguration config) async {
Stream<Either<Failure, Success>> execute(Uri baseUrl, OIDCConfiguration config) async* {
try {
log('GetTokenOIDCInteractor::execute(): baseUrl: $baseUrl');
final tokenOIDC = await authenticationOIDCRepository
.getTokenOIDC(config.clientId, config.redirectUrl, config.discoveryUrl, config.scopes);
yield Right<Failure, Success>(GetTokenOIDCLoading());
final tokenOIDC = await authenticationOIDCRepository.getTokenOIDC(
config.clientId,
config.redirectUrl,
config.discoveryUrl,
config.scopes);
await Future.wait([
_credentialRepository.saveBaseUrl(baseUrl),
_accountRepository.setCurrentAccount(Account(
@@ -35,10 +38,10 @@ class GetTokenOIDCInteractor {
authenticationOIDCRepository.persistTokenOIDC(tokenOIDC),
authenticationOIDCRepository.persistAuthorityOidc(config.authority),
]);
return Right<Failure, Success>(GetTokenOIDCSuccess(tokenOIDC));
yield Right<Failure, Success>(GetTokenOIDCSuccess(tokenOIDC, config));
} catch (e) {
logError('GetTokenOIDCInteractor::execute(): $e');
return Left<Failure, Success>(GetTokenOIDCFailure(e));
yield Left<Failure, Success>(GetTokenOIDCFailure(e));
}
}
}