-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Coderefactoring in release 1.13 (#252) * Fix focus problem * PicosListCard * Refactor PicosListCard (2.round) * Show phone number in patients_list_card.dart (#254) * Set walkDistance to start with zero (#253) * Feature/fogot password (#256) * Add the feature "forgot password?" to the login screen * Use theme color for "forgot password?" * Refactor the code in forgot_password_screen.dart * Resolve Copy paste error * Use our 'standard' route * Error handling during login (#255) * Localizations * implementation of backend reachability check * "notReachable" added to "BackendError" * Typo in comment fixed * Localizations * errormessage, errorcode & 'incompleteMessages' introduced * Changes discarded * Adjust _createPassword(). (#258) Reformat the code. * Adjust pubspec.yaml (#259) --------- Co-authored-by: mustiwebp <[email protected]>
- Loading branch information
1 parent
173669e
commit 296be1b
Showing
15 changed files
with
407 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
lib/screens/fogot_password_screen/forgot_password_screen.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* This file is part of Picos, a health tracking mobile app | ||
* Copyright (C) 2022 Healthcare IT Solutions GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:parse_server_sdk/parse_server_sdk.dart'; | ||
import 'package:picos/widgets/picos_body.dart'; | ||
import 'package:picos/widgets/picos_screen_frame.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
|
||
import '../../widgets/picos_ink_well_button.dart'; | ||
import '../../widgets/picos_label.dart'; | ||
import '../../widgets/picos_text_field.dart'; | ||
|
||
/// Displays the forgot password screen. | ||
class ForgotPasswordScreen extends StatefulWidget { | ||
/// ForgotPasswordScreen constructor. | ||
const ForgotPasswordScreen({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<ForgotPasswordScreen> createState() => _ForgotPasswordScreenState(); | ||
} | ||
|
||
class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> { | ||
final TextEditingController emailController = TextEditingController(); | ||
final GlobalKey<FormState> formKey = GlobalKey<FormState>(); | ||
|
||
static final RegExp emailRegex = RegExp('.+@.+', caseSensitive: false); | ||
|
||
Future<void> resetPassword(String email) async { | ||
try { | ||
await ParseUser(null, null, email).requestPasswordReset(); | ||
if (mounted) { | ||
showSnackBarMessage(AppLocalizations.of(context)!.ifEmailCorrect); | ||
} | ||
} on ParseException catch (e) { | ||
showSnackBarMessage('Error: $e'); | ||
} | ||
} | ||
|
||
void showSnackBarMessage(String message) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar(content: Text(message)), | ||
); | ||
} | ||
|
||
void validateAndResetPassword() { | ||
if (formKey.currentState!.validate()) { | ||
resetPassword(emailController.text); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return PicosScreenFrame( | ||
title: AppLocalizations.of(context)!.forgotPassword, | ||
body: PicosBody( | ||
child: Form( | ||
key: formKey, | ||
child: Column( | ||
children: <Widget>[ | ||
Text(AppLocalizations.of(context)!.enterMailToResetPW), | ||
const SizedBox(height: 10), | ||
PicosLabel(AppLocalizations.of(context)!.email), | ||
emailInputField(), | ||
resetPasswordButton(), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
PicosTextField emailInputField() { | ||
return PicosTextField( | ||
controller: emailController, | ||
hint: AppLocalizations.of(context)!.email, | ||
keyboardType: TextInputType.emailAddress, | ||
validator: (String? value) { | ||
if (value == null || value.isEmpty) { | ||
return AppLocalizations.of(context)!.entryEmail; | ||
} else if (!emailRegex.hasMatch(value)) { | ||
return AppLocalizations.of(context)!.entryValidEmail; | ||
} | ||
return null; | ||
}, | ||
); | ||
} | ||
|
||
Widget resetPasswordButton() { | ||
return PicosInkWellButton( | ||
text: AppLocalizations.of(context)!.resetPassword, | ||
onTap: validateAndResetPassword, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.