-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-admin.html
More file actions
330 lines (284 loc) Β· 11.4 KB
/
Copy pathsetup-admin.html
File metadata and controls
330 lines (284 loc) Β· 11.4 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Setup - LINQXFITNESS</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
margin: 0;
padding: 20px;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.setup-container {
background: rgba(255, 255, 255, 0.95);
border-radius: 20px;
padding: 40px;
max-width: 500px;
width: 100%;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
text-align: center;
}
.setup-container h1 {
color: #1e3a8a;
margin-bottom: 10px;
font-size: 2.5rem;
}
.setup-container p {
color: #6b7280;
margin-bottom: 30px;
font-size: 1.1rem;
}
.setup-btn {
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
color: white;
border: none;
padding: 15px 30px;
border-radius: 10px;
font-size: 1.1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
margin: 10px;
}
.setup-btn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}
.setup-btn:disabled {
background: #9ca3af;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
.status {
margin: 20px 0;
padding: 15px;
border-radius: 10px;
font-weight: 600;
}
.status.success {
background: #dcfce7;
color: #166534;
border: 1px solid #86efac;
}
.status.error {
background: #fee2e2;
color: #991b1b;
border: 1px solid #fca5a5;
}
.status.info {
background: #dbeafe;
color: #1e40af;
border: 1px solid #93c5fd;
}
.admin-credentials {
background: #fef3c7;
border: 2px solid #f59e0b;
border-radius: 10px;
padding: 20px;
margin: 20px 0;
text-align: left;
}
.admin-credentials h3 {
color: #92400e;
margin-top: 0;
}
.admin-credentials p {
margin: 8px 0;
color: #92400e;
font-weight: 600;
}
.admin-credentials code {
background: rgba(0, 0, 0, 0.1);
padding: 2px 6px;
border-radius: 4px;
font-family: monospace;
}
.navigation-links {
margin-top: 30px;
display: flex;
gap: 15px;
justify-content: center;
flex-wrap: wrap;
}
.nav-link {
background: rgba(59, 130, 246, 0.1);
color: #3b82f6;
padding: 10px 20px;
border-radius: 8px;
text-decoration: none;
font-weight: 600;
transition: all 0.3s ease;
border: 1px solid rgba(59, 130, 246, 0.2);
}
.nav-link:hover {
background: rgba(59, 130, 246, 0.2);
transform: translateY(-1px);
}
</style>
</head>
<body>
<div class="setup-container">
<h1>π Admin Setup</h1>
<p>Set up the default admin account for LINQXFITNESS</p>
<div id="statusDiv"></div>
<button id="setupBtn" class="setup-btn" onclick="setupAdminAccount()">
Create Admin Account
</button>
<div id="adminCredentials" class="admin-credentials" style="display: none;">
<h3>π Admin Account Created</h3>
<p><strong>Email:</strong> <code>admin@linoxfitness.com</code></p>
<p><strong>Password:</strong> <code>Admin123!</code></p>
<p><strong>Access:</strong> Full admin privileges</p>
</div>
<div class="navigation-links">
<a href="loginPage-firebase.html" class="nav-link">π Login Page</a>
<a href="admin-portal.html" class="nav-link">π Admin Portal</a>
<a href="home.html" class="nav-link">π Home Page</a>
</div>
</div>
<!-- Firebase CDN -->
<script type="module">
// Import Firebase modules
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js';
import { getAuth, createUserWithEmailAndPassword, updateProfile } from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js';
import { getFirestore, doc, setDoc, getDocs, query, where, collection } from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-firestore.js';
// Firebase configuration
const firebaseConfig = {
apiKey: "AQ.Ab8RN6KgqvLt8-m4-nu8_m9YwNxwJEPkY-2VQitKApmH9h4EAA",
authDomain: "linox-website.firebaseapp.com",
projectId: "linox-website",
storageBucket: "linox-website.firebasestorage.app",
messagingSenderId: "559179347351",
appId: "1:559179347351:web:1158b072023b4a7a6500d2",
measurementId: "G-FN0BHTE93G"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const db = getFirestore(app);
let setupComplete = false;
async function setupAdminAccount() {
const setupBtn = document.getElementById('setupBtn');
const statusDiv = document.getElementById('statusDiv');
const credentialsDiv = document.getElementById('adminCredentials');
if (setupComplete) {
showStatus('Admin account already exists!', 'info');
credentialsDiv.style.display = 'block';
return;
}
setupBtn.disabled = true;
setupBtn.textContent = 'Creating Admin Account...';
try {
showStatus('Creating admin account...', 'info');
// Check if admin account already exists
const adminQuery = query(collection(db, 'users'), where('email', '==', 'admin@linoxfitness.com'));
const adminSnapshot = await getDocs(adminQuery);
if (!adminSnapshot.empty) {
showStatus('Admin account already exists!', 'info');
credentialsDiv.style.display = 'block';
setupBtn.textContent = 'Admin Account Exists';
setupComplete = true;
return;
}
// Create admin user account
const userCredential = await createUserWithEmailAndPassword(auth, 'admin@linoxfitness.com', 'Admin123!');
const user = userCredential.user;
// Update user profile
await updateProfile(user, {
displayName: 'Admin User'
});
// Create admin user document in Firestore
const adminProfile = {
uid: user.uid,
firstName: 'Admin',
lastName: 'User',
email: 'admin@linoxfitness.com',
phone: '',
fitnessGoal: 'General Fitness',
experience: 'Advanced',
trainingLevel: 'Advanced',
goals: ['System Administration', 'User Management'],
isAdmin: true,
createdAt: new Date(),
lastLogin: null,
isActive: true,
profileComplete: true,
emergencyContact: {},
medicalInfo: {}
};
await setDoc(doc(db, 'users', user.uid), adminProfile);
// Create admin customer record
const adminCustomerData = {
firstName: 'Admin',
lastName: 'User',
email: 'admin@linoxfitness.com',
phone: '',
status: 'active',
trainingLevel: 'Advanced',
goals: ['System Administration'],
createdAt: new Date(),
updatedAt: new Date(),
isActive: true
};
await setDoc(doc(db, 'customers', user.uid), adminCustomerData);
showStatus('β
Admin account created successfully!', 'success');
credentialsDiv.style.display = 'block';
setupBtn.textContent = 'Admin Account Created';
setupBtn.disabled = true;
setupComplete = true;
} catch (error) {
console.error('Admin setup error:', error);
let errorMessage = 'Failed to create admin account. ';
if (error.code === 'auth/email-already-in-use') {
errorMessage += 'Admin account already exists.';
showStatus('Admin account already exists!', 'info');
credentialsDiv.style.display = 'block';
setupBtn.textContent = 'Admin Account Exists';
setupBtn.disabled = true;
setupComplete = true;
} else if (error.code === 'auth/weak-password') {
errorMessage += 'Password is too weak.';
} else if (error.code === 'auth/operation-not-allowed') {
errorMessage += 'Email/password accounts are not enabled.';
} else {
errorMessage += error.message;
}
showStatus('β ' + errorMessage, 'error');
setupBtn.disabled = false;
setupBtn.textContent = 'Create Admin Account';
}
}
function showStatus(message, type) {
const statusDiv = document.getElementById('statusDiv');
statusDiv.textContent = message;
statusDiv.className = `status ${type}`;
}
// Check if admin already exists on page load
document.addEventListener('DOMContentLoaded', async () => {
try {
const adminQuery = query(collection(db, 'users'), where('email', '==', 'admin@linoxfitness.com'));
const adminSnapshot = await getDocs(adminQuery);
if (!adminSnapshot.empty) {
showStatus('Admin account already exists!', 'info');
document.getElementById('adminCredentials').style.display = 'block';
document.getElementById('setupBtn').textContent = 'Admin Account Exists';
document.getElementById('setupBtn').disabled = true;
setupComplete = true;
}
} catch (error) {
console.log('Admin check:', error.message);
}
});
// Make setupAdminAccount globally available
window.setupAdminAccount = setupAdminAccount;
</script>
</body>
</html>