Skip to content

Commit

Permalink
Feature/forgot password link (#763)
Browse files Browse the repository at this point in the history
* Add "forgot password link" to login view

* Move "forgot password" to bottom right of password input

* [BOT] Bump version from 4.20.0+1 to 4.21.0+1

* [BOT] Applying format.

* SizedBox heights and padding changes

* Fix to avoid merge conflict

* [BOT] Bump version from 4.21.0+1 to 4.22.0+1

* [BOT] Applying format.

* [BOT] Bump version from 4.21.0+1 to 4.22.0+1

* Change url launch method

* [BOT] Applying format.

* Put launchInBrowser method in service

* [BOT] Bump version from 4.21.5+1 to 4.22.0+1

* Put launchInBrowser method in launch_url_service and delete launch_url_in_browser_service

* [BOT] Applying format.

* Add launchUrlService to WebLinkCardViewModel test

* Refactor signets url location

* [BOT] Applying format.

* Reset work on web_link_card_viewmodel_test

* Reset work on web_link_card_viewmodel_test

* [BOT] Applying version.

* Fix web_link_card_test

* Just a TEST ...

* Fix another test

* Fix test

* Use settingsManager.themeMode

* [BOT] Applying format.

* Fix themeMode

* [BOT] Applying format.

* [BOT] Applying version.

* Brigthness for theme

* Remove unused imports

* Update lib/core/constants/urls.dart

Co-authored-by: Samuel Montambault <[email protected]>

* Rename signetsForgottenPassword

---------

Co-authored-by: J01716 <[email protected]>
Co-authored-by: Samuel Montambault <[email protected]>
Co-authored-by: Camille Brulotte <[email protected]>
Co-authored-by: camillebrulotte <[email protected]>
Co-authored-by: Camille Brulotte <[email protected]>
Co-authored-by: Antoine Martineau <[email protected]>
  • Loading branch information
7 people authored Sep 9, 2023
1 parent 1472dcc commit df1f238
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 65 deletions.
1 change: 1 addition & 0 deletions l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
"progress_bar_suffix": "days",

"in_app_review_title": "Rate us!",
"forgot_password": "Forgot your password?",
"need_help_contact_us": "Need help? Contact us!",
"universal_code_example": "Ex: AB12345",
"my_tickets": "My tickets",
Expand Down
3 changes: 2 additions & 1 deletion l10n/intl_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@
},
"progress_bar_suffix": "jours",

