appscms-tools-theme 5.0.9 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/_includes/.DS_Store +0 -0
- data/_includes/appscms/.DS_Store +0 -0
- data/_includes/appscms/extras/ratings.html +196 -24
- data/_includes/appscms/scripts/script.html +0 -1
- data/assets/.DS_Store +0 -0
- data/assets/css/appscms-theme.css +267 -3
- data/assets/js/appscms-login.js +430 -283
- metadata +2 -3
- data/assets/js/appscms-auth.js +0 -9
data/assets/js/appscms-login.js
CHANGED
@@ -2,81 +2,155 @@ const profileButton = document.getElementById("profileButton");
|
|
2
2
|
const userModal = document.getElementById("userModal");
|
3
3
|
let isModalOpen = false;
|
4
4
|
|
5
|
-
profileButton
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
5
|
+
if (profileButton && userModal) {
|
6
|
+
profileButton.addEventListener("click", () => {
|
7
|
+
if (isModalOpen) {
|
8
|
+
userModal.style.display = "none";
|
9
|
+
isModalOpen = false;
|
10
|
+
} else {
|
11
|
+
userModal.style.display = "block";
|
12
|
+
isModalOpen = true;
|
13
|
+
}
|
14
|
+
});
|
15
|
+
|
16
|
+
// Close modal when clicking outside
|
17
|
+
document.addEventListener("click", (event) => {
|
18
|
+
if (
|
19
|
+
profileButton &&
|
20
|
+
userModal &&
|
21
|
+
!profileButton.contains(event.target) &&
|
22
|
+
!userModal.contains(event.target)
|
23
|
+
) {
|
24
|
+
userModal.style.display = "none";
|
25
|
+
isModalOpen = false;
|
26
|
+
}
|
27
|
+
});
|
28
|
+
}
|
29
|
+
|
25
30
|
// Get the modal elements
|
26
|
-
const
|
27
|
-
const
|
31
|
+
const sideModal = document.getElementById("sideModal");
|
32
|
+
const modalOverlayy = document.getElementById("modalOverlay");
|
28
33
|
const openModalBtn = document.querySelector(".open-modal-btn");
|
29
34
|
const closeModalBtn = document.querySelector(".close-modal-btn");
|
30
35
|
|
31
36
|
// Function to open the modal
|
32
37
|
function openModal() {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
if (modalOverlayy && sideModal) {
|
39
|
+
modalOverlayy.style.display = "block";
|
40
|
+
// Slight delay for the overlay to appear before the modal slides in
|
41
|
+
setTimeout(() => {
|
42
|
+
sideModal.style.right = "0";
|
43
|
+
}, 50);
|
44
|
+
}
|
38
45
|
}
|
39
46
|
|
40
47
|
// Function to close the modal
|
41
48
|
function closeModal() {
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
49
|
+
if (sideModal && modalOverlayy) {
|
50
|
+
sideModal.style.right = "-90%";
|
51
|
+
// Wait for the animation to complete before hiding the overlay
|
52
|
+
setTimeout(() => {
|
53
|
+
modalOverlayy.style.display = "none";
|
54
|
+
}, 300);
|
55
|
+
}
|
47
56
|
}
|
48
57
|
|
49
58
|
// Event listeners
|
50
|
-
openModalBtn
|
51
|
-
|
52
|
-
|
59
|
+
if (openModalBtn) {
|
60
|
+
openModalBtn.addEventListener("click", openModal);
|
61
|
+
}
|
62
|
+
|
63
|
+
if (closeModalBtn) {
|
64
|
+
closeModalBtn.addEventListener("click", closeModal);
|
65
|
+
}
|
66
|
+
|
67
|
+
if (modalOverlayy) {
|
68
|
+
modalOverlayy.addEventListener("click", closeModal);
|
69
|
+
}
|
53
70
|
|
54
71
|
// Prevent closing when clicking inside the modal
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
72
|
+
if (sideModal) {
|
73
|
+
sideModal.addEventListener("click", function (event) {
|
74
|
+
event.stopPropagation();
|
75
|
+
});
|
76
|
+
}
|
77
|
+
|
78
|
+
if (
|
79
|
+
window.location.pathname === "/profile" &&
|
80
|
+
document.querySelector(".login-button")
|
81
|
+
) {
|
59
82
|
document.querySelector(".login-button").addEventListener("click", openModal);
|
60
83
|
}
|
61
84
|
|
62
|
-
// Firebase configuration
|
85
|
+
// Firebase configuration
|
86
|
+
let firebaseConfig;
|
87
|
+
|
88
|
+
async function loadFirebaseConfig() {
|
89
|
+
try {
|
90
|
+
// Try to get config from Netlify function
|
91
|
+
const hostname = window.location.hostname;
|
92
|
+
const port = window.location.port;
|
93
|
+
|
94
|
+
let baseUrl = "";
|
95
|
+
|
96
|
+
// Development environment detection
|
97
|
+
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
98
|
+
// When running locally, we need to specify which port the Netlify Functions are running on
|
99
|
+
// Default Netlify CLI functions port is 8888, but could be 9000 or custom
|
100
|
+
baseUrl = "http://localhost:9000"; // Adjust this if your Netlify Functions are on a different port
|
101
|
+
}
|
102
|
+
|
103
|
+
// Make the request to the Netlify function with credentials included
|
104
|
+
|
105
|
+
const response = await fetch(
|
106
|
+
`http://localhost:9000/.netlify/functions/get-firebase-config`
|
107
|
+
);
|
108
|
+
|
109
|
+
if (response.ok) {
|
110
|
+
firebaseConfig = await response.json();
|
111
|
+
|
112
|
+
// Check if we got all required config fields
|
113
|
+
if (
|
114
|
+
firebaseConfig.apiKey &&
|
115
|
+
firebaseConfig.authDomain &&
|
116
|
+
firebaseConfig.projectId
|
117
|
+
) {
|
118
|
+
// Initialize Firebase with the config
|
119
|
+
if (typeof firebase !== "undefined") {
|
120
|
+
initializeFirebase();
|
121
|
+
} else {
|
122
|
+
console.error("Firebase SDK not loaded");
|
123
|
+
}
|
124
|
+
} else {
|
125
|
+
console.error("Incomplete Firebase configuration received");
|
126
|
+
}
|
127
|
+
} else {
|
128
|
+
console.error("Failed to load Firebase config:", response.status);
|
129
|
+
}
|
130
|
+
} catch (error) {
|
131
|
+
console.log(error);
|
132
|
+
console.error("Error loading Firebase config:", error);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
function initializeFirebase() {
|
137
|
+
if (!firebase.apps.length) {
|
138
|
+
firebase.initializeApp(firebaseConfig);
|
63
139
|
|
64
|
-
|
65
|
-
|
66
|
-
|
140
|
+
setupAuthListeners();
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
function setupAuthListeners() {
|
145
|
+
const auth = firebase.auth();
|
67
146
|
|
68
|
-
// Check for redirect result immediately when page loads
|
69
|
-
document.addEventListener("DOMContentLoaded", function () {
|
70
|
-
console.log("Checking for auth redirect...");
|
71
147
|
auth
|
72
148
|
.getRedirectResult()
|
73
149
|
.then((result) => {
|
74
150
|
if (result && result.user) {
|
75
|
-
console.log("Redirect authentication successful:", result.user);
|
76
151
|
// Twitter or other redirect login was successful
|
77
152
|
// Auth state observer will handle the UI update
|
78
153
|
} else if (result) {
|
79
|
-
console.log("Redirect completed but no user");
|
80
154
|
}
|
81
155
|
})
|
82
156
|
.catch((error) => {
|
@@ -85,265 +159,338 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
85
159
|
alert(`Authentication error: ${error.message}`);
|
86
160
|
}
|
87
161
|
});
|
88
|
-
});
|
89
|
-
|
90
|
-
// DOM Elements
|
91
|
-
const loginForm = document.getElementById("loginForm");
|
92
|
-
const signupForm = document.getElementById("signupForm");
|
93
|
-
const forgotPasswordForm = document.getElementById("forgotPasswordForm");
|
94
|
-
const authContainer = document.getElementById("authContainer");
|
95
|
-
const userAvatar = document.getElementById("userAvatar");
|
96
|
-
const profileUserAvatar = document.querySelector(".profile-user-avatar");
|
97
|
-
|
98
|
-
// Switch between login and signup
|
99
|
-
document.getElementById("showSignup").addEventListener("click", (e) => {
|
100
|
-
e.preventDefault();
|
101
|
-
loginForm.style.display = "none";
|
102
|
-
signupForm.style.display = "block";
|
103
|
-
forgotPasswordForm.style.display = "none";
|
104
|
-
});
|
105
|
-
|
106
|
-
document.getElementById("showLogin").addEventListener("click", (e) => {
|
107
|
-
e.preventDefault();
|
108
|
-
signupForm.style.display = "none";
|
109
|
-
loginForm.style.display = "block";
|
110
|
-
forgotPasswordForm.style.display = "none";
|
111
|
-
});
|
112
|
-
|
113
|
-
// Show forgot password form
|
114
|
-
document.getElementById("forgotPassword").addEventListener("click", (e) => {
|
115
|
-
e.preventDefault();
|
116
|
-
loginForm.style.display = "none";
|
117
|
-
forgotPasswordForm.style.display = "block";
|
118
|
-
});
|
119
|
-
|
120
|
-
// Back to login from forgot password
|
121
|
-
document.getElementById("backToLogin").addEventListener("click", () => {
|
122
|
-
forgotPasswordForm.style.display = "none";
|
123
|
-
loginForm.style.display = "block";
|
124
|
-
document.getElementById("resetSuccess").style.display = "none";
|
125
|
-
});
|
126
|
-
|
127
|
-
// Handle reset password form submission
|
128
|
-
document.getElementById("resetPasswordForm").addEventListener("submit", (e) => {
|
129
|
-
e.preventDefault();
|
130
|
-
const email = document.getElementById("resetEmail").value;
|
131
162
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
163
|
+
// DOM Elements
|
164
|
+
const loginForm = document.getElementById("loginForm");
|
165
|
+
const signupForm = document.getElementById("signupForm");
|
166
|
+
const forgotPasswordForm = document.getElementById("forgotPasswordForm");
|
167
|
+
const userAvatar = document.getElementById("userAvatar");
|
168
|
+
const profileUserAvatar = document.querySelector(".profile-user-avatar");
|
169
|
+
|
170
|
+
// Switch between login and signup
|
171
|
+
const showSignupBtn = document.getElementById("showSignup");
|
172
|
+
if (showSignupBtn) {
|
173
|
+
showSignupBtn.addEventListener("click", (e) => {
|
174
|
+
e.preventDefault();
|
175
|
+
if (loginForm) loginForm.style.display = "none";
|
176
|
+
if (signupForm) signupForm.style.display = "block";
|
177
|
+
if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
|
146
178
|
});
|
147
|
-
}
|
148
|
-
|
149
|
-
// Toggle password visibility
|
150
|
-
document.getElementById("toggleLoginPassword").addEventListener("click", () => {
|
151
|
-
const passwordInput = document.getElementById("loginPassword");
|
152
|
-
passwordInput.type = passwordInput.type === "password" ? "text" : "password";
|
153
|
-
});
|
154
|
-
|
155
|
-
document
|
156
|
-
.getElementById("toggleSignupPassword")
|
157
|
-
.addEventListener("click", () => {
|
158
|
-
const passwordInput = document.getElementById("signupPassword");
|
159
|
-
passwordInput.type =
|
160
|
-
passwordInput.type === "password" ? "text" : "password";
|
161
|
-
});
|
179
|
+
}
|
162
180
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
181
|
+
const showLoginBtn = document.getElementById("showLogin");
|
182
|
+
if (showLoginBtn) {
|
183
|
+
showLoginBtn.addEventListener("click", (e) => {
|
184
|
+
e.preventDefault();
|
185
|
+
if (signupForm) signupForm.style.display = "none";
|
186
|
+
if (loginForm) loginForm.style.display = "block";
|
187
|
+
if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
|
188
|
+
});
|
189
|
+
}
|
168
190
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
.catch((error) => {
|
177
|
-
alert(`Login error: ${error.message}`);
|
191
|
+
// Show forgot password form
|
192
|
+
const forgotPasswordBtn = document.getElementById("forgotPassword");
|
193
|
+
if (forgotPasswordBtn) {
|
194
|
+
forgotPasswordBtn.addEventListener("click", (e) => {
|
195
|
+
e.preventDefault();
|
196
|
+
if (loginForm) loginForm.style.display = "none";
|
197
|
+
if (forgotPasswordForm) forgotPasswordForm.style.display = "block";
|
178
198
|
});
|
179
|
-
}
|
199
|
+
}
|
180
200
|
|
181
|
-
//
|
182
|
-
document.getElementById("
|
183
|
-
|
184
|
-
|
185
|
-
|
201
|
+
// Back to login from forgot password
|
202
|
+
const backToLoginBtn = document.getElementById("backToLogin");
|
203
|
+
if (backToLoginBtn) {
|
204
|
+
backToLoginBtn.addEventListener("click", () => {
|
205
|
+
if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
|
206
|
+
if (loginForm) loginForm.style.display = "block";
|
207
|
+
const resetSuccess = document.getElementById("resetSuccess");
|
208
|
+
if (resetSuccess) resetSuccess.style.display = "none";
|
209
|
+
});
|
210
|
+
}
|
186
211
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
212
|
+
// Handle reset password form submission
|
213
|
+
const resetPasswordForm = document.getElementById("resetPasswordForm");
|
214
|
+
if (resetPasswordForm) {
|
215
|
+
resetPasswordForm.addEventListener("submit", (e) => {
|
216
|
+
e.preventDefault();
|
217
|
+
const resetEmail = document.getElementById("resetEmail");
|
218
|
+
if (!resetEmail) return;
|
219
|
+
|
220
|
+
const email = resetEmail.value;
|
221
|
+
|
222
|
+
// This is the correct way to set up redirects - Firebase will handle adding the continueUrl internally
|
223
|
+
const actionCodeSettings = {
|
224
|
+
url: "https://pdftoolkit-develop.netlify.app/",
|
225
|
+
handleCodeInApp: false,
|
226
|
+
};
|
227
|
+
|
228
|
+
auth
|
229
|
+
.sendPasswordResetEmail(email, actionCodeSettings)
|
230
|
+
.then(() => {
|
231
|
+
// Show success message
|
232
|
+
const resetSuccess = document.getElementById("resetSuccess");
|
233
|
+
if (resetSuccess) resetSuccess.style.display = "block";
|
234
|
+
resetPasswordForm.reset();
|
235
|
+
})
|
236
|
+
.catch((error) => {
|
237
|
+
alert(`Error: ${error.message}`);
|
238
|
+
});
|
196
239
|
});
|
197
|
-
}
|
240
|
+
}
|
198
241
|
|
199
|
-
//
|
200
|
-
document.getElementById("
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
alert(`Google login error: ${error.message}`);
|
242
|
+
// Toggle password visibility
|
243
|
+
const toggleLoginPassword = document.getElementById("toggleLoginPassword");
|
244
|
+
if (toggleLoginPassword) {
|
245
|
+
toggleLoginPassword.addEventListener("click", () => {
|
246
|
+
const passwordInput = document.getElementById("loginPassword");
|
247
|
+
if (passwordInput) {
|
248
|
+
passwordInput.type =
|
249
|
+
passwordInput.type === "password" ? "text" : "password";
|
250
|
+
}
|
209
251
|
});
|
210
|
-
}
|
252
|
+
}
|
211
253
|
|
212
|
-
document.getElementById("
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
.catch((error) => {
|
221
|
-
alert(`Google signup error: ${error.message}`);
|
254
|
+
const toggleSignupPassword = document.getElementById("toggleSignupPassword");
|
255
|
+
if (toggleSignupPassword) {
|
256
|
+
toggleSignupPassword.addEventListener("click", () => {
|
257
|
+
const passwordInput = document.getElementById("signupPassword");
|
258
|
+
if (passwordInput) {
|
259
|
+
passwordInput.type =
|
260
|
+
passwordInput.type === "password" ? "text" : "password";
|
261
|
+
}
|
222
262
|
});
|
223
|
-
}
|
263
|
+
}
|
224
264
|
|
225
|
-
//
|
226
|
-
document.getElementById("
|
227
|
-
|
228
|
-
|
265
|
+
// Email/Password Login
|
266
|
+
const emailLoginForm = document.getElementById("emailLoginForm");
|
267
|
+
if (emailLoginForm) {
|
268
|
+
emailLoginForm.addEventListener("submit", (e) => {
|
269
|
+
e.preventDefault();
|
270
|
+
const loginEmail = document.getElementById("loginEmail");
|
271
|
+
const loginPassword = document.getElementById("loginPassword");
|
272
|
+
if (!loginEmail || !loginPassword) return;
|
273
|
+
|
274
|
+
const email = loginEmail.value;
|
275
|
+
const password = loginPassword.value;
|
276
|
+
|
277
|
+
auth
|
278
|
+
.signInWithEmailAndPassword(email, password)
|
279
|
+
.then((userCredential) => {
|
280
|
+
// Signed in
|
281
|
+
const user = userCredential.user;
|
282
|
+
})
|
283
|
+
.catch((error) => {
|
284
|
+
alert(`Login error: ${error.message}`);
|
285
|
+
});
|
286
|
+
});
|
287
|
+
}
|
229
288
|
|
230
|
-
//
|
231
|
-
|
232
|
-
|
233
|
-
.
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
289
|
+
// Email/Password Signup
|
290
|
+
const emailSignupForm = document.getElementById("emailSignupForm");
|
291
|
+
if (emailSignupForm) {
|
292
|
+
emailSignupForm.addEventListener("submit", (e) => {
|
293
|
+
e.preventDefault();
|
294
|
+
const signupEmail = document.getElementById("signupEmail");
|
295
|
+
const signupPassword = document.getElementById("signupPassword");
|
296
|
+
if (!signupEmail || !signupPassword) return;
|
297
|
+
|
298
|
+
const email = signupEmail.value;
|
299
|
+
const password = signupPassword.value;
|
300
|
+
|
301
|
+
auth
|
302
|
+
.createUserWithEmailAndPassword(email, password)
|
303
|
+
.then((userCredential) => {
|
304
|
+
// Signed up
|
305
|
+
const user = userCredential.user;
|
306
|
+
})
|
307
|
+
.catch((error) => {
|
308
|
+
alert(`Signup error: ${error.message}`);
|
309
|
+
});
|
239
310
|
});
|
240
|
-
}
|
311
|
+
}
|
241
312
|
|
242
|
-
//
|
243
|
-
document.getElementById("
|
244
|
-
|
245
|
-
|
313
|
+
// Google Login
|
314
|
+
const googleLoginBtn = document.getElementById("googleLogin");
|
315
|
+
if (googleLoginBtn) {
|
316
|
+
googleLoginBtn.addEventListener("click", () => {
|
317
|
+
const provider = new firebase.auth.GoogleAuthProvider();
|
318
|
+
auth
|
319
|
+
.signInWithPopup(provider)
|
320
|
+
.then((result) => {})
|
321
|
+
.catch((error) => {
|
322
|
+
alert(`Google login error: ${error.message}`);
|
323
|
+
});
|
324
|
+
});
|
325
|
+
}
|
246
326
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
.
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
327
|
+
const googleSignupBtn = document.getElementById("googleSignup");
|
328
|
+
if (googleSignupBtn) {
|
329
|
+
googleSignupBtn.addEventListener("click", () => {
|
330
|
+
const provider = new firebase.auth.GoogleAuthProvider();
|
331
|
+
auth
|
332
|
+
.signInWithPopup(provider)
|
333
|
+
.then((result) => {})
|
334
|
+
.catch((error) => {
|
335
|
+
alert(`Google signup error: ${error.message}`);
|
336
|
+
});
|
337
|
+
});
|
338
|
+
}
|
339
|
+
|
340
|
+
// Facebook Login
|
341
|
+
const facebookLoginBtn = document.getElementById("facebookLogin");
|
342
|
+
if (facebookLoginBtn) {
|
343
|
+
facebookLoginBtn.addEventListener("click", () => {
|
344
|
+
const provider = new firebase.auth.FacebookAuthProvider();
|
345
|
+
provider.addScope("email");
|
346
|
+
|
347
|
+
// Try popup instead of redirect for Facebook
|
348
|
+
auth
|
349
|
+
.signInWithPopup(provider)
|
350
|
+
.then((result) => {})
|
351
|
+
.catch((error) => {
|
352
|
+
console.error("Facebook login error:", error);
|
353
|
+
alert(`Facebook login error: ${error.message}`);
|
354
|
+
});
|
355
|
+
});
|
356
|
+
}
|
357
|
+
|
358
|
+
// Twitter Login - Try using popup method first
|
359
|
+
const twitterLoginBtn = document.getElementById("twitterLogin");
|
360
|
+
if (twitterLoginBtn) {
|
361
|
+
twitterLoginBtn.addEventListener("click", () => {
|
362
|
+
const provider = new firebase.auth.TwitterAuthProvider();
|
363
|
+
|
364
|
+
try {
|
365
|
+
// Try popup method first as it provides better error feedback
|
366
|
+
auth
|
367
|
+
.signInWithPopup(provider)
|
368
|
+
.then((result) => {})
|
369
|
+
.catch((error) => {
|
370
|
+
console.error("Twitter popup error:", error);
|
371
|
+
|
372
|
+
// If popup fails, fallback to redirect
|
373
|
+
if (
|
374
|
+
error.code === "auth/popup-blocked" ||
|
375
|
+
error.code === "auth/popup-closed-by-user"
|
376
|
+
) {
|
377
|
+
auth.signInWithRedirect(provider).catch((redirectError) => {
|
378
|
+
console.error("Twitter redirect error:", redirectError);
|
379
|
+
alert(`Twitter login error: ${redirectError.message}`);
|
380
|
+
});
|
381
|
+
} else {
|
382
|
+
alert(`Twitter login error: ${error.message}`);
|
383
|
+
}
|
266
384
|
});
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
} catch (e) {
|
272
|
-
console.error("Exception during Twitter login:", e);
|
385
|
+
} catch (e) {
|
386
|
+
console.error("Exception during Twitter login:", e);
|
387
|
+
}
|
388
|
+
});
|
273
389
|
}
|
274
|
-
});
|
275
390
|
|
276
|
-
// Logout
|
277
|
-
document.getElementById("logoutBtn")
|
278
|
-
|
279
|
-
.
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
391
|
+
// Logout
|
392
|
+
const logoutBtn = document.getElementById("logoutBtn");
|
393
|
+
if (logoutBtn) {
|
394
|
+
logoutBtn.addEventListener("click", () => {
|
395
|
+
auth
|
396
|
+
.signOut()
|
397
|
+
.then(() => {
|
398
|
+
const userProfileHeader = document.querySelector(
|
399
|
+
".user-profile-header"
|
400
|
+
);
|
401
|
+
if (userProfileHeader) userProfileHeader.style.display = "none";
|
402
|
+
window.location.reload();
|
403
|
+
})
|
404
|
+
.catch((error) => {
|
405
|
+
alert(`Logout error: ${error.message}`);
|
406
|
+
});
|
287
407
|
});
|
288
|
-
}
|
408
|
+
}
|
409
|
+
|
410
|
+
// Auth state observer
|
411
|
+
auth.onAuthStateChanged((user) => {
|
412
|
+
if (user) {
|
413
|
+
const email = user.email || "No email available";
|
414
|
+
const loggedInUserEmail = document.querySelector(".logged-in-user-email");
|
415
|
+
if (loggedInUserEmail) loggedInUserEmail.textContent = email;
|
416
|
+
|
417
|
+
let displayName =
|
418
|
+
user.displayName || (user.email ? user.email.split("@")[0] : "User");
|
419
|
+
|
420
|
+
// Special handling for Twitter users who might not have email
|
421
|
+
if (
|
422
|
+
user.providerData[0].providerId === "twitter.com" &&
|
423
|
+
!user.displayName
|
424
|
+
) {
|
425
|
+
displayName = user.providerData[0].uid;
|
426
|
+
}
|
289
427
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
user ? "User logged in" : "User logged out"
|
295
|
-
);
|
428
|
+
if (sideModal) {
|
429
|
+
sideModal.style.display = "none";
|
430
|
+
sideModal.style.right = "-90%";
|
431
|
+
}
|
296
432
|
|
297
|
-
|
298
|
-
|
433
|
+
if (modalOverlayy) {
|
434
|
+
modalOverlayy.style.display = "none";
|
435
|
+
}
|
299
436
|
|
300
|
-
|
301
|
-
|
302
|
-
let displayName =
|
303
|
-
user.displayName || (user.email ? user.email.split("@")[0] : "User");
|
437
|
+
const loggedInUsername = document.querySelector(".logged-in-username");
|
438
|
+
if (loggedInUsername) loggedInUsername.textContent = displayName;
|
304
439
|
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
440
|
+
const loginModalButton = document.querySelector(".login-modal-button");
|
441
|
+
if (loginModalButton) loginModalButton.style.display = "none";
|
442
|
+
|
443
|
+
// Set initials for avatar
|
444
|
+
const initials = displayName
|
445
|
+
.split(" ")
|
446
|
+
.map((n) => n[0])
|
447
|
+
.join("")
|
448
|
+
.toUpperCase()
|
449
|
+
.substring(0, 2);
|
312
450
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
.
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
451
|
+
if (profileButton) profileButton.textContent = initials;
|
452
|
+
if (profileUserAvatar) profileUserAvatar.textContent = initials;
|
453
|
+
|
454
|
+
const userProfileHeader = document.querySelector(".user-profile-header");
|
455
|
+
if (userProfileHeader) userProfileHeader.style.display = "block";
|
456
|
+
|
457
|
+
if (userAvatar) {
|
458
|
+
userAvatar.textContent = initials;
|
459
|
+
userAvatar.style.display = "flex";
|
460
|
+
}
|
461
|
+
|
462
|
+
if (window.location.pathname === "/profile") {
|
463
|
+
const userProfileSection = document.querySelector(
|
464
|
+
".user-profile-section"
|
465
|
+
);
|
466
|
+
if (userProfileSection) userProfileSection.style.display = "flex";
|
467
|
+
|
468
|
+
const profileLoginContainer = document.querySelector(
|
469
|
+
".profile-login-container"
|
470
|
+
);
|
471
|
+
if (profileLoginContainer) profileLoginContainer.style.display = "none";
|
472
|
+
|
473
|
+
const avatarLarge = document.querySelector(".avatar-large");
|
474
|
+
if (avatarLarge) avatarLarge.textContent = initials;
|
475
|
+
|
476
|
+
const userEmailInput = document.querySelector("#user-email-input");
|
477
|
+
if (userEmailInput) userEmailInput.value = email;
|
478
|
+
|
479
|
+
const usernameInput = document.querySelector(".username-input");
|
480
|
+
if (usernameInput) usernameInput.value = displayName;
|
481
|
+
}
|
482
|
+
} else {
|
483
|
+
if (userAvatar) userAvatar.style.display = "none";
|
484
|
+
if (loginForm) loginForm.style.display = "block";
|
485
|
+
if (signupForm) signupForm.style.display = "none";
|
486
|
+
if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
|
342
487
|
}
|
343
|
-
}
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
}
|
488
|
+
});
|
489
|
+
}
|
490
|
+
|
491
|
+
// Initialize the app
|
492
|
+
if (document.readyState === "loading") {
|
493
|
+
document.addEventListener("DOMContentLoaded", loadFirebaseConfig);
|
494
|
+
} else {
|
495
|
+
loadFirebaseConfig();
|
496
|
+
}
|