Skip to content

Commit

Permalink
0.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
apps4av committed May 30, 2024
1 parent 961568e commit ce42380
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 51 deletions.
7 changes: 6 additions & 1 deletion lib/data/user_realm_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ class UserRealmHelper {
}

Future<String> deleteAccount(List<String>args) 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;
Expand Down
64 changes: 55 additions & 9 deletions lib/online_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,45 @@ class OnlineScreenState extends State<OnlineScreen> {
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<String>(
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) {
Expand All @@ -47,11 +77,10 @@ class OnlineScreenState extends State<OnlineScreen> {
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.")
),
Expand All @@ -64,8 +93,25 @@ class OnlineScreenState extends State<OnlineScreen> {

// 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<String>(
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) {}, ""),
],
));

Expand Down
49 changes: 23 additions & 26 deletions lib/progress_button_message_input_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,35 @@ class ProgressButtonMessageInputWidget extends StatefulWidget {
final String title;
final String success;
final Future<String> Function(List<String> 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<StatefulWidget> createState() => ProgressButtonMessageInputWidgetState();

}


class ProgressButtonMessageInputWidgetState extends State<ProgressButtonMessageInputWidget> {

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: <Widget>[

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)
Expand All @@ -51,7 +47,7 @@ class ProgressButtonMessageInputWidgetState extends State<ProgressButtonMessageI
TextFormField(
obscureText: true,
onChanged: (value) {
widget.input2 = value;
input2 = value;
},
controller: TextEditingController()..text = widget.init2,
decoration: InputDecoration(border: const UnderlineInputBorder(), labelText: widget.label2)
Expand All @@ -61,27 +57,28 @@ class ProgressButtonMessageInputWidgetState extends State<ProgressButtonMessageI
children: <Widget>[
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),),
],
));
}
Expand Down
29 changes: 14 additions & 15 deletions lib/progress_button_message_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ class ProgressButtonMessageWidget extends StatefulWidget {
final Future<String> Function(List<String> 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<StatefulWidget> createState() => ProgressButtonMessageWidgetState();
Expand All @@ -22,6 +18,9 @@ class ProgressButtonMessageWidget extends StatefulWidget {


class ProgressButtonMessageWidgetState extends State<ProgressButtonMessageWidget> {
bool progress = false;
String error = "";
Color color = Colors.red;

@override
Widget build(BuildContext context) {
Expand All @@ -30,20 +29,20 @@ class ProgressButtonMessageWidgetState extends State<ProgressButtonMessageWidget
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[

Text(widget.label, style: const TextStyle(fontStyle: FontStyle.italic, fontSize: 18),),
Text(widget.label, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600)),
Row(
children: <Widget>[
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);
Expand All @@ -52,10 +51,10 @@ class ProgressButtonMessageWidgetState extends State<ProgressButtonMessageWidget
});
});
}, 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),),
],
));
}
Expand Down

0 comments on commit ce42380

Please sign in to comment.