-
Notifications
You must be signed in to change notification settings - Fork 12
Create a login page that redirects to the browser: #1237 #1336
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
Open
Shafaatul-Islam
wants to merge
36
commits into
master
Choose a base branch
from
feature/1237-login-page-that-redirects-to-the-browser
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
4aa8159
Ajout du package et des fichiers concernant la page login
Shafaatul-Islam 47be59e
Ajout des variables dans router pour login
Shafaatul-Islam 63275e8
premier visuel complete pour login
Shafaatul-Islam 50ee34f
meilleur respect de l'issue, vue refaite
Shafaatul-Islam e6b875d
Page login complete
Shafaatul-Islam 868ea8b
Page login complete
Shafaatul-Islam 98ace77
Merge branch 'master' into feature/1237-login-page-that-redirects-to-…
Shafaatul-Islam 9f4f796
version anglais/francais
Shafaatul-Islam a36967d
ajout dans localization en et fr
Shafaatul-Islam 7c01397
Merge branch 'master' into feature/1237-login-page-that-redirects-to-…
Shafaatul-Islam b5ad9ae
changement du texte de la version anglaise
Shafaatul-Islam 88268c7
tests + changement nom variable + enlevement code inutile
Shafaatul-Islam f15d4fb
[BOT] Applying version.
Shafaatul-Islam 1839528
pubspec new version
Shafaatul-Islam 6aac832
pull 5.9.2
Shafaatul-Islam 1dc3194
changement du logo dans la page de login
Shafaatul-Islam 848b331
[BOT] Applying format.
Shafaatul-Islam 3cbcc59
ajout des icones aux boutons
Shafaatul-Islam cd98379
Merge branch 'feature/1237-login-page-that-redirects-to-the-browser' …
Shafaatul-Islam 7db1803
ajout des icones aux boutons
Shafaatul-Islam 84e9925
Merge branch 'master' into feature/1237-login-page-that-redirects-to-…
Shafaatul-Islam 11f55f9
fix workflow + debut fix test
Shafaatul-Islam fad1eed
mouvement des tests de startup a login
Shafaatul-Islam 525f249
[BOT] Applying format.
Shafaatul-Islam a851352
ajout du gradient et espacement entre les boutons
Shafaatul-Islam c734f72
Merge branch 'feature/1237-login-page-that-redirects-to-the-browser' …
Shafaatul-Islam d38495d
[BOT] Applying format.
Shafaatul-Islam 24a32ff
merge avec V5
Shafaatul-Islam 70e5b87
deletion of the linux and macos folders+changes after mergin with V5+…
Shafaatul-Islam 2a84bf3
[BOT] Applying format.
Shafaatul-Islam 9e81d15
removing useless imports in router.dart
Shafaatul-Islam 245a309
indentation in login_viewmodel and login_viewmodel_test
Shafaatul-Islam 94b29c3
Merge branch 'feature/1237-login-page-that-redirects-to-the-browser' …
Shafaatul-Islam 3f0f79d
deletion of redundant constants in router_paths + cleaner loading man…
Shafaatul-Islam 8fda8c2
correct exception pattern that does not catch locally in login_viewmodel
Shafaatul-Islam c8361fd
change in login to better suit dark mode + name change of variable lo…
Shafaatul-Islam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // | ||
|
|
||
| // Package imports: | ||
| import 'package:fluttertoast/fluttertoast.dart'; | ||
| import 'package:msal_auth/msal_auth.dart'; | ||
| import 'package:stacked/stacked.dart'; | ||
|
|
||
| // Project imports: | ||
| import 'package:notredame/data/repositories/settings_repository.dart'; | ||
| import 'package:notredame/data/services/analytics_service.dart'; | ||
| import 'package:notredame/data/services/auth_service.dart'; | ||
| import 'package:notredame/data/services/navigation_service.dart'; | ||
| import 'package:notredame/domain/constants/router_paths.dart'; | ||
| import 'package:notredame/l10n/app_localizations.dart'; | ||
| import 'package:notredame/locator.dart'; | ||
|
|
||
| class LoginViewModel extends BaseViewModel { | ||
| /// Localization class of the application. | ||
| final AppIntl _appIntl; | ||
|
|
||
| final SettingsRepository _settingsManager = locator<SettingsRepository>(); | ||
| final AuthService _authService = locator<AuthService>(); | ||
| final NavigationService navigationService = locator<NavigationService>(); | ||
| final AnalyticsService _analyticsService = locator<AnalyticsService>(); | ||
|
|
||
| LoginViewModel({required AppIntl intl}) : _appIntl = intl; | ||
|
|
||
| Future authenticate() async { | ||
| AuthenticationResult? token; | ||
| token = (await _authService.acquireToken()).$1; | ||
|
|
||
| if (token == null) { | ||
| Fluttertoast.showToast(msg: _appIntl.login_viewmodel_acquire_token_fail); | ||
| await _analyticsService.logError('LoginViewmodel', 'Failed to acquire token due to cancellation'); | ||
| return; | ||
| } | ||
|
|
||
| _settingsManager.isLoggedIn = true; | ||
| navigationService.pushNamedAndRemoveUntil(RouterPaths.startup); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| // Flutter imports: | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| // Package imports: | ||
| import 'package:flutter_svg/flutter_svg.dart'; | ||
| import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | ||
| import 'package:stacked/stacked.dart'; | ||
|
|
||
| // Project imports: | ||
| import 'package:notredame/domain/constants/router_paths.dart'; | ||
| import 'package:notredame/l10n/app_localizations.dart'; | ||
| import 'package:notredame/ui/core/themes/app_palette.dart'; | ||
| import 'package:notredame/ui/login/view_model/login_viewmodel.dart'; | ||
|
|
||
| class LoginView extends StatefulWidget { | ||
| const LoginView({super.key}); | ||
|
|
||
| @override | ||
| State<LoginView> createState() => _LoginViewState(); | ||
| } | ||
|
|
||
| class _LoginViewState extends State<LoginView> { | ||
| bool _isLoading = false; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return ViewModelBuilder<LoginViewModel>.reactive( | ||
| viewModelBuilder: () => LoginViewModel(intl: AppIntl.of(context)!), | ||
| builder: (context, model, child) => Scaffold( | ||
| body: Container( | ||
| width: double.infinity, | ||
| height: double.infinity, | ||
| decoration: const BoxDecoration( | ||
| gradient: LinearGradient( | ||
| begin: Alignment.topCenter, | ||
| end: Alignment.bottomCenter, | ||
| colors: [AppPalette.etsLightRed, AppPalette.etsDarkRed], | ||
| ), | ||
| ), | ||
| child: Center( | ||
| child: Padding( | ||
| padding: const EdgeInsets.all(30.0), | ||
| child: Column( | ||
| mainAxisAlignment: MainAxisAlignment.center, | ||
| crossAxisAlignment: CrossAxisAlignment.center, | ||
| children: [ | ||
| Padding( | ||
| padding: const EdgeInsets.only(bottom: 20), | ||
| child: Hero( | ||
| tag: 'ets_logo', | ||
| child: SvgPicture.asset( | ||
| "assets/images/ets_white_logo.svg", | ||
| excludeFromSemantics: true, | ||
| width: 90, | ||
| height: 90, | ||
| colorFilter: ColorFilter.mode(AppPalette.grey.white, BlendMode.srcIn), | ||
| ), | ||
| ), | ||
| ), | ||
| Padding( | ||
| padding: const EdgeInsets.only(bottom: 30), | ||
| child: Text( | ||
| AppIntl.of(context)!.login_startup_title, | ||
| style: TextStyle(fontWeight: FontWeight.normal, fontSize: 18, color: AppPalette.grey.white), | ||
| ), | ||
| ), | ||
| Padding( | ||
| padding: const EdgeInsets.only(bottom: 40), | ||
| child: Stack( | ||
| alignment: Alignment.centerRight, | ||
| children: [ | ||
| ElevatedButton.icon( | ||
| onPressed: () async { | ||
| setState(() => _isLoading = true); | ||
| await model.authenticate(); | ||
| setState(() => _isLoading = false); | ||
| }, | ||
| icon: const FaIcon(FontAwesomeIcons.lockOpen, color: Colors.white), | ||
| label: Text( | ||
| AppIntl.of(context)!.login_action_sign_in, | ||
| style: TextStyle(color: AppPalette.grey.white, fontSize: 16, fontWeight: FontWeight.bold), | ||
| ), | ||
| style: ElevatedButton.styleFrom( | ||
| backgroundColor: AppPalette.grey.black, | ||
| shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)), | ||
| minimumSize: const Size(300, 50), | ||
| ), | ||
| ), | ||
| if (_isLoading) ...[ | ||
| CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(AppPalette.grey.white)), | ||
| ], | ||
| ], | ||
| ), | ||
| ), | ||
| Padding( | ||
| padding: const EdgeInsets.only(bottom: 20), | ||
| child: ElevatedButton.icon( | ||
| onPressed: () { | ||
| model.navigationService.pushNamed(RouterPaths.faq); | ||
| }, | ||
| icon: const FaIcon(FontAwesomeIcons.question, color: Colors.white), | ||
| label: Text( | ||
| "FAQ", | ||
| style: TextStyle(color: AppPalette.grey.white, fontSize: 13, fontWeight: FontWeight.bold), | ||
| ), | ||
| style: ElevatedButton.styleFrom( | ||
| backgroundColor: AppPalette.grey.darkGrey, | ||
| shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)), | ||
| ), | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Package imports: | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:mockito/mockito.dart'; | ||
|
|
||
| // Project imports: | ||
| import 'package:notredame/data/repositories/settings_repository.dart'; | ||
| import 'package:notredame/data/repositories/user_repository.dart'; | ||
| import 'package:notredame/data/services/analytics_service.dart'; | ||
| import 'package:notredame/data/services/auth_service.dart'; | ||
| import 'package:notredame/data/services/navigation_service.dart'; | ||
| import 'package:notredame/data/services/networking_service.dart'; | ||
| import 'package:notredame/domain/constants/router_paths.dart'; | ||
| import 'package:notredame/l10n/app_localizations.dart'; | ||
| import 'package:notredame/ui/login/view_model/login_viewmodel.dart'; | ||
| import '../../../data/mocks/repositories/settings_repository_mock.dart'; | ||
| import '../../../data/mocks/services/auth_service_mock.dart'; | ||
| import '../../../data/mocks/services/navigation_service_mock.dart'; | ||
| import '../../../data/mocks/services/networking_service_mock.dart'; | ||
| import '../../../helpers.dart'; | ||
|
|
||
| void main() { | ||
| late NavigationServiceMock navigationServiceMock; | ||
| late SettingsRepositoryMock settingsRepositoryMock; | ||
| late NetworkingServiceMock networkingServiceMock; | ||
| late AuthServiceMock authServiceMock; | ||
|
|
||
| late LoginViewModel viewModel; | ||
| late AppIntl appIntl; | ||
|
|
||
| group('LoginViewModel - ', () { | ||
| setUp(() async { | ||
| setupAnalyticsServiceMock(); | ||
| navigationServiceMock = setupNavigationServiceMock(); | ||
| settingsRepositoryMock = setupSettingsRepositoryMock(); | ||
| networkingServiceMock = setupNetworkingServiceMock(); | ||
| authServiceMock = setupAuthServiceMock(); | ||
|
|
||
| appIntl = await setupAppIntl(); | ||
| viewModel = LoginViewModel(intl: appIntl); | ||
| }); | ||
|
|
||
| tearDown(() { | ||
| unregister<AuthService>(); | ||
| unregister<NetworkingService>(); | ||
| unregister<UserRepository>(); | ||
| unregister<SettingsRepository>(); | ||
| unregister<NavigationService>(); | ||
| unregister<AnalyticsService>(); | ||
| }); | ||
|
|
||
| test('silent sign in failed redirect to startup', () async { | ||
| NetworkingServiceMock.stubHasConnectivity(networkingServiceMock); | ||
| SettingsRepositoryMock.stubIsLocaleDefined(settingsRepositoryMock, toReturn: true); | ||
| AuthServiceMock.stubCreatePublicClientApplication(authServiceMock); | ||
| AuthServiceMock.stubAcquireTokenSilent(authServiceMock, success: false); | ||
| AuthServiceMock.stubAcquireToken(authServiceMock, success: true); | ||
|
|
||
| await viewModel.authenticate(); | ||
|
|
||
| verify(authServiceMock.acquireToken()).called(1); | ||
| verify(navigationServiceMock.pushNamedAndRemoveUntil(RouterPaths.startup)); | ||
| verify(settingsRepositoryMock.isLoggedIn = true).called(1); | ||
| }); | ||
| }); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.