-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.html
More file actions
246 lines (220 loc) · 14.3 KB
/
settings.html
File metadata and controls
246 lines (220 loc) · 14.3 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Account Settings - Notify</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Poppins:wght@700&display=swap" rel="stylesheet">
<style>
body { font-family: 'Inter', sans-serif; }
.font-poppins { font-family: 'Poppins', sans-serif; }
.btn-bubbly { transition: transform 0.1s ease-out; }
.btn-bubbly:active { transform: scale(0.95); }
</style>
</head>
<body class="bg-gray-50 text-gray-800 antialiased min-h-screen flex flex-col">
<header class="bg-white border-b border-gray-200 shadow-sm sticky top-0 z-20">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between items-center py-3">
<a href="./dashboard.html" class="flex items-center space-x-4">
<svg class="w-8 h-8 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"></path></svg>
<h1 class="text-2xl font-bold text-gray-800">Notify</h1>
</a>
<a href="./dashboard.html" class="font-poppins inline-block bg-white text-gray-700 font-bold py-1 px-4 rounded-lg border border-gray-300 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors duration-150">
Dashboard
</a>
</div>
</div>
</header>
<main class="flex-grow flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
<div class="max-w-xl w-full space-y-8 bg-white p-8 rounded-xl shadow-md">
<div>
<h2 class="text-center text-3xl font-extrabold text-gray-900">
Account Settings
</h2>
<p class="mt-2 text-center text-sm text-gray-600">
Manage your profile and account credentials.
</p>
</div>
<div class="space-y-6">
<div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
<h3 class="text-lg font-semibold text-gray-800 mb-4">Update Username</h3>
<form id="update-username-form" class="space-y-4">
<div>
<label for="username" class="sr-only">New Username</label>
<input id="username-input" name="username" type="text" autocomplete="username" required class="appearance-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-md focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm" placeholder="New Username">
</div>
<button type="submit" class="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 btn-bubbly">
Update Username
</button>
</form>
<p id="username-error" class="text-red-500 text-sm text-center mt-2 hidden">Error updating username.</p>
</div>
<div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
<h3 class="text-lg font-semibold text-gray-800 mb-4">Change Password</h3>
<form id="change-password-form" class="space-y-4">
<div>
<label for="new-password" class="sr-only">New Password</label>
<input id="new-password-input" name="new-password" type="password" required class="appearance-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-md focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm" placeholder="New Password">
</div>
<div>
<label for="confirm-password" class="sr-only">Confirm Password</label>
<input id="confirm-password-input" name="confirm-password" type="password" required class="appearance-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-md focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm" placeholder="Confirm Password">
</div>
<button type="submit" class="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 btn-bubbly">
Change Password
</button>
</form>
<p id="password-error" class="text-red-500 text-sm text-center mt-2 hidden">Error changing password.</p>
</div>
<div class="bg-red-50 p-6 rounded-lg border border-red-200">
<h3 class="text-lg font-semibold text-red-800 mb-4">Danger Zone</h3>
<p class="text-sm text-red-700">Deleting your account is permanent. All your data will be erased and cannot be recovered.</p>
<button id="delete-account-btn" type="button" class="mt-4 group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-red-600 hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 btn-bubbly">
Delete Account
</button>
<p id="delete-error" class="text-red-500 text-sm text-center mt-2 hidden">Error deleting account.</p>
</div>
</div>
<p id="form-success" class="text-green-500 text-sm text-center mt-4 hidden">Changes saved successfully!</p>
</div>
</main>
<footer class="bg-white border-t border-gray-200 mt-auto">
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8 text-center text-gray-500">
<p>© 2025 Notify. A website created by 4simpleproblems.</p>
</div>
</footer>
<script src="https://www.gstatic.com/firebasejs/9.6.1/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.6.1/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.6.1/firebase-firestore-compat.js"></script>
<script src="../firebase-config.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const usernameForm = document.getElementById('update-username-form');
const passwordForm = document.getElementById('change-password-form');
const deleteBtn = document.getElementById('delete-account-btn');
const successMsg = document.getElementById('form-success');
const usernameError = document.getElementById('username-error');
const passwordError = document.getElementById('password-error');
const deleteError = document.getElementById('delete-error');
function onFirebaseReady(callback) {
const interval = setInterval(() => {
if (typeof firebase !== 'undefined' && typeof firebase.initializeApp === 'function' && typeof firebaseConfig !== 'undefined') {
clearInterval(interval);
callback();
}
}, 50);
}
onFirebaseReady(() => {
const app = firebase.initializeApp(firebaseConfig);
const auth = firebase.auth();
const db = firebase.firestore();
let currentUser = null;
auth.onAuthStateChanged(user => {
if (user) {
currentUser = user;
} else {
window.location.href = 'login.html';
}
});
function displayMessage(element, text) {
element.textContent = text;
element.classList.remove('hidden');
setTimeout(() => element.classList.add('hidden'), 3000);
}
// Update Username
usernameForm.addEventListener('submit', async (e) => {
e.preventDefault();
if (!currentUser) return;
const newUsername = document.getElementById('username-input').value.trim();
if (newUsername === '') {
displayMessage(usernameError, 'Username cannot be empty.');
return;
}
try {
await currentUser.updateProfile({
displayName: newUsername
});
await db.collection('users').doc(currentUser.uid).update({ username: newUsername });
displayMessage(successMsg, 'Username updated successfully!');
} catch (error) {
console.error("Error updating username:", error);
displayMessage(usernameError, 'Failed to update username. Please try again.');
}
});
// Change Password
passwordForm.addEventListener('submit', async (e) => {
e.preventDefault();
if (!currentUser) return;
const newPassword = document.getElementById('new-password-input').value;
const confirmPassword = document.getElementById('confirm-password-input').value;
if (newPassword.length < 6) {
displayMessage(passwordError, 'Password must be at least 6 characters long.');
return;
}
if (newPassword !== confirmPassword) {
displayMessage(passwordError, 'Passwords do not match.');
return;
}
try {
await currentUser.updatePassword(newPassword);
passwordForm.reset();
displayMessage(successMsg, 'Password changed successfully!');
} catch (error) {
console.error("Error changing password:", error);
if (error.code === 'auth/requires-recent-login') {
displayMessage(passwordError, 'Please log out and log back in to change your password.');
} else {
displayMessage(passwordError, 'Failed to change password. Please try again.');
}
}
});
// Delete Account
deleteBtn.addEventListener('click', async () => {
if (!currentUser) return;
if (confirm("Are you sure you want to delete your account? This action is permanent and cannot be undone.")) {
try {
// Find and delete all user-related data
await db.runTransaction(async t => {
const userDocRef = db.collection('users').doc(currentUser.uid);
t.delete(userDocRef);
// Find and delete username entry
const usernameQuery = await db.collection('usernames').where('uid', '==', currentUser.uid).get();
if (!usernameQuery.empty) {
t.delete(usernameQuery.docs[0].ref);
}
// Remove user from all classes
const classesQuery = await db.collection('classes').where('studentIds', 'array-contains', currentUser.uid).get();
classesQuery.forEach(doc => {
t.update(doc.ref, { studentIds: firebase.firestore.FieldValue.arrayRemove(currentUser.uid) });
});
// Delete all classes where user is the sole teacher/owner
const teacherClassesQuery = await db.collection('classes').where('teacherId', '==', currentUser.uid).get();
teacherClassesQuery.forEach(doc => {
t.delete(doc.ref);
});
});
// Delete the user from Firebase Auth
await currentUser.delete();
displayMessage(successMsg, 'Account deleted successfully!');
setTimeout(() => {
window.location.href = 'signup.html';
}, 2000);
} catch (error) {
console.error("Error deleting account:", error);
if (error.code === 'auth/requires-recent-login') {
displayMessage(deleteError, 'Please log out and log back in to delete your account.');
} else {
displayMessage(deleteError, 'Failed to delete account. Please try again.');
}
}
}
});
});
});
</script>
</body>
</html>