From ce42380485a10028048e79af94b0b235a80cbb6b Mon Sep 17 00:00:00 2001 From: zkhan Date: Wed, 29 May 2024 21:38:53 -0400 Subject: [PATCH] 0.0.9 --- lib/data/user_realm_helper.dart | 7 +- lib/online_screen.dart | 64 ++++++++++++++++--- lib/progress_button_message_input_widget.dart | 49 +++++++------- lib/progress_button_message_widget.dart | 29 ++++----- 4 files changed, 98 insertions(+), 51 deletions(-) diff --git a/lib/data/user_realm_helper.dart b/lib/data/user_realm_helper.dart index 0879f9d..9f8d72a 100644 --- a/lib/data/user_realm_helper.dart +++ b/lib/data/user_realm_helper.dart @@ -98,8 +98,13 @@ class UserRealmHelper { } Future deleteAccount(Listargs) async { - String password = args[0]; + String confirmation = args[0]; + String password = args[1]; String failedDeleteMessage = ""; + if(confirmation != "delete") { + failedDeleteMessage = "Confirmation not received."; + return failedDeleteMessage; + } if(password != Storage().settings.getPasswordBackup()) { failedDeleteMessage = "Password does not match the password of the account you are deleting."; return failedDeleteMessage; diff --git a/lib/online_screen.dart b/lib/online_screen.dart index c4d0a52..24e1bce 100644 --- a/lib/online_screen.dart +++ b/lib/online_screen.dart @@ -27,15 +27,45 @@ class OnlineScreenState extends State { children: [ const Padding(padding: EdgeInsets.all(20)), if(!loggedIn) - ProgressButtonMessageInputWidget("Sign In", "Email", email, "Password", password, "Login", Storage().userRealmHelper.login, (value) { - if(value) setState(() {}); + ProgressButtonMessageInputWidget("Sign In", "Email", email, "Password", password, "Login", Storage().userRealmHelper.login, (result, input1, input2) { + Storage().settings.setEmailBackup(input1); + Storage().settings.setPasswordBackup(input2); + if(result) { + setState(() { + }); + }; }, ""), if(loggedIn) ProgressButtonMessageWidget("You are logged in as $email, and your data is backed up automatically when Internet connection is available.", "Logout", Storage().userRealmHelper.logout, const [], (value) { if(value) setState(() {}); }, ""), + if(!loggedIn) - ProgressButtonMessageWidget("Do not have a backup account yet?", "Register", Storage().userRealmHelper.registerUser, [email, password], null, "Successfully Registered $email."), + ProgressButtonMessageWidget("Do not have a backup account yet?", "Register", (args) { + showDialog( + context: context, + builder: (BuildContext context) => + Dialog.fullscreen( + child: Stack(children:[ + Padding(padding: const EdgeInsets.fromLTRB(40, 50, 40, 0), + child:ProgressButtonMessageInputWidget( + "To register a new account, enter an email and password then press Submit.", "Email", email, "Password", password, "Submit", Storage().userRealmHelper.registerUser, + (result, input1, input2) { + if(result) { + setState(() { + Storage().settings.setEmailBackup(input1); + Storage().settings.setPasswordBackup(input2); + }); + }; + }, + "You are now registered.") + ), + Align(alignment: Alignment.topRight, child: IconButton(onPressed: () => Navigator.pop(context), icon: const Icon(Icons.close, size: 36, color: Colors.white))) + ]) + ) + ); + return Future(() => ""); + }, const [], (value) {}, ""), if(!loggedIn) ProgressButtonMessageWidget("Forgot Password?", "Reset Password", Storage().userRealmHelper.resetPasswordRequest, [email], (value) { @@ -47,11 +77,10 @@ class OnlineScreenState extends State { child: Stack(children:[ Padding(padding: const EdgeInsets.fromLTRB(40, 50, 40, 0), child:ProgressButtonMessageInputWidget( - "The request to reset your password has been sent. Check your email for the password reset code. Enter the password reset code a new password here then press Submit to reset your password.", "Password Reset Code", "", "New Password", "", "Submit", Storage().userRealmHelper.resetPassword, - (value) { - if(value) { + "The request to reset your password has been sent to $email. Check your email for the password reset code. Enter the password reset code and a new password then press Submit to reset your password.", "Password Reset Code", "", "New Password", "", "Submit", Storage().userRealmHelper.resetPassword, + (result, input1, input2) { + if(result) { setState(() {}); - Navigator.pop(context); } }, "Your password has been reset.") ), @@ -64,8 +93,25 @@ class OnlineScreenState extends State { // can only delete account if logged in if(loggedIn) - ProgressButtonMessageInputWidget("To delete this account, enter your password and press Submit.", "Email", email, "Password", "", "Submit", Storage().userRealmHelper.deleteAccount, - (value) {}, "Your account has been deleted."), + + ProgressButtonMessageWidget("Do you want to delete the account?", "Proceed", (args) { + showDialog( + context: context, + builder: (BuildContext context) => + Dialog.fullscreen( + child: Stack(children:[ + Padding(padding: const EdgeInsets.fromLTRB(40, 50, 40, 0), + child: ProgressButtonMessageInputWidget("To delete $email account, enter 'delete' in Confirm, enter password, then press Submit.", "Confirm", "", "Password", "", "Submit", Storage().userRealmHelper.deleteAccount, + (result, input1, input2) { + Storage().userRealmHelper.logout([]).then((value) => setState(() {})); + }, "Your account has been deleted."), + ), + Align(alignment: Alignment.topRight, child: IconButton(onPressed: () => Navigator.pop(context), icon: const Icon(Icons.close, size: 36, color: Colors.white))) + ]) + ) + ); + return Future(() => ""); + }, const [], (value) {}, ""), ], )); diff --git a/lib/progress_button_message_input_widget.dart b/lib/progress_button_message_input_widget.dart index 2be45a4..0124cb4 100644 --- a/lib/progress_button_message_input_widget.dart +++ b/lib/progress_button_message_input_widget.dart @@ -10,39 +10,35 @@ class ProgressButtonMessageInputWidget extends StatefulWidget { final String title; final String success; final Future Function(List args) onPressed; - final void Function(bool)? onComplete; + final void Function(bool, String, String)? onComplete; - bool progress = false; - String error = ""; - Color color = Colors.red; - String input1 = ""; - String input2 = ""; - - ProgressButtonMessageInputWidget(this.label, this.label1, this.init1, this.label2, this.init2, this.title, this.onPressed, this.onComplete, this.success, {super.key}) { - input1 = init1; - input2 = init2; - } + const ProgressButtonMessageInputWidget(this.label, this.label1, this.init1, this.label2, this.init2, this.title, this.onPressed, this.onComplete, this.success, {super.key}); @override State createState() => ProgressButtonMessageInputWidgetState(); } - class ProgressButtonMessageInputWidgetState extends State { + bool progress = false; + String error = ""; + Color color = Colors.red; + @override Widget build(BuildContext context) { + String input1 = widget.init1; + String input2 = widget.init2; return Padding(padding: const EdgeInsets.all(10), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(widget.label, style: const TextStyle(fontStyle: FontStyle.italic, fontSize: 18),), + Text(widget.label, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),), TextFormField( onChanged: (value) { - widget.input1 = value; + input1 = value; }, controller: TextEditingController()..text = widget.init1, decoration: InputDecoration(border: const UnderlineInputBorder(), labelText: widget.label1) @@ -51,7 +47,7 @@ class ProgressButtonMessageInputWidgetState extends State[ TextButton(onPressed: () { setState(() { - widget.error = ""; - widget.progress = true; - widget.onPressed([widget.input1, widget.input2]).then((value) { + error = ""; + progress = true; + widget.onPressed([input1, input2]).then((value) { setState(() { - widget.progress = false; - widget.error = value; - if(widget.error.isEmpty) { - widget.color = Colors.green; - widget.error = widget.success; + progress = false; + error = value; + if(error.isEmpty) { + color = Colors.green; + error = widget.success; } if(widget.onComplete != null) { - widget.onComplete!(value.isEmpty); + // return success and new values + widget.onComplete!(value.isEmpty, input1, input2); } }); }); }); }, child: Text(widget.title)), - Visibility(visible: widget.progress, child: const CircularProgressIndicator(),), + Visibility(visible: progress, child: const CircularProgressIndicator(),), ], ), - Text(widget.error, style: TextStyle(color: widget.color),), + Text(error, style: TextStyle(color: color),), ], )); } diff --git a/lib/progress_button_message_widget.dart b/lib/progress_button_message_widget.dart index 5bc1f07..970ba56 100644 --- a/lib/progress_button_message_widget.dart +++ b/lib/progress_button_message_widget.dart @@ -9,11 +9,7 @@ class ProgressButtonMessageWidget extends StatefulWidget { final Future Function(List args) onPressed; final void Function(bool)? onComplete; - bool progress = false; - String error = ""; - Color color = Colors.red; - - ProgressButtonMessageWidget(this.label, this.title, this.onPressed, this.args, this.onComplete, this.success, {super.key}); + const ProgressButtonMessageWidget(this.label, this.title, this.onPressed, this.args, this.onComplete, this.success, {super.key}); @override State createState() => ProgressButtonMessageWidgetState(); @@ -22,6 +18,9 @@ class ProgressButtonMessageWidget extends StatefulWidget { class ProgressButtonMessageWidgetState extends State { + bool progress = false; + String error = ""; + Color color = Colors.red; @override Widget build(BuildContext context) { @@ -30,20 +29,20 @@ class ProgressButtonMessageWidgetState extends State[ - Text(widget.label, style: const TextStyle(fontStyle: FontStyle.italic, fontSize: 18),), + Text(widget.label, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600)), Row( children: [ TextButton(onPressed: () { setState(() { - widget.error = ""; - widget.progress = true; + error = ""; + progress = true; widget.onPressed(widget.args).then((value) { setState(() { - widget.progress = false; - widget.error = value; - if(widget.error.isEmpty) { - widget.color = Colors.green; - widget.error = widget.success; + progress = false; + error = value; + if(error.isEmpty) { + color = Colors.green; + error = widget.success; } if(widget.onComplete != null) { widget.onComplete!(value.isEmpty); @@ -52,10 +51,10 @@ class ProgressButtonMessageWidgetState extends State