Skip to content

Commit

Permalink
add user account page and password reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Alidantech committed Mar 21, 2024
1 parent 8348831 commit 9e9800a
Show file tree
Hide file tree
Showing 22 changed files with 911 additions and 731 deletions.
6 changes: 3 additions & 3 deletions lib/config/themes/dark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ ThemeData darkMode = ThemeData(
primary: Colors.cyan.shade500,
secondary: Colors.cyan.shade800,
),

appBarTheme: AppBarTheme(
centerTitle: true,
backgroundColor: Colors.cyan.shade500,
foregroundColor: Colors.white,
elevation: 1),
backgroundColor: Colors.transparent,
elevation: 0),
bottomNavigationBarTheme: BottomNavigationBarThemeData(
unselectedItemColor: Colors.grey.shade400.withOpacity(0.8),
selectedItemColor: Colors.cyan.shade200,
Expand Down
69 changes: 39 additions & 30 deletions lib/config/themes/light.dart
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,
);
62 changes: 56 additions & 6 deletions lib/controllers/auth/forgot_pwd_controller.dart
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.');
}
}
}
1 change: 1 addition & 0 deletions lib/controllers/user_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:cloud_firestore/cloud_firestore.dart';
class UserController {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;

// Create a new user document in the users collection
Future<void> createUser(UserModel user) async {
await _firestore.collection('users').doc(user.id).set(user.toMap());
}
Expand Down
12 changes: 4 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';


import 'views/services/user_provider.dart';

void main() async {
Expand All @@ -26,8 +25,7 @@ void main() async {
MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => ThemeProvider()),
ChangeNotifierProvider(
create: (context) => UserProvider()),
ChangeNotifierProvider(create: (context) => UserProvider()),
],
child: OrganiserApp(),
),
Expand All @@ -54,18 +52,16 @@ class _OrganiserAppState extends State<OrganiserApp> {
: Brightness.dark,
systemNavigationBarColor:
themeProvider.themeData.brightness == Brightness.dark
? Colors.black.withOpacity(0.9)
: Colors.white.withOpacity(0.9),
? Colors.black
: Colors.white,
statusBarIconBrightness:
themeProvider.themeData.brightness == Brightness.dark
? Brightness.light
: Brightness.dark,
));
return MaterialApp(
theme: themeProvider.themeData,
home: SplashScreen(
onSelectThemeColor: () {},
),
home: SplashScreen(),
debugShowCheckedModeBanner: false,
themeAnimationCurve: Curves.easeInOut,
themeAnimationDuration: const Duration(milliseconds: 500),
Expand Down
7 changes: 6 additions & 1 deletion lib/models/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class UserModel {
final String? lname;
final String? gender;
final DateTime? dob;
final DateTime? createdAt;
final String? profilePhotoUrl;
final List<String> groupIds;
final List<String> communityIds;
Expand All @@ -20,6 +21,7 @@ class UserModel {
this.lname,
this.gender,
this.dob,
this.createdAt,
this.profilePhotoUrl,
this.groupIds = const [],
this.communityIds = const [],
Expand All @@ -34,10 +36,12 @@ class UserModel {
fname: data['fname'],
lname: data['lname'],
gender: data['gender'],
dob: data['dob']?.toDate(),
dob: DateTime.parse(data['dob']!),
createdAt: DateTime.parse(data['createdAt']!),
profilePhotoUrl: data['profilePhotoUrl'],
groupIds: List<String>.from(data['groupIds'] ?? []),
communityIds: List<String>.from(data['communityIds'] ?? []),

);
}

Expand All @@ -49,6 +53,7 @@ class UserModel {
'lname': lname,
'gender': gender,
'dob': dob?.toIso8601String(),
'createdAt': createdAt?.toIso8601String(),
'profilePhotoUrl': profilePhotoUrl,
'groupIds': groupIds,
'communityIds': communityIds,
Expand Down
Loading

0 comments on commit 9e9800a

Please sign in to comment.