-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
229 lines (216 loc) · 10.5 KB
/
Copy pathindex.html
File metadata and controls
229 lines (216 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="x-content-type-options" content="nosniff">
<!--<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Login with Facebook to access your profile and view personalized stats.">
<meta name="google-adsense-account" content="ca-pub-6340254487227270">
<meta property="og:title" content="Your Page Title Here">
<meta property="og:description" content="A brief description of your page content.">
<meta property="og:image" content="https://facebookegypt.github.io/evry1falls/img/looking-good.gif">
<meta property="og:url" content="https://facebookegypt.github.io/evry1falls/">
<meta property="og:type" content="website">
<meta property="fb:app_id" content="880835337346722">
<title>Ahmed Samir's - Evry1falls (Social Logins)</title>
<link href="favicon.ico" rel="icon" type="image/x-icon">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=DynaPuff:wdth,wght@75..100,400..700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="m.css">
<!-- Firebase SDKs (version 9.1.3 for browser compatibility) -->
<script src="https://www.gstatic.com/firebasejs/9.1.3/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.1.3/firebase-auth-compat.js"></script>
</head>
<body>
<div class="headerGH">
<div class="user-info d-flex align-items-center" id="user-info">
<span id="user-name1" style="color: green; font-size: 18px; display:none;">Welcome, User</span>
</div>
<button type="button" id="logout-btn" class="logout-btn" onclick="logout()" style="display: none;">Log out</button>
</div>
<div class="login-container" id="login-container">
<img id="user-photo" src="img/hh.gif" alt="Profile Picture" class="profile-photo me-2">
<h1>Welcome</h1>
<span id="user-name" style="color: green; font-size: 18px; display: none;">Welcome, User</span>
<h3>Social Media Login</h3>
<form id="sign-up-form" onsubmit="event.preventDefault(); submitForm();">
<div class="login-form" id="signup-div">
<input type="text" id="email" placeholder="Email" autocomplete="off" required>
<input type="password" id="password" placeholder="Password" autocomplete="off" required>
<button type="button">Login</button>
<button type="button" onclick="signUp()">Sign Up</button>
</div>
<!-- Message display area -->
<div id="message" style="height: 20px; color: green; font-size: 14px; margin-top: 10px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">
<!-- This will show success/error messages -->
</div>
<div class="social-buttons">
<button class="facebook" id="facebook-login-btn">
<i class="fab fa-facebook-f"></i>
Login with Facebook
</button>
<button class="twitter">
<i class="fab fa-twitter"></i>
Login with Twitter
</button>
<button class="google">
<i class="fab fa-google"></i>
Login with Google
</button>
<button class="instagram">
<i class="fab fa-instagram"></i>
Login with Instagram
</button>
</div>
</div>
<script>
// Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyBdDxwmuS9w0VnfYzLL2ptYBI4GYUWuZqQ",
authDomain: "git-hub-test-34e5a.firebaseapp.com",
databaseURL: "https://git-hub-test-34e5a-default-rtdb.firebaseio.com",
projectId: "git-hub-test-34e5a",
storageBucket: "git-hub-test-34e5a.appspot.com",
messagingSenderId: "824616741271",
appId: "1:824616741271:web:7d068b5de85ba781757cd2",
measurementId: "G-TV39YCR646"
};
// Initialize Firebase
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
// Set session persistence to LOCAL
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL)
.then(() => {
// Track authentication state changes
firebase.auth().onAuthStateChanged((user) => {
if (user) {
updateUIForLoggedInUser(user);
} else {
resetUIForLoggedOutUser();
}
});
})
.catch((error) => {
console.error("Error setting auth persistence:", error);
});
// Select elements
const SocialButtons = document.querySelector('.social-buttons');
const loginForm = document.getElementById('signup-div');
const userInfo = document.getElementById('user-info');
const userName = document.getElementById('user-name');
const userPhoto = document.getElementById('user-photo');
const logoutBtn = document.getElementById('logout-btn');
const messageDiv = document.getElementById('message');
// Function to handle UI update for logged-in user
function updateUIForLoggedInUser(user) {
loginForm.style.display = 'none'; // Hide form
userName.style.display = 'block';
userName.textContent = user.displayName || 'Guest';
userPhoto.src = user.photoURL || 'img/hh.gif';
userInfo.style.display = 'none';
logoutBtn.style.display = 'flex';
logoutBtn.style.justifyContent = 'center';
SocialButtons.style.display= 'none';
// Set logo for logout button based on provider
if (user.providerData.some(provider => provider.providerId === 'google.com')) {
logoutBtn.innerHTML = '<i class="fab fa-google"></i> Log out';
} else if (user.providerData.some(provider => provider.providerId === 'facebook.com')) {
logoutBtn.innerHTML = '<i class="fab fa-facebook-f"></i> Log out';
} else {
logoutBtn.innerHTML = 'Log out'; // Default appearance for email/password
}
}
// Function to reset UI for logged-out user
function resetUIForLoggedOutUser() {
loginForm.style.display = 'flex'; // Show form
logoutBtn.style.display = 'none'; // Hide logout button
SocialButtons.style.display = 'flex'; // Hide logout button
}
// Sign-up function
function signUp() {
const email = document.getElementById('email').value.trim();
const password = document.getElementById('password').value.trim();
if (email === '' || password === '') {
messageDiv.textContent = 'Error: All fields are required.';
messageDiv.style.color = 'red';
return;
}
if (!isValidEmail(email)) {
messageDiv.textContent = 'Error: Please enter a valid email address.';
messageDiv.style.color = 'red';
return;
}
if (password.length < 8) {
messageDiv.textContent = 'Error: Password must be at least 8 characters long.';
messageDiv.style.color = 'red';
return;
}
if (!isValidPassword(password)) {
messageDiv.textContent = 'Error: Password must include letters, numbers, and special characters.';
messageDiv.style.color = 'red';
return;
}
firebase.auth().createUserWithEmailAndPassword(email, password)
.then((userCredential) => {
messageDiv.textContent = 'Registered successfully!';
messageDiv.style.color = 'green';
})
.catch((error) => {
console.error("Error signing up:", error);
messageDiv.textContent = `Error: ${error.message}`;
messageDiv.style.color = 'red';
});
}
// Email/Password Login function
function submitForm() {
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
firebase.auth().signInWithEmailAndPassword(email, password)
.then((result) => {
console.log(result.user);
})
.catch((error) => {
console.error("Error with Email/Password login: ", error);
messageDiv.textContent = `Error: ${error.message}`;
messageDiv.style.color = 'red';
});
}
// Logout function
function logout() {
firebase.auth().signOut()
.then(() => console.log("User logged out"))
.catch((error) => console.error("Logout error:", error));
}
// Helper function to validate email format
function isValidEmail(email) {
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailPattern.test(email);
}
// Helper function for password complexity check
function isValidPassword(password) {
const passwordPattern = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
return passwordPattern.test(password);
}
// Google and Facebook Login
document.querySelector('.google').addEventListener('click', () => {
const provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider); // Use signInWithPopup
});
// Facebook Login function
document.getElementById('facebook-login-btn').addEventListener('click', () => {
const provider = new firebase.auth.FacebookAuthProvider();
provider.addScope('email');
provider.setCustomParameters({'display': 'popup'});
firebase.auth().signInWithPopup(provider)
.then((result) => {
const user = result.user;
updateUIForLoggedInUser(user);
})
.catch((error) => {
console.error("Facebook sign-in error:", error);
});
});
</script>
</body>
</html>