"in_app_review_title": "Évaluez-nous!",
"in_app_review_title": "Évaluez-nous!",
"forgot_password": "Mot de passe oublié?",
"need_help_contact_us": "Besoin d'aide? Contactez-nous!",
"universal_code_example": "Ex: AB12345",
"my_tickets": "Mes billets",
Expand Down
2 changes: 2 additions & 0 deletions lib/core/constants/urls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ class Urls {
static const String clubYoutube =
"https://youtube.com/channel/UCiSzzfW1bVbE_0KcEZO52ew";
static const String clubDiscord = "https://discord.gg/adMkWptn6Y";
static const String signetsForgottenPassword =
"https://signets-ens.etsmtl.ca/Public/MotDePassePerdu.aspx";
}
13 changes: 8 additions & 5 deletions lib/core/managers/settings_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ class SettingsManager with ChangeNotifier {

/// Get ThemeMode
ThemeMode get themeMode {
_preferencesService.getString(PreferencesFlag.theme).then((value) {
if (value != null) {
_themeMode = ThemeMode.values.firstWhere((e) => e.toString() == value);
}
});
_preferencesService.getString(PreferencesFlag.theme).then((value) => {
if (value != null)
{
_themeMode =
ThemeMode.values.firstWhere((e) => e.toString() == value)
}
});

return _themeMode;
}

Expand Down
62 changes: 59 additions & 3 deletions lib/core/services/launch_url_service.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,70 @@
// FLUTTER / DART / THIRD-PARTIES
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter/material.dart';
import 'package:flutter_custom_tabs/flutter_custom_tabs.dart' as custom_tabs;
import 'package:url_launcher/url_launcher.dart' as url_launch;

// Managers
import 'package:notredame/core/managers/settings_manager.dart';

// UTILS
import 'package:notredame/ui/utils/app_theme.dart';

// OTHER
import 'package:notredame/locator.dart';

class LaunchUrlService {
final SettingsManager settingsManager = locator<SettingsManager>();

Future<bool> canLaunch(String url) async {
final uri = Uri.parse(url);
return canLaunchUrl(uri);
return url_launch.canLaunchUrl(uri);
}

Future<bool> launch(String url) async {
final uri = Uri.parse(url);
return launchUrl(uri);
return url_launch.launchUrl(uri);
}

Future<void> launchInBrowser(String url, Brightness brightness) async {
await custom_tabs.launch(
url,
customTabsOption: custom_tabs.CustomTabsOption(
toolbarColor: brightness == Brightness.light
? AppTheme.etsLightRed
: AppTheme.etsDarkRed,
enableDefaultShare: false,
enableUrlBarHiding: true,
showPageTitle: true,
animation: custom_tabs.CustomTabsSystemAnimation.slideIn(),
extraCustomTabs: const <String>[
// ref. https://play.google.com/store/apps/details?id=org.mozilla.firefox
'org.mozilla.firefox',
// https://play.google.com/store/apps/details?id=com.brave.browser
'com.brave.browser',
// https://play.google.com/store/apps/details?id=com.opera.browser
'com.opera.browser',
'com.opera.mini.native',
'com.opera.gx',
// https://play.google.com/store/apps/details?id=com.sec.android.app.sbrowser
'com.sec.android.app.sbrowser',
// ref. https://play.google.com/store/apps/details?id=com.microsoft.emmx
'com.microsoft.emmx',
// https://play.google.com/store/apps/details?id=com.UCMobile.intl
'com.UCMobile.intl',
],
),
safariVCOption: custom_tabs.SafariViewControllerOption(
preferredBarTintColor: brightness == Brightness.light
? AppTheme.etsLightRed
: AppTheme.etsDarkRed,
preferredControlTintColor: brightness == Brightness.light
? AppTheme.lightThemeBackground
: AppTheme.darkThemeBackground,
barCollapsingEnabled: true,
entersReaderIfAvailable: false,
dismissButtonStyle:
custom_tabs.SafariViewControllerDismissButtonStyle.close,
),
);
}
}
50 changes: 7 additions & 43 deletions lib/core/viewmodels/web_link_card_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// FLUTTER / DART / THIRD-PARTIES
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:notredame/core/models/quick_link.dart';
import 'package:stacked/stacked.dart';
import 'package:flutter_custom_tabs/flutter_custom_tabs.dart';

// CONSTANTS
import 'package:notredame/core/constants/router_paths.dart';

// SERVICES
import 'package:notredame/core/services/analytics_service.dart';
import 'package:notredame/core/services/navigation_service.dart';

// UTILS
import 'package:notredame/ui/utils/app_theme.dart';
import 'package:notredame/core/services/launch_url_service.dart';

// OTHER
import 'package:notredame/locator.dart';
Expand All @@ -22,59 +21,24 @@ class WebLinkCardViewModel extends BaseViewModel {

final AnalyticsService _analyticsService = locator<AnalyticsService>();

final LaunchUrlService _launchUrlService = locator<LaunchUrlService>();

/// used to open a website or the security view
Future<void> onLinkClicked(QuickLink link) async {
Future<void> onLinkClicked(QuickLink link, Brightness brightness) async {
_analyticsService.logEvent("QuickLink", "QuickLink clicked: ${link.name}");

if (link.link == 'security') {
_navigationService.pushNamed(RouterPaths.security);
} else {
try {
await launchInBrowser(link.link);
await _launchUrlService.launchInBrowser(link.link, brightness);
} catch (error) {
// An exception is thrown if browser app is not installed on Android device.
await launchWebView(link);
}
}
}

/// used to open a website inside AndroidChromeCustomTabs or SFSafariViewController
Future<void> launchInBrowser(String url) async {
await launch(
url,
customTabsOption: CustomTabsOption(
toolbarColor: AppTheme.etsLightRed,
enableDefaultShare: false,
enableUrlBarHiding: true,
showPageTitle: true,
animation: CustomTabsSystemAnimation.slideIn(),
extraCustomTabs: const <String>[
// ref. https://play.google.com/store/apps/details?id=org.mozilla.firefox
'org.mozilla.firefox',
// https://play.google.com/store/apps/details?id=com.brave.browser
'com.brave.browser',
// https://play.google.com/store/apps/details?id=com.opera.browser
'com.opera.browser',
'com.opera.mini.native',
'com.opera.gx',
// https://play.google.com/store/apps/details?id=com.sec.android.app.sbrowser
'com.sec.android.app.sbrowser',
// ref. https://play.google.com/store/apps/details?id=com.microsoft.emmx
'com.microsoft.emmx',
// https://play.google.com/store/apps/details?id=com.UCMobile.intl
'com.UCMobile.intl',
],
),
safariVCOption: const SafariViewControllerOption(
preferredBarTintColor: AppTheme.etsLightRed,
preferredControlTintColor: AppTheme.lightThemeBackground,
barCollapsingEnabled: true,
entersReaderIfAvailable: false,
dismissButtonStyle: SafariViewControllerDismissButtonStyle.close,
),
);
}

Future<void> launchWebView(QuickLink link) async {
_navigationService.pushNamed(RouterPaths.webView, arguments: link);
}
Expand Down
30 changes: 25 additions & 5 deletions lib/ui/views/login_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'package:notredame/ui/widgets/password_text_field.dart';

// CONSTANTS
import 'package:notredame/core/constants/app_info.dart';
import 'package:notredame/core/constants/urls.dart';

// OTHER
import 'package:notredame/ui/utils/app_theme.dart';
Expand Down Expand Up @@ -71,7 +72,7 @@ class _LoginViewState extends State<LoginView> {
child: Column(
children: [
const SizedBox(
height: 60,
height: 48,
),
Hero(
tag: 'ets_logo',
Expand All @@ -86,7 +87,7 @@ class _LoginViewState extends State<LoginView> {
: AppTheme.etsLightRed,
)),
const SizedBox(
height: 60,
height: 48,
),
TextFormField(
autofillHints: const [AutofillHints.username],
Expand Down Expand Up @@ -138,13 +139,32 @@ class _LoginViewState extends State<LoginView> {
],
),
const SizedBox(
height: 20,
height: 16,
),
PasswordFormField(
validator: model.validatePassword,
onEditionComplete: _focusNode.nextFocus),
Align(
alignment: Alignment.topRight,
child: Padding(
padding: const EdgeInsets.only(top: 4),
child: InkWell(
child: Text(
AppIntl.of(context).forgot_password,
style: const TextStyle(
decoration: TextDecoration.underline,
color: Colors.white),
),
onTap: () {
_launchUrlService.launchInBrowser(
Urls.signetsForgottenPassword,
Theme.of(context).brightness);
},
),
),
),
const SizedBox(
height: 30.0,
height: 24,
),
SizedBox(
width: double.infinity,
Expand Down Expand Up @@ -184,7 +204,7 @@ class _LoginViewState extends State<LoginView> {
),
Center(
child: Padding(
padding: const EdgeInsets.only(top: 30),
padding: const EdgeInsets.only(top: 24),
child: InkWell(
child: Text(
AppIntl.of(context).need_help_contact_us,
Expand Down
2 changes: 0 additions & 2 deletions lib/ui/views/quick_links_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import 'package:notredame/core/viewmodels/quick_links_viewmodel.dart';
import 'package:notredame/ui/widgets/base_scaffold.dart';
import 'package:notredame/ui/widgets/web_link_card.dart';

// OTHER

class QuickLinksView extends StatefulWidget {
@override
_QuickLinksViewState createState() => _QuickLinksViewState();
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/widgets/web_link_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class WebLinkCard extends StatelessWidget {
child: Card(
elevation: 4.0,
child: InkWell(
onTap: () => model.onLinkClicked(_links),
onTap: () =>
model.onLinkClicked(_links, Theme.of(context).brightness),
splashColor: AppTheme.etsLightRed.withAlpha(50),
child: Padding(
padding: const EdgeInsets.all(8.0),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: The 4th generation of ÉTSMobile, the main gateway between the Éco
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 4.24.0+1
version: 4.25.0+1

environment:
sdk: ">=2.10.0 <3.0.0"
Expand Down
3 changes: 3 additions & 0 deletions test/ui/views/quick_links_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:notredame/core/constants/quick_links.dart';

// SERVICES
import 'package:notredame/core/services/networking_service.dart';
import 'package:notredame/core/services/launch_url_service.dart';

// VIEW
import 'package:notredame/ui/views/quick_links_view.dart';
Expand All @@ -32,13 +33,15 @@ void main() {
setupAnalyticsServiceMock();
setupInternalInfoServiceMock();
setupNetworkingServiceMock();
setupLaunchUrlServiceMock();
});

tearDown(() {
unregister<NavigationServiceMock>();
unregister<AnalyticsServiceMock>();
unregister<InternalInfoServiceMock>();
unregister<NetworkingService>();
unregister<LaunchUrlService>();
});

group('UI - ', () {
Expand Down
4 changes: 4 additions & 0 deletions test/ui/widgets/web_link_card_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:notredame/core/models/quick_link.dart';
import 'package:notredame/core/services/navigation_service.dart';
import 'package:notredame/core/services/analytics_service.dart';
import 'package:notredame/core/services/internal_info_service.dart';
import 'package:notredame/core/services/launch_url_service.dart';

// WIDGETS
import 'package:notredame/ui/widgets/web_link_card.dart';
Expand All @@ -20,17 +21,20 @@ final _quickLink =

void main() {
AnalyticsService analyticsService;
LaunchUrlService launchUrlService;

group('WebLinkCard - ', () {
setUp(() {
analyticsService = setupAnalyticsServiceMock();
launchUrlService = setupLaunchUrlServiceMock();
setupInternalInfoServiceMock();
setupNavigationServiceMock();
});

tearDown(() {
unregister<NavigationService>();
clearInteractions(analyticsService);
clearInteractions(launchUrlService);
unregister<AnalyticsService>();
unregister<InternalInfoService>();
});
Expand Down
Loading

0 comments on commit df1f238

Please sign in to comment.