Skip to content

Commit

Permalink
Feature Request: Display username, email address, and profile photo f…
Browse files Browse the repository at this point in the history
…rom firebase authentication

Fixes muzammildafedar#15
  • Loading branch information
xkaper001 committed Oct 7, 2024
1 parent 6acb9a8 commit a3001a8
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 38 deletions.
81 changes: 70 additions & 11 deletions functions/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"cors": "^2.8.5",
"crypto": "^1.0.1",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"express": "^4.21.0",
"express-validator": "^7.2.0",
"multer": "^1.4.5-lts.1",
"nodemailer": "^6.9.14",
Expand Down
4 changes: 2 additions & 2 deletions lib/layout/navigation_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class _NavigationPanelState extends State<NavigationPanel> {
return NavigationButton(
onPressed: () {
activeTabProvider.setActiveTabIndex(item.index);
if (activeTabProvider.fetchCurrentTabIndex >= 2) {
if (activeTabProvider.fetchCurrentTabIndex == 3) {
activeTabProvider.setActiveTabIndex(item.index - 1);
ShowLogoutDialog(context, logout);
}
Expand All @@ -51,7 +51,7 @@ class _NavigationPanelState extends State<NavigationPanel> {
? const EdgeInsets.symmetric(horizontal: 30, vertical: 20)
: const EdgeInsets.all(10),
child: widget.axis == Axis.vertical
? Column(
? Column(
mainAxisAlignment: MainAxisAlignment.center, // Center items vertically
children: NavigationItems.values
.map((e) => buildNavigationButton(e))
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class App extends StatelessWidget {
routerDelegate: router.routerDelegate,
routeInformationParser: router.routeInformationParser,
routeInformationProvider: router.routeInformationProvider,
debugShowCheckedModeBanner: false,
debugShowCheckedModeBanner: false,
title: "Udayah | AI-Powered Tools for Job Hunters",

theme: ThemeData(
Expand Down
3 changes: 3 additions & 0 deletions lib/models/enums/navigation_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
enum NavigationItems {
home,
settings,
profile,
logout
}

Expand All @@ -13,6 +14,8 @@ extension NavigationItemsExtensions on NavigationItems {
return Icons.home;
case NavigationItems.settings:
return Icons.settings;
case NavigationItems.profile:
return Icons.person;
case NavigationItems.logout:
return Icons.logout;
default:
Expand Down
8 changes: 4 additions & 4 deletions lib/pages/dashboard_page.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:udayah/layout/app_layout.dart';
import 'package:udayah/provider/auth.dart';
import 'package:udayah/provider/navigation.dart';
import 'package:udayah/responsive.dart';
import 'package:udayah/widgets/companies_list.dart';
import 'package:udayah/widgets/profile_page.dart';
import 'package:udayah/widgets/smtp_page.dart';

class Dashboard extends StatefulWidget {
Expand All @@ -17,7 +16,8 @@ class Dashboard extends StatefulWidget {
class _DashboardState extends State<Dashboard> {
List<Widget> screens = [
CompaniesList(),
SmtpSetup(),
const SmtpSetup(),
const ProfilePage(),
];

@override
Expand All @@ -33,7 +33,7 @@ class _DashboardState extends State<Dashboard> {
// Main Panel
Expanded(
flex: 5,
child: _.fetchCurrentTabIndex >= 2
child: _.fetchCurrentTabIndex >= 3
? Container()
: screens[_.fetchCurrentTabIndex],
),
Expand Down
11 changes: 10 additions & 1 deletion lib/provider/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ class AuthProvider with ChangeNotifier {
final FirebaseAuth _auth = FirebaseAuth.instance;
User? _user;

// Persists the user's authentication state across app restarts
AuthProvider() {
_auth.authStateChanges().listen((User? user) {
_user = user;
notifyListeners();
});
}

User? get user => _user;
bool get isAuthenticated => _user != null;

Future<void> signInWithGoogle(BuildContext context) async {
try {
UserCredential userCredential = await _auth.signInWithPopup(GoogleAuthProvider());
UserCredential userCredential =
await _auth.signInWithPopup(GoogleAuthProvider());
_user = userCredential.user;
// Redirect to dashboard after successful sign-in
if (_user != null) {
Expand Down
6 changes: 5 additions & 1 deletion lib/provider/companies.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:developer';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:udayah/data/constants.dart';
Expand Down Expand Up @@ -45,8 +47,10 @@ class CompaniesProvider with ChangeNotifier {
notifyListeners();

try {
log("Fetching emails from: $apiUrl");
final response = await http.get(Uri.parse(apiUrl));

log("Response: ${response.body}");
log("Response Code: ${response.statusCode}");
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
final decryptedData =
Expand Down
14 changes: 8 additions & 6 deletions lib/widgets/category_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import 'package:udayah/responsive.dart';
import 'package:udayah/styles/fonts.dart';
import 'package:udayah/styles/styles.dart';
import 'package:flutter/material.dart';
import 'package:udayah/widgets/video.dart';


class CategoryBox extends StatelessWidget {
final List<Widget> children;
final Widget? suffix;
final String title;
final CrossAxisAlignment? crossAxisAlignment;

const CategoryBox({
Key? key,
super.key,
this.suffix,
required this.children,
required this.title,
}) : super(key: key);
this.crossAxisAlignment,
});

@override
Widget build(BuildContext context) {
Expand All @@ -25,7 +25,7 @@ class CategoryBox extends StatelessWidget {
borderRadius: Styles.defaultBorderRadius,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: crossAxisAlignment ?? CrossAxisAlignment.start,
children: [
// Responsive.isMobile(context) || Responsive.isTablet(context)
// ? Flexible(
Expand Down Expand Up @@ -53,7 +53,9 @@ class CategoryBox extends StatelessWidget {
children: [
Text(
title,
style: Responsive.isMobile(context) ? AppTextStyles.heading1BlackMobile : AppTextStyles.heading1Black,
style: Responsive.isMobile(context)
? AppTextStyles.heading1BlackMobile
: AppTextStyles.heading1Black,
),
suffix ?? Container(),
// ElevatedButton(
Expand Down
78 changes: 78 additions & 0 deletions lib/widgets/profile_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:udayah/widgets/category_box.dart';

import '../provider/auth.dart';

class ProfilePage extends StatefulWidget {
const ProfilePage({super.key});

@override
State<ProfilePage> createState() => _ProfilePageState();
}

class _ProfilePageState extends State<ProfilePage> {
@override
Widget build(BuildContext context) {
return Consumer<AuthProvider>(
builder: (context, data, child) {
log("User: ${data.user}");
if (data.user == null) {
return const Center(
child: CircularProgressIndicator(),
);
}
final photoURL = data.user?.photoURL;
final displayName = data.user?.displayName;
final email = data.user?.email;

return CategoryBox(
title: "Profile",
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(height: 50),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text("Name"),
Text(
displayName ?? "User",
style: const TextStyle(
fontSize: 36,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
const Text("Email"),
Text(
email ?? "No Email Provided",
style: const TextStyle(
fontSize: 36,
fontWeight: FontWeight.bold,
),
),
],
),
// Displays User Profile Picture if available other
CircleAvatar(
radius: 100,
backgroundImage:
photoURL != null ? NetworkImage(photoURL) : null,
child: photoURL == null
? const Icon(Icons.person, size: 50)
: null,
),
],
),
const SizedBox(height: 20),
],
);
},
);
}
}
22 changes: 11 additions & 11 deletions lib/widgets/smtp_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import 'package:udayah/styles/fonts.dart';
import 'package:udayah/styles/styles.dart';
import 'package:udayah/widgets/category_box.dart';
import 'package:udayah/widgets/popups.dart';

class SmtpSetup extends StatefulWidget {
const SmtpSetup({Key? key}) : super(key: key);
const SmtpSetup({super.key});

@override
State<SmtpSetup> createState() => _SmtpSetupState();
Expand Down Expand Up @@ -110,10 +110,10 @@ class _SmtpSetupState extends State<SmtpSetup> {
style: ElevatedButton.styleFrom(
backgroundColor:
Styles.brandBackgroundColor, // Button color
padding: EdgeInsets.symmetric(
padding: const EdgeInsets.symmetric(
horizontal: 16.0, vertical: 12.0), // Padding
),
child: Text(
child: const Text(
"Instructions",
style: AppTextStyles.regular,
),
Expand All @@ -135,40 +135,40 @@ class _SmtpSetupState extends State<SmtpSetup> {
validator: (value) =>
_validateNotEmpty(value, 'SMTP Server'),
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
_buildTextField(
controller: _smtpPortController,
labelText: 'SMTP Port',
keyboardType: TextInputType.number,
validator: _validatePort,
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
_buildTextField(
controller: _smtpUsernameController,
labelText: 'SMTP Username',
validator: (value) =>
_validateNotEmpty(value, 'SMTP Username'),
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
_buildTextField(
controller: _smtpPasswordController,
labelText: 'SMTP Password',
obscureText: true,
validator: (value) =>
_validateNotEmpty(value, 'SMTP Password'),
),
SizedBox(height: 32.0),
const SizedBox(height: 32.0),
ElevatedButton.icon(
onPressed: () => _submitForm(context),
icon: Icon(Icons.save, color: Colors.white,),
label: Text(
icon: const Icon(Icons.save, color: Colors.white,),
label: const Text(
'Save Settings',
style: AppTextStyles.regular,
),
style: ElevatedButton.styleFrom(
backgroundColor:
Styles.brandBackgroundColor, // Button color
padding: EdgeInsets.symmetric(
padding: const EdgeInsets.symmetric(
horizontal: 32.0,
vertical: 12.0,
),
Expand Down
4 changes: 4 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ import cloud_firestore
import firebase_auth
import firebase_core
import firebase_storage
import flutter_inappwebview_macos
import path_provider_foundation
import shared_preferences_foundation
import url_launcher_macos
import webview_flutter_wkwebview

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTFirebaseFirestorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseFirestorePlugin"))
FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin"))
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
FLTFirebaseStoragePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseStoragePlugin"))
InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
FLTWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "FLTWebViewFlutterPlugin"))
}
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <firebase_auth/firebase_auth_plugin_c_api.h>
#include <firebase_core/firebase_core_plugin_c_api.h>
#include <firebase_storage/firebase_storage_plugin_c_api.h>
#include <flutter_inappwebview_windows/flutter_inappwebview_windows_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
Expand All @@ -21,6 +22,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FirebaseCorePluginCApi"));
FirebaseStoragePluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FirebaseStoragePluginCApi"));
FlutterInappwebviewWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterInappwebviewWindowsPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
firebase_auth
firebase_core
firebase_storage
flutter_inappwebview_windows
url_launcher_windows
)

Expand Down

0 comments on commit a3001a8

Please sign in to comment.