Skip to content

Commit 36b2b51

Browse files
authored
Merge pull request #145 from SanskarModi22/hactober/Sanskar
Added Forget password functionality Fixes #124
2 parents 113f2fb + bbb8496 commit 36b2b51

File tree

4 files changed

+56
-21
lines changed

4 files changed

+56
-21
lines changed

lib/screens/auth/forgot_password.dart

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:books_app/constants/colors.dart';
22
import 'package:books_app/constants/routes.dart';
3+
import 'package:books_app/services/auth.dart';
34
import 'package:books_app/widgets/auth/auth_navigation.dart';
45
import 'package:books_app/widgets/auth/auth_page_title.dart';
56
import 'package:books_app/widgets/button.dart';
@@ -16,6 +17,7 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
1617
TextEditingController _emailController = TextEditingController();
1718
// final BackendService authService = BackendService();
1819

20+
String? _message;
1921
@override
2022
Widget build(BuildContext context) {
2123
return Scaffold(
@@ -25,6 +27,7 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
2527
child: Column(
2628
crossAxisAlignment: CrossAxisAlignment.stretch,
2729
children: <Widget>[
30+
showAlert() ,
2831
const AuthPageTitle(name: 'Reset password'),
2932
// AuthErrorMessage(errorMessage: error.toString()),
3033
Form(
@@ -38,29 +41,62 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
3841
Button(
3942
name: 'Continue',
4043
color: blackButton,
41-
myFunction: () {
44+
myFunction: () async {
45+
await FirebaseAuthService()
46+
.ResetPassword(_emailController.text);
47+
setState(() {
48+
_message =
49+
'Password reset link has been sent to you on email ${_emailController.text}.You will be redirected to signIn page';
50+
});
51+
52+
print(_message);
53+
await Future<dynamic>.delayed(const Duration(seconds: 4), () {});
4254
Navigator.pushReplacementNamed(context, Routes.INITIAL_PAGE);
4355
},
4456
)
45-
// AuthButton(
46-
// text: 'Continue',
47-
// formKey: formKey,
48-
// onClick: onSubmit,
49-
// onSuccess: onSuccess,
50-
// onError: onError,
51-
// )
5257
],
5358
),
5459
),
5560
);
5661
}
5762

58-
// Future<String> onSubmit() async {
59-
// return authService.forgotPassword(email).toString();
60-
// }
61-
62-
// void onSuccess() {
63-
// Navigator.of(context).push<dynamic>(MaterialPageRoute<dynamic>(
64-
// builder: (BuildContext context) => ResetPasswordScreen(email: email)));
65-
// }
63+
Widget showAlert() {
64+
if (_message != null) {
65+
return Align(
66+
alignment: Alignment.topCenter,
67+
child: Container(
68+
color: Colors.amberAccent,
69+
width: double.infinity,
70+
padding: const EdgeInsets.all(8.0),
71+
child: Row(
72+
children: <Widget>[
73+
const Padding(
74+
padding: EdgeInsets.only(right: 8.0),
75+
child: Icon(Icons.error_outline),
76+
),
77+
Expanded(
78+
child: Text(
79+
_message!,
80+
maxLines: 3,
81+
),
82+
),
83+
Padding(
84+
padding: const EdgeInsets.only(left: 8.0),
85+
child: IconButton(
86+
icon: const Icon(Icons.close),
87+
onPressed: () {
88+
setState(() {
89+
_message = '';
90+
});
91+
},
92+
),
93+
)
94+
],
95+
),
96+
),
97+
);
98+
}
99+
else
100+
return Container();
101+
}
66102
}

lib/screens/auth/register.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import 'package:books_app/constants/colors.dart';
2-
import 'package:books_app/constants/routes.dart';
32
import 'package:books_app/services/auth.dart';
4-
import 'package:books_app/widgets/auth/auth_error_message.dart';
53
import 'package:books_app/widgets/auth/auth_navigation.dart';
64
import 'package:books_app/widgets/auth/auth_page_title.dart';
75
import 'package:books_app/widgets/button.dart';
86
import 'package:books_app/widgets/text_field.dart';
9-
import 'package:firebase_auth/firebase_auth.dart';
107
import 'package:flutter/material.dart';
118

129
class RegisterScreen extends StatefulWidget {

lib/screens/book_desciption.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:books_app/constants/colors.dart';
1+
22
import 'package:books_app/constants/routes.dart';
33
import 'package:books_app/providers/book.dart';
44
import 'package:books_app/services/auth.dart';

lib/services/auth.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ class FirebaseAuthService extends ChangeNotifier {
159159
}
160160
}
161161
}
162-
162+
Future<void>ResetPassword(String email) async {
163+
await firebaseAuth.sendPasswordResetEmail(email: email);
164+
}
163165
// sign out from app
164166
Future<void> signOut() async {
165167
await firebaseAuth.signOut();

0 commit comments

Comments
 (0)