Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF-2387 Add starting page for mobile #3132

Merged
merged 14 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@
</intent-filter>
</activity>

<activity
android:name="com.linusu.flutter_web_auth_2.CallbackActivity"
android:exported="true">
<intent-filter android:label="flutter_web_auth_2">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="twakemail.mobile"
android:host="redirect" />
</intent-filter>
</activity>

<provider android:authorities="${applicationId}.firebaseinitprovider"
android:name="com.google.firebase.provider.FirebaseInitProvider"
android:exported="false"
Expand Down
48 changes: 48 additions & 0 deletions assets/images/ic_logo_twake_welcome.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions core/lib/presentation/resources/image_paths.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class ImagePaths {
String get icGoodSignature => _getImagePath('ic_good_signature.svg');
String get icBadSignature => _getImagePath('ic_bad_signature.svg');
String get icDeleteSelection => _getImagePath('ic_delete_selection.svg');
String get icLogoTwakeWelcome => _getImagePath('ic_logo_twake_welcome.svg');

String _getImagePath(String imageName) {
return AssetsPaths.images + imageName;
Expand Down
24 changes: 24 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PODS:
- AppAuth/Core
- better_open_file (0.0.1):
- Flutter
- CocoaAsyncSocket (7.6.5)
- connectivity_plus (0.0.1):
- Flutter
- ReachabilitySwift
Expand Down Expand Up @@ -116,6 +117,8 @@ PODS:
- Flutter
- flutter_secure_storage (6.0.0):
- Flutter
- flutter_web_auth_2 (3.0.0):
- Flutter
- GoogleDataTransport (9.3.0):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30910.0, >= 2.30908.0)
Expand Down Expand Up @@ -163,10 +166,17 @@ PODS:
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- patrol (0.0.1):
- CocoaAsyncSocket (~> 7.6)
- Flutter
- FlutterMacOS
- pdf_render (0.0.1):
- Flutter
- permission_handler_apple (9.1.1):
- Flutter
- photo_manager (2.0.0):
- Flutter
- FlutterMacOS
- pointer_interceptor_ios (0.0.1):
- Flutter
- printing (1.0.0):
Expand Down Expand Up @@ -214,10 +224,13 @@ DEPENDENCIES:
- flutter_local_notifications (from `.symlinks/plugins/flutter_local_notifications/ios`)
- flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`)
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
- flutter_web_auth_2 (from `.symlinks/plugins/flutter_web_auth_2/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- patrol (from `.symlinks/plugins/patrol/darwin`)
- pdf_render (from `.symlinks/plugins/pdf_render/ios`)
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
- photo_manager (from `.symlinks/plugins/photo_manager/ios`)
- pointer_interceptor_ios (from `.symlinks/plugins/pointer_interceptor_ios/ios`)
- printing (from `.symlinks/plugins/printing/ios`)
- receive_sharing_intent (from `.symlinks/plugins/receive_sharing_intent/ios`)
Expand All @@ -229,6 +242,7 @@ DEPENDENCIES:
SPEC REPOS:
trunk:
- AppAuth
- CocoaAsyncSocket
- DKImagePickerController
- DKPhotoGallery
- Firebase
Expand Down Expand Up @@ -290,14 +304,20 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/flutter_native_splash/ios"
flutter_secure_storage:
:path: ".symlinks/plugins/flutter_secure_storage/ios"
flutter_web_auth_2:
:path: ".symlinks/plugins/flutter_web_auth_2/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
patrol:
:path: ".symlinks/plugins/patrol/darwin"
pdf_render:
:path: ".symlinks/plugins/pdf_render/ios"
permission_handler_apple:
:path: ".symlinks/plugins/permission_handler_apple/ios"
photo_manager:
:path: ".symlinks/plugins/photo_manager/ios"
pointer_interceptor_ios:
:path: ".symlinks/plugins/pointer_interceptor_ios/ios"
printing:
Expand All @@ -317,6 +337,7 @@ SPEC CHECKSUMS:
app_settings: 017320c6a680cdc94c799949d95b84cb69389ebc
AppAuth: 182c5b88630569df5acb672720534756c29b3358
better_open_file: 03cf320415d4d3f46b6e00adc4a567d76c1a399d
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
connectivity_plus: 413a8857dd5d9f1c399a39130850d02fe0feaf7e
contacts_service: 849e1f84281804c8bfbec1b4c3eedcb23c5d3eca
device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed
Expand All @@ -342,6 +363,7 @@ SPEC CHECKSUMS:
flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743
flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef
flutter_secure_storage: 23fc622d89d073675f2eaa109381aefbcf5a49be
flutter_web_auth_2: 051cf9f5dc366f31b5dcc4e2952c2b954767be8a
GoogleDataTransport: 57c22343ab29bc686febbf7cbb13bad167c2d8fe
GoogleUtilities: 0759d1a57ebb953965c2dfe0ba4c82e95ccc2e34
libwebp: 1786c9f4ff8a279e4dac1e8f385004d5fc253009
Expand All @@ -350,8 +372,10 @@ SPEC CHECKSUMS:
OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c
package_info_plus: 115f4ad11e0698c8c1c5d8a689390df880f47e85
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
patrol: 0564cee315ff6c86fb802b3647db05cc2d3d0624
pdf_render: 0b4e1a615aab83ce88b26c57753049424908a755
permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6
photo_manager: ff695c7a1dd5bc379974953a2b5c0a293f7c4c8a
pointer_interceptor_ios: 9280618c0b2eeb80081a343924aa8ad756c21375
printing: 233e1b73bd1f4a05615548e9b5a324c98588640b
PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4
Expand Down
34 changes: 26 additions & 8 deletions lib/features/base/base_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,32 @@ abstract class BaseController extends GetxController
FirebaseCapability.fcmIdentifier.isSupported(session, accountId) && AppConfig.fcmAvailable;

void goToLogin() {
if (Get.currentRoute != AppRoutes.login) {
pushAndPopAll(
AppRoutes.login,
arguments: LoginArguments(
PlatformInfo.isMobile ? LoginFormType.dnsLookupForm : LoginFormType.none
)
);
if (PlatformInfo.isMobile) {
navigateToTwakeWelcomePage();
} else {
navigateToLoginPage();
}
}

void removeAllPageAndGoToLogin() {
if (PlatformInfo.isMobile) {
pushAndPopAll(AppRoutes.twakeWelcome);
} else {
navigateToLoginPage();
}
}

void navigateToTwakeWelcomePage() {
popAndPush(AppRoutes.twakeWelcome);
}

void navigateToLoginPage() {
if (Get.currentRoute == AppRoutes.login) {
return;
}
pushAndPopAll(
AppRoutes.login,
arguments: LoginArguments(LoginFormType.none));
hoangdat marked this conversation as resolved.
Show resolved Hide resolved
}

void logout(Session? session, AccountId? accountId) async {
Expand Down Expand Up @@ -460,7 +478,7 @@ abstract class BaseController extends GetxController
Future<void> clearDataAndGoToLoginPage() async {
log('$runtimeType::clearDataAndGoToLoginPage:');
await clearAllData();
goToLogin();
removeAllPageAndGoToLogin();
}

Future<void> clearAllData() async {
Expand Down
4 changes: 2 additions & 2 deletions lib/features/base/reloadable/reloadable_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class ReloadableController extends BaseController {
goToLogin();
} else if (failure is GetSessionFailure) {
logError('$runtimeType::handleFailureViewState():Failure = $failure');
_handleGetSessionFailure(failure.exception);
handleGetSessionFailure(failure.exception);
} else if (failure is UpdateAccountCacheFailure) {
logError('$runtimeType::handleFailureViewState():Failure = $failure');
_handleUpdateAccountCacheCompleted(
Expand Down Expand Up @@ -127,7 +127,7 @@ abstract class ReloadableController extends BaseController {
consumeState(_getSessionInteractor.execute());
}

void _handleGetSessionFailure(GetSessionFailure failure) {
void handleGetSessionFailure(GetSessionFailure failure) {
if (failure.exception is! BadCredentialsException) {
toastManager.showMessageFailure(failure);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ abstract class AuthenticationClientBase {

Future<bool> logoutOidc(TokenId tokenId, OIDCConfiguration config, OIDCDiscoveryResponse oidcRescovery);

Future<TokenOIDC> signInTwakeWorkplace(OIDCConfiguration oidcConfiguration);

Future<TokenOIDC> signUpTwakeWorkplace(OIDCConfiguration oidcConfiguration);

factory AuthenticationClientBase({String? tag}) => getAuthenticationClientImplementation(tag: tag);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import 'package:core/utils/app_logger.dart';
import 'package:flutter_appauth/flutter_appauth.dart';
import 'package:flutter_web_auth_2/flutter_web_auth_2.dart';
import 'package:get/get.dart';
import 'package:model/oidc/oidc_configuration.dart';
import 'package:model/oidc/response/oidc_discovery_response.dart';
Expand All @@ -9,6 +10,7 @@ import 'package:model/oidc/token_oidc.dart';
import 'package:tmail_ui_user/features/login/data/extensions/authentication_token_extension.dart';
import 'package:tmail_ui_user/features/login/data/extensions/token_response_extension.dart';
import 'package:tmail_ui_user/features/login/data/network/authentication_client/authentication_client_base.dart';
import 'package:tmail_ui_user/features/login/data/network/config/oidc_constant.dart';
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
import 'package:tmail_ui_user/features/login/domain/extensions/oidc_configuration_extensions.dart';

Expand Down Expand Up @@ -96,6 +98,32 @@ class AuthenticationClientMobile implements AuthenticationClientBase {
Future<String> getAuthenticationInfo() {
return Future.value('');
}

@override
Future<TokenOIDC> signInTwakeWorkplace(OIDCConfiguration oidcConfiguration) async {
final uri = await FlutterWebAuth2.authenticate(
url: oidcConfiguration.signInTWPUrl,
callbackUrlScheme: OIDCConstant.twakeWorkplaceUrlScheme,
options: const FlutterWebAuth2Options(
intentFlags: ephemeralIntentFlags,
),
);
log('AuthenticationClientMobile::signInTwakeWorkplace():Uri = $uri');
return TokenOIDC.fromUri(uri);
}

@override
Future<TokenOIDC> signUpTwakeWorkplace(OIDCConfiguration oidcConfiguration) async {
final uri = await FlutterWebAuth2.authenticate(
url: oidcConfiguration.signUpTWPUrl,
callbackUrlScheme: OIDCConstant.twakeWorkplaceUrlScheme,
options: const FlutterWebAuth2Options(
intentFlags: ephemeralIntentFlags,
),
);
log('AuthenticationClientMobile::signUpTwakeWorkplace():Uri = $uri');
return TokenOIDC.fromUri(uri);
}
}

AuthenticationClientBase getAuthenticationClientImplementation({String? tag}) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ class AuthenticationClientWeb implements AuthenticationClientBase {
throw CanNotAuthenticationInfoOnWeb();
}
}

@override
Future<TokenOIDC> signUpTwakeWorkplace(OIDCConfiguration oidcConfiguration) {
throw UnimplementedError();
}

@override
Future<TokenOIDC> signInTwakeWorkplace(OIDCConfiguration oidcConfiguration) {
throw UnimplementedError();
}
}

AuthenticationClientBase getAuthenticationClientImplementation({String? tag}) =>
Expand Down
7 changes: 6 additions & 1 deletion lib/features/login/data/network/config/oidc_constant.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import 'package:core/core.dart';
import 'package:core/utils/platform_info.dart';
import 'package:tmail_ui_user/main/utils/app_config.dart';

class OIDCConstant {
static String get mobileOidcClientId => 'teammail-mobile';
static List<String> get oidcScope => ['openid', 'profile', 'email', 'offline_access'];
static const keyAuthorityOidc = 'KEY_AUTHORITY_OIDC';
static const authResponseKey = "auth_info";
static const String twakeWorkplaceUrlScheme = 'twakemail.mobile';
static const String twakeWorkplaceRedirectUrl = '$twakeWorkplaceUrlScheme://redirect';
static const String appParameter = 'tmail';
static const String postRegisteredRedirectUrlPathParams = 'post_registered_redirect_url';
static const String postLoginRedirectUrlPathParams = 'post_login_redirect_url';

static String get clientId => PlatformInfo.isWeb ? AppConfig.webOidcClientId : mobileOidcClientId;
}
Loading
Loading