Skip to content

Commit

Permalink
Merge pull request #33 from AdrianMargineanu/delete_profile
Browse files Browse the repository at this point in the history
Check password when deleting account
  • Loading branch information
IoanaAlexandru authored Sep 21, 2020
2 parents 9125681 + 83d1b81 commit 4f7a7d9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
7 changes: 6 additions & 1 deletion lib/authentication/service/auth_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ class AuthProvider with ChangeNotifier {
}).then((_) => true);
}

Future<bool> verifyPassword({String password, BuildContext context}) async {
return await signIn(
email: _firebaseUser.email, password: password, context: context);
}

Future<bool> signIn(
{String email, String password, BuildContext context}) async {
if (email == null || email == '') {
Expand Down Expand Up @@ -433,7 +438,7 @@ class AuthProvider with ChangeNotifier {
var userUpdateInfo = UserUpdateInfo();
userUpdateInfo.displayName = firstName + ' ' + lastName;
await _firebaseUser.updateProfile(userUpdateInfo);

notifyListeners();
return true;
} catch (e) {
Expand Down
57 changes: 36 additions & 21 deletions lib/authentication/view/edit_profile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,44 @@ class _EditProfilePageState extends State<EditProfilePage> {

final formKey = GlobalKey<FormState>();

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<AuthProvider>(context, listen: false);
bool res = await authProvider.delete(context: context);
if (res) {
AppDialog _deletionConfirmationDialog(BuildContext context) {
final passwordController = TextEditingController();
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).labelConfirmPassword,
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<AuthProvider>(context, listen: false);
if (await authProvider.verifyPassword(
password: passwordController.text, context: context)) {
if (await authProvider.delete(context: context)) {
Utils.signOut(context);
}
},
)
],
);
}
},
)
],
);
}

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion lib/resources/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ class Utils {
AuthProvider authProvider =
Provider.of<AuthProvider>(context, listen: false);
authProvider.signOut(context);
Navigator.pushReplacementNamed(context, Routes.login);
Navigator.pushNamedAndRemoveUntil(context, Routes.login, (route) => false);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.2+1

environment:
sdk: ">=2.6.0 <3.0.0"
Expand Down

0 comments on commit 4f7a7d9

Please sign in to comment.