-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add user account page and password reset
- Loading branch information
1 parent
8348831
commit 9e9800a
Showing
22 changed files
with
911 additions
and
731 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,42 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
ThemeData lightMode = ThemeData( | ||
primaryColor: Colors.cyan, | ||
cardTheme: CardTheme(color: Colors.white, elevation: 1), | ||
drawerTheme: | ||
DrawerThemeData(backgroundColor: Colors.cyan.shade50,), | ||
scaffoldBackgroundColor: Colors.white, | ||
brightness: Brightness.light, | ||
colorScheme: ColorScheme.light( | ||
background: Colors.grey.shade400, | ||
primary: Colors.cyan, | ||
secondary: Colors.cyan.shade50, | ||
), | ||
appBarTheme: AppBarTheme( | ||
centerTitle: true, | ||
backgroundColor: Colors.cyan.shade50, | ||
foregroundColor: Colors.black87, | ||
elevation: 1), | ||
bottomNavigationBarTheme: BottomNavigationBarThemeData( | ||
unselectedItemColor: Colors.black38, | ||
selectedItemColor: Colors.cyan, | ||
selectedLabelStyle: TextStyle(fontWeight: FontWeight.bold, fontSize: 10), | ||
selectedIconTheme: IconThemeData(size: 25), | ||
unselectedIconTheme: IconThemeData(size: 20), | ||
backgroundColor: Colors.cyan.shade50), | ||
dialogTheme: DialogTheme( | ||
backgroundColor: Colors.cyan.shade50.withOpacity(0.95), | ||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(50)), | ||
), | ||
shadowColor: Colors.grey.shade200, | ||
|
||
); | ||
primaryColor: Colors.cyan, | ||
cardTheme: CardTheme(color: Colors.white, elevation: 1), | ||
drawerTheme: DrawerThemeData( | ||
backgroundColor: Colors.cyan.shade50, | ||
), | ||
scaffoldBackgroundColor: Colors.white, | ||
brightness: Brightness.light, | ||
colorScheme: ColorScheme.light( | ||
background: Colors.grey.shade400, | ||
primary: Colors.cyan, | ||
secondary: Colors.cyan.shade50, | ||
), | ||
appBarTheme: AppBarTheme( | ||
centerTitle: true, | ||
backgroundColor: Colors.transparent, | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.only( | ||
bottomLeft: Radius.circular(50), | ||
), | ||
), | ||
elevation: 0), | ||
bottomNavigationBarTheme: BottomNavigationBarThemeData( | ||
unselectedItemColor: Colors.black38, | ||
selectedItemColor: Colors.cyan, | ||
selectedLabelStyle: TextStyle(fontWeight: FontWeight.bold, fontSize: 10), | ||
selectedIconTheme: IconThemeData(size: 25), | ||
unselectedIconTheme: IconThemeData(size: 20), | ||
elevation: 0, | ||
mouseCursor: MaterialStateMouseCursor.textable, | ||
enableFeedback: false, | ||
type: BottomNavigationBarType.fixed, | ||
backgroundColor: Colors.transparent, | ||
), | ||
dialogTheme: DialogTheme( | ||
backgroundColor: Colors.cyan.shade50.withOpacity(0.95), | ||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(50)), | ||
), | ||
shadowColor: Colors.grey.shade200, | ||
); |
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 |
---|---|---|
@@ -1,14 +1,64 @@ | ||
import 'package:Organiser/views/widgets/common/snack_bar.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class PasswordResetController { | ||
Future<String> resetPassword(String email) async { | ||
class ResetPasswordController { | ||
final FirebaseAuth _auth = FirebaseAuth.instance; | ||
final ValueNotifier<bool> isLoading = ValueNotifier<bool>(false); | ||
|
||
Future <Either<String, bool?>> resetPassword( | ||
BuildContext context, | ||
String email, | ||
) async { | ||
try { | ||
await FirebaseAuth.instance.sendPasswordResetEmail(email: email.trim()); | ||
return 'Email sent successfully'; | ||
isLoading.value = true; | ||
showDialog( | ||
context: context, | ||
barrierDismissible: false, | ||
builder: (BuildContext context) { | ||
return Center( | ||
child: CircularProgressIndicator(), | ||
); | ||
}, | ||
); | ||
|
||
// Send a password reset email | ||
await _auth.sendPasswordResetEmail( | ||
email: email.trim(), | ||
); | ||
|
||
isLoading.value = false; | ||
Navigator.pop(context); | ||
CustomSnackbar.show(context, 'success', 'Email sent succesfully.'); | ||
|
||
return Right(true); | ||
} on FirebaseAuthException catch (e) { | ||
return 'Error: ${e.message}'; | ||
isLoading.value = false; | ||
Navigator.pop(context); | ||
print('FirebaseAuthException: ${e.code}'); | ||
String errorMessage; | ||
switch (e.code) { | ||
case 'invalid-credential': | ||
errorMessage = 'Email not registered.'; | ||
break; | ||
case 'network-request-failed': | ||
errorMessage = 'No network connection.'; | ||
break; | ||
default: | ||
errorMessage = 'An unexpected auth error occurred.'; | ||
break; | ||
} | ||
|
||
CustomSnackbar.show(context, 'error', errorMessage); | ||
|
||
return Left(errorMessage); | ||
} catch (e) { | ||
return 'Error: Something went wrong'; | ||
isLoading.value = false; | ||
Navigator.pop(context); | ||
|
||
print('Login error: $e'); | ||
return Left('An unexpected error occurred.'); | ||
} | ||
} | ||
} |
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.