From 36f46fa3d3ebba38fea16ce6bb3379fb5a810518 Mon Sep 17 00:00:00 2001 From: Adrian Margineanu Date: Fri, 11 Sep 2020 15:08:06 +0300 Subject: [PATCH 1/9] Add a password text field in delete account dialog --- .../view/edit_profile_page.dart | 72 +++++++++++-------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/lib/authentication/view/edit_profile_page.dart b/lib/authentication/view/edit_profile_page.dart index e11d0d31b..8dd92607f 100644 --- a/lib/authentication/view/edit_profile_page.dart +++ b/lib/authentication/view/edit_profile_page.dart @@ -140,29 +140,43 @@ class _EditProfilePageState extends State { Navigator.pushReplacementNamed(context, Routes.login); } - AppDialog _deletionConfirmationDialog(BuildContext context) => AppDialog( - icon: Icon(Icons.warning, color: Colors.red), - title: S.of(context).actionDeleteAccount, - message: S.of(context).messageDeleteAccount + - ' ' + - S.of(context).messageCannotBeUndone, - actions: [ - AppButton( - key: ValueKey('delete_account_button'), - text: S.of(context).actionDeleteAccount.toUpperCase(), - color: Colors.red, - width: 130, - onTap: () async { - AuthProvider authProvider = - Provider.of(context, listen: false); - bool res = await authProvider.delete(context: context); - if (res) { - _signOut(context); - } - }, - ) - ], - ); + AppDialog _deletionConfirmationDialog(BuildContext context) { + final passwordController = TextEditingController(); + _addControllerListener(passwordController); + return AppDialog( + icon: Icon(Icons.warning, color: Colors.red), + title: S.of(context).actionDeleteAccount, + message: S.of(context).messageDeleteAccount + + ' ' + + S.of(context).messageCannotBeUndone, + content: [ + TextFormField( + decoration: InputDecoration( + labelText: S.of(context).labelPassword, + hintText: S.of(context).hintPassword, + ), + obscureText: true, + controller: passwordController, + ) + ], + actions: [ + AppButton( + key: ValueKey('delete_account_button'), + text: S.of(context).actionDeleteAccount.toUpperCase(), + color: Colors.red, + width: 130, + onTap: () async { + AuthProvider authProvider = + Provider.of(context, listen: false); + bool res = await authProvider.delete(context: context); + if (res) { + _signOut(context); + } + }, + ) + ], + ); + } @override Widget build(BuildContext context) { @@ -178,17 +192,17 @@ class _EditProfilePageState extends State { S.of(context).labelFirstName: firstNameController.text, S.of(context).labelLastName: lastNameController.text, filter.localizedLevelNames[0][LocaleProvider.localeString]: - nodes[1].name != null ? nodes[1].name: null, + nodes[1].name != null ? nodes[1].name : null, filter.localizedLevelNames[1][LocaleProvider.localeString]: - nodes[2].name != null ? nodes[2].name: null, + nodes[2].name != null ? nodes[2].name : null, filter.localizedLevelNames[2][LocaleProvider.localeString]: - nodes[3].name != null ? nodes[3].name: null, + nodes[3].name != null ? nodes[3].name : null, filter.localizedLevelNames[3][LocaleProvider.localeString]: - nodes[4].name != null ? nodes[4].name: null, + nodes[4].name != null ? nodes[4].name : null, filter.localizedLevelNames[4][LocaleProvider.localeString]: - nodes[5].name != null ? nodes[5].name: null, + nodes[5].name != null ? nodes[5].name : null, filter.localizedLevelNames[5][LocaleProvider.localeString]: - nodes[6].name != null ? nodes[6].name: null, + nodes[6].name != null ? nodes[6].name : null, }, context: context, ); From bb4b996d75fb57edd654d0d3104e49b846a318c9 Mon Sep 17 00:00:00 2001 From: Adrian Margineanu Date: Sat, 19 Sep 2020 19:36:37 +0300 Subject: [PATCH 2/9] Add password validation when delete account --- lib/authentication/service/auth_provider.dart | 7 +++- .../view/edit_profile_page.dart | 38 ++++++++++++------- lib/generated/l10n.dart | 1 - 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/lib/authentication/service/auth_provider.dart b/lib/authentication/service/auth_provider.dart index db8ae16dc..242a31caf 100644 --- a/lib/authentication/service/auth_provider.dart +++ b/lib/authentication/service/auth_provider.dart @@ -199,6 +199,11 @@ class AuthProvider with ChangeNotifier { }).then((_) => true); } + Future verifyPassword({String password, BuildContext context}) async { + return await signIn( + email: _firebaseUser.email, password: password, context: context); + } + Future signIn( {String email, String password, BuildContext context}) async { if (email == null || email == '') { @@ -433,7 +438,7 @@ class AuthProvider with ChangeNotifier { var userUpdateInfo = UserUpdateInfo(); userUpdateInfo.displayName = firstName + ' ' + lastName; await _firebaseUser.updateProfile(userUpdateInfo); - + notifyListeners(); return true; } catch (e) { diff --git a/lib/authentication/view/edit_profile_page.dart b/lib/authentication/view/edit_profile_page.dart index 1953c4181..015dfe6c3 100644 --- a/lib/authentication/view/edit_profile_page.dart +++ b/lib/authentication/view/edit_profile_page.dart @@ -28,7 +28,7 @@ class _EditProfilePageState extends State { AppDialog _deletionConfirmationDialog(BuildContext context) { final passwordController = TextEditingController(); - _addControllerListener(passwordController); + final passwordKey = GlobalKey(); return AppDialog( icon: Icon(Icons.warning, color: Colors.red), title: S.of(context).actionDeleteAccount, @@ -36,13 +36,21 @@ class _EditProfilePageState extends State { ' ' + S.of(context).messageCannotBeUndone, content: [ - TextFormField( - decoration: InputDecoration( - labelText: S.of(context).labelPassword, - hintText: S.of(context).hintPassword, - ), - obscureText: true, - controller: passwordController, + Form( + key: passwordKey, + child: TextFormField( + decoration: InputDecoration( + labelText: S.of(context).labelPassword, + hintText: S.of(context).hintPassword, + ), + obscureText: true, + controller: passwordController, + validator: (value) { + if (value.isEmpty || value == null) { + return S.of(context).errorNoPassword; + } + return null; + }), ) ], actions: [ @@ -52,11 +60,15 @@ class _EditProfilePageState extends State { color: Colors.red, width: 130, onTap: () async { - AuthProvider authProvider = - Provider.of(context, listen: false); - bool res = await authProvider.delete(context: context); - if (res) { - _signOut(context); + if(passwordKey.currentState.validate()) { + AuthProvider authProvider = + Provider.of(context, listen: false); + if (await authProvider.verifyPassword( + password: passwordController.text, context: context)) { + if (await authProvider.delete(context: context)) { + Utils.signOut(context); + } + } } }, ) diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 87b6e5abb..7b6ef405d 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -1,7 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; - import 'intl/messages_all.dart'; // ************************************************************************** From 8452ea4bba51e58750468f0d212fd975986fb6e6 Mon Sep 17 00:00:00 2001 From: Adrian Margineanu Date: Sat, 19 Sep 2020 19:37:23 +0300 Subject: [PATCH 3/9] Fix press back after sign out --- lib/resources/utils.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/resources/utils.dart b/lib/resources/utils.dart index 1d18ec0c0..318acd76b 100644 --- a/lib/resources/utils.dart +++ b/lib/resources/utils.dart @@ -23,6 +23,7 @@ class Utils { AuthProvider authProvider = Provider.of(context, listen: false); authProvider.signOut(context); - Navigator.pushReplacementNamed(context, Routes.login); + Navigator.popUntil(context, (route) => !route.isFirst); + Navigator.pushNamed(context, Routes.login); } } From c0ee320bd7fa24e552f4522662fe2e2f9622c49f Mon Sep 17 00:00:00 2001 From: Adrian Margineanu Date: Mon, 21 Sep 2020 13:16:28 +0300 Subject: [PATCH 4/9] Change the label name --- lib/authentication/view/edit_profile_page.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/authentication/view/edit_profile_page.dart b/lib/authentication/view/edit_profile_page.dart index 015dfe6c3..91369efb5 100644 --- a/lib/authentication/view/edit_profile_page.dart +++ b/lib/authentication/view/edit_profile_page.dart @@ -40,7 +40,7 @@ class _EditProfilePageState extends State { key: passwordKey, child: TextFormField( decoration: InputDecoration( - labelText: S.of(context).labelPassword, + labelText: S.of(context).labelConfirmPassword, hintText: S.of(context).hintPassword, ), obscureText: true, From 7a377b28ef61beb8d68829453a4958015a2e31f1 Mon Sep 17 00:00:00 2001 From: Adrian Margineanu Date: Mon, 21 Sep 2020 13:22:57 +0300 Subject: [PATCH 5/9] Improve the sign out method --- lib/resources/utils.dart | 3 +-- pubspec.lock | 38 +++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/resources/utils.dart b/lib/resources/utils.dart index 318acd76b..18a2ed873 100644 --- a/lib/resources/utils.dart +++ b/lib/resources/utils.dart @@ -23,7 +23,6 @@ class Utils { AuthProvider authProvider = Provider.of(context, listen: false); authProvider.signOut(context); - Navigator.popUntil(context, (route) => !route.isFirst); - Navigator.pushNamed(context, Routes.login); + Navigator.pushNamedAndRemoveUntil(context, Routes.login, (route) => false); } } diff --git a/pubspec.lock b/pubspec.lock index ac04853e3..175baec6f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -35,7 +35,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.2" + version: "2.5.0-nullsafety" auto_size_text: dependency: "direct main" description: @@ -63,7 +63,7 @@ packages: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0-nullsafety" cached_network_image: dependency: "direct main" description: @@ -77,14 +77,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.1.0-nullsafety.2" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.3" + version: "1.2.0-nullsafety" cli_util: dependency: transitive description: @@ -98,7 +98,7 @@ packages: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0-nullsafety" cloud_firestore: dependency: "direct main" description: @@ -126,7 +126,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.13" + version: "1.15.0-nullsafety.2" color: dependency: transitive description: @@ -203,7 +203,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.0-nullsafety" ffi: dependency: transitive description: @@ -454,14 +454,14 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.8" + version: "0.12.10-nullsafety" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0-nullsafety.2" mockito: dependency: "direct dev" description: @@ -531,7 +531,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0-nullsafety" path_provider: dependency: transitive description: @@ -718,7 +718,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0-nullsafety" sqflite: dependency: transitive description: @@ -739,21 +739,21 @@ packages: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.5" + version: "1.10.0-nullsafety" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0-nullsafety" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0-nullsafety" synchronized: dependency: transitive description: @@ -767,14 +767,14 @@ packages: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0-nullsafety" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.17" + version: "0.2.19-nullsafety" time: dependency: transitive description: @@ -802,7 +802,7 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0-nullsafety.2" url_launcher: dependency: "direct main" description: @@ -865,7 +865,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0-nullsafety.2" watcher: dependency: transitive description: @@ -902,5 +902,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.9.0 <3.0.0" + dart: ">=2.10.0-0.0.dev <2.10.0" flutter: ">=1.20.0 <2.0.0" From 07acf37bce5d8e91d835cd91d38fefb64600df2e Mon Sep 17 00:00:00 2001 From: Adrian Margineanu Date: Mon, 21 Sep 2020 13:53:39 +0300 Subject: [PATCH 6/9] Removed the Form --- .../view/edit_profile_page.dart | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/lib/authentication/view/edit_profile_page.dart b/lib/authentication/view/edit_profile_page.dart index 91369efb5..b34161b81 100644 --- a/lib/authentication/view/edit_profile_page.dart +++ b/lib/authentication/view/edit_profile_page.dart @@ -28,7 +28,6 @@ class _EditProfilePageState extends State { AppDialog _deletionConfirmationDialog(BuildContext context) { final passwordController = TextEditingController(); - final passwordKey = GlobalKey(); return AppDialog( icon: Icon(Icons.warning, color: Colors.red), title: S.of(context).actionDeleteAccount, @@ -36,21 +35,13 @@ class _EditProfilePageState extends State { ' ' + S.of(context).messageCannotBeUndone, content: [ - Form( - key: passwordKey, - child: TextFormField( - decoration: InputDecoration( - labelText: S.of(context).labelConfirmPassword, - hintText: S.of(context).hintPassword, - ), - obscureText: true, - controller: passwordController, - validator: (value) { - if (value.isEmpty || value == null) { - return S.of(context).errorNoPassword; - } - return null; - }), + TextFormField( + decoration: InputDecoration( + labelText: S.of(context).labelConfirmPassword, + hintText: S.of(context).hintPassword, + ), + obscureText: true, + controller: passwordController, ) ], actions: [ @@ -60,14 +51,12 @@ class _EditProfilePageState extends State { color: Colors.red, width: 130, onTap: () async { - if(passwordKey.currentState.validate()) { - AuthProvider authProvider = - Provider.of(context, listen: false); - if (await authProvider.verifyPassword( - password: passwordController.text, context: context)) { - if (await authProvider.delete(context: context)) { - Utils.signOut(context); - } + AuthProvider authProvider = + Provider.of(context, listen: false); + if (await authProvider.verifyPassword( + password: passwordController.text, context: context)) { + if (await authProvider.delete(context: context)) { + Utils.signOut(context); } } }, From b55907f1ae5d035d5d6a7d0621c6ab406f5ac5c9 Mon Sep 17 00:00:00 2001 From: Adrian Margineanu Date: Mon, 21 Sep 2020 14:41:55 +0300 Subject: [PATCH 7/9] bump the patch --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index dab75cdf9..ca0c8b689 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: A mobile application for students at ACS UPB. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.7.1+3 +version: 0.7.1+4 environment: sdk: ">=2.6.0 <3.0.0" From 0c4de5b1fdd9f1399cece206f54d0043f3580783 Mon Sep 17 00:00:00 2001 From: Adrian Margineanu Date: Mon, 21 Sep 2020 15:07:37 +0300 Subject: [PATCH 8/9] Fix bump path version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index ca0c8b689..2906adb6f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: A mobile application for students at ACS UPB. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.7.1+4 +version: 0.7.2+3 environment: sdk: ">=2.6.0 <3.0.0" From 83d1b81d0f613984a1ce6c5c684b92a4c42c23b4 Mon Sep 17 00:00:00 2001 From: Adrian Margineanu Date: Mon, 21 Sep 2020 15:08:55 +0300 Subject: [PATCH 9/9] Fix bump version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 2906adb6f..35e494758 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: A mobile application for students at ACS UPB. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.7.2+3 +version: 0.7.2+1 environment: sdk: ">=2.6.0 <3.0.0"