@@ -5,9 +5,12 @@ if logged in, go to homepage
55no account, go to register page
66*/
77
8+ import 'package:azt/features/auth/presentation/components/google_sign_in_button.dart' ;
89import 'package:azt/features/auth/presentation/components/my_button.dart' ;
910import 'package:azt/features/auth/presentation/components/my_textfield.dart' ;
11+ import 'package:azt/features/auth/presentation/cubits/auth_cubit.dart' ;
1012import 'package:flutter/material.dart' ;
13+ import 'package:flutter_bloc/flutter_bloc.dart' ;
1114
1215class LoginPage extends StatefulWidget {
1316 final void Function ()? togglePages;
@@ -22,6 +25,62 @@ class _LoginPageState extends State<LoginPage> {
2225 //text controller
2326 final emailController = TextEditingController ();
2427 final pwController = TextEditingController ();
28+
29+ //auth cubit
30+ late final authCubit = context.read <AuthCubit >();
31+
32+ //LOGIN button pressed
33+ void login (){
34+ //prepare email and password
35+ final String email = emailController.text;
36+ final String pw = pwController.text;
37+
38+ //ensure fields are filled
39+ if (email.isNotEmpty && pw.isNotEmpty){
40+ authCubit.login (email, pw);
41+ }
42+
43+ //fields are empty
44+ else {
45+ ScaffoldMessenger .of (context).showSnackBar (
46+ const SnackBar (content: Text ("Please Enter Both Email and Password!" )));
47+ }
48+ }
49+ void openForgotPasswordBox (){
50+ showDialog (
51+ context: context,
52+ builder: (context)=> AlertDialog (
53+ title: Text ("Forgot Password" ),
54+ content: MyTextField (
55+ controller: emailController, hintText: "Enter email" , obscureText: false
56+ ),
57+ actions: [
58+ //cancel button
59+ TextButton (
60+ onPressed: ()=> Navigator .pop (context),
61+ child: const Text ("Cancel" ),
62+ ),
63+
64+ //reset button
65+ TextButton (
66+ onPressed: () async {
67+ String message = await authCubit.forgotPassword (emailController.text);
68+ if (message == "Password reset email sent!" ){
69+ Navigator .pop (context);
70+ emailController.clear ();
71+ }
72+ ScaffoldMessenger .of (context).showSnackBar (SnackBar (content: Text (message)));
73+ },
74+
75+ child: const Text ("Reset" ),
76+ ),
77+ ]
78+ ),
79+ );
80+ }
81+
82+
83+ //BUILD UI
2584 @override
2685 Widget build (BuildContext context) {
2786
@@ -64,30 +123,70 @@ class _LoginPageState extends State<LoginPage> {
64123
65124 //password
66125 MyTextField (controller: pwController, hintText: "Password" , obscureText: true ),
67-
126+
127+ const SizedBox (height: 10 ),
128+
68129 //forgot pass
69130 Row (
70131 mainAxisAlignment: MainAxisAlignment .center,
71132 children: [
72- Text (
73- "Forgot Password?" ,
74- style: TextStyle (
75- color: Theme .of (context).colorScheme.primary,
76- fontWeight: FontWeight .bold,
77- )
78-
133+ GestureDetector (
134+ onTap: ()=> openForgotPasswordBox (),
135+ child: Text (
136+ "Forgot Password?" ,
137+ style: TextStyle (
138+ color: Theme .of (context).colorScheme.primary,
139+ fontWeight: FontWeight .bold,
140+ )
141+
142+ ),
79143 ),
80144 ],
81145 ),
82146
83- const SizedBox (height: 25 ),
147+ const SizedBox (height: 10 ),
84148
85149 //login
86150 MyButton (
87- onTap: () {} ,
151+ onTap: login ,
88152 text: "Login" ,
89153 ),
90154
155+ const SizedBox (height: 10 ),
156+
157+ Row (
158+ children: [
159+ Expanded (
160+ child: Divider (
161+ color: Theme .of (context).colorScheme.tertiary,
162+ ),
163+ ),
164+ Text ("Or sign in with" ),
165+ Expanded (
166+ child: Divider (
167+ color: Theme .of (context).colorScheme.tertiary,
168+ ),
169+ ),
170+ ],
171+ ),
172+
173+ const SizedBox (height: 15 ),
174+
175+
176+ // oauth using google
177+ Row (
178+ mainAxisAlignment: MainAxisAlignment .center,
179+ children: [
180+ //google button
181+ MyGoogleSignInButton (
182+ onTap: () {},
183+ )
184+
185+ ],
186+ ),
187+
188+ const SizedBox (height: 25 ),
189+
91190 //dont have acc sign in later
92191 Row (
93192 mainAxisAlignment: MainAxisAlignment .center,
0 commit comments