-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsettings.php
More file actions
348 lines (313 loc) · 14 KB
/
settings.php
File metadata and controls
348 lines (313 loc) · 14 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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Looma | Settings</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link href="style.css" rel="stylesheet">
<style>
/* Dark mode overrides */
[data-bs-theme="dark"] {
background-color: #1a1a1a;
color: #fff;
}
[data-bs-theme="dark"] .sidebar {
background-color: #2d2d2d;
color: #fff;
}
[data-bs-theme="dark"] .card {
background-color: #2d2d2d;
border-color: #444;
}
[data-bs-theme="dark"] .form-control {
background-color: #333;
color: #fff;
border-color: #555;
}
[data-bs-theme="dark"] .nav-link {
color: #fff;
}
[data-bs-theme="dark"] .nav-link.active {
background-color: #444;
}
</style>
</head>
<body data-bs-theme="<?php echo isset($user['theme']) ? $user['theme'] : 'light'; ?>">
<?php
session_start();
require_once 'includes/db.php';
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
// Security headers
header('X-Frame-Options: DENY');
header('X-Content-Type-Options: nosniff');
$user_id = $_SESSION['user_id'];
$password_alert = '';
// Fetch user data
$stmt = $conn->prepare('SELECT full_name, username FROM users WHERE user_id = ?');
if ($stmt === false) {
$password_alert = '<div class="alert alert-danger">Error: ' . htmlspecialchars($conn->error) . '</div>';
} else {
$stmt->bind_param('i', $user_id);
$stmt->execute();
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
}
// Handle Password Change
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['change_password'])) {
$current_password = $_POST['current_password'] ?? '';
$new_password = $_POST['new_password'] ?? '';
$confirm_password = $_POST['confirm_password'] ?? '';
if (empty($current_password) || empty($new_password) || empty($confirm_password)) {
$password_alert = '<div class="alert alert-danger">All password fields are required.</div>';
} elseif ($new_password !== $confirm_password) {
$password_alert = '<div class="alert alert-danger">New passwords do not match.</div>';
} elseif (strlen($new_password) < 8 || !preg_match('/[A-Z]/', $new_password) ||
!preg_match('/[0-9]/', $new_password) || !preg_match('/[!@#$%^&*]/', $new_password)) {
$password_alert = '<div class="alert alert-danger">Password must be at least 8 characters, include an uppercase letter, a number, and a special character.</div>';
} else {
$stmt = $conn->prepare('SELECT password FROM users WHERE user_id = ?');
if ($stmt === false) {
$password_alert = '<div class="alert alert-danger">Error: ' . htmlspecialchars($conn->error) . '</div>';
} else {
$stmt->bind_param('i', $user_id);
$stmt->execute();
$stored_password = $stmt->get_result()->fetch_assoc()['password'];
$stmt->close();
if (password_verify($current_password, $stored_password)) {
$new_password_hash = password_hash($new_password, PASSWORD_BCRYPT);
$stmt = $conn->prepare('UPDATE users SET password = ? WHERE user_id = ?');
if ($stmt === false) {
$password_alert = '<div class="alert alert-danger">Error: ' . htmlspecialchars($conn->error) . '</div>';
} else {
$stmt->bind_param('si', $new_password_hash, $user_id);
if ($stmt->execute()) {
$password_alert = '<div class="alert alert-success">Password updated successfully.</div>';
} else {
$password_alert = '<div class="alert alert-danger">Failed to update password.</div>';
}
$stmt->close();
}
} else {
$password_alert = '<div class="alert alert-danger">Current password is incorrect.</div>';
}
}
}
}
// Fetch user data
$stmt = $conn->prepare('SELECT full_name, username, theme FROM users WHERE user_id = ?');
?>
<!-- Desktop Sidebar -->
<div class="sidebar" id="sidebar">
<div class="sidebar-brand">
<h2>LOOMA</h2>
<p>Earn While You Play</p>
</div>
<nav class="nav flex-column">
<a href="index1.php" class="nav-link">
<i class="fas fa-home"></i>
<span>Dashboard</span>
</a>
<a href="games.php" class="nav-link">
<i class="fas fa-gamepad"></i>
<span>Games</span>
</a>
<a href="wallet1.php" class="nav-link">
<i class="fas fa-chart-line"></i>
<span>Earnings</span>
</a>
<a href="referrals.php" class="nav-link">
<i class="fas fa-users"></i>
<span>Referrals</span>
</a>
<a href="settings.php" class="nav-link active">
<i class="fas fa-cog"></i>
<span>Settings</span>
</a>
<a href="logout.php" class="nav-link">
<i class="fas fa-sign-out-alt"></i>
<span>Log out</span>
</a>
</nav>
<div class="sidebar-footer">
<p>© 2025 Looma</p>
</div>
</div>
<!-- Main Content -->
<div class="main-content" id="mainContent">
<!-- Top Navbar -->
<div class="top-navbar">
<h2>LOOMA</h2>
<div class="user-profile">
<div class="user-avatar"><?php echo htmlspecialchars(substr($user['full_name'], 0, 2)); ?></div>
<div>
<div class="fw-bold"><?php echo htmlspecialchars($user['username']); ?></div>
</div>
</div>
</div>
<!-- Settings Content -->
<div class="container">
<!-- Tabs Navigation -->
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="tab" href="#account">Account</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="tab" href="#appearance">Appearance</a>
</li>
</ul>
<div class="tab-content mt-3">
<!-- Account Tab -->
<div class="tab-pane fade show active" id="account">
<div class="card">
<div class="card-body">
<h4 class="card-title">Change Password</h4>
<?php echo $password_alert; ?>
<form id="password-form" method="POST">
<input type="hidden" name="change_password" value="1">
<div class="mb-3">
<label for="current_password" class="form-label">Current Password</label>
<input type="password" class="form-control" id="current_password" name="current_password" required minlength="8">
</div>
<div class="mb-3">
<label for="new_password" class="form-label">New Password</label>
<input type="password" class="form-control" id="new_password" name="new_password" required minlength="8">
</div>
<div class="mb-3">
<label for="confirm_password" class="form-label">Confirm New Password</label>
<input type="password" class="form-control" id="confirm_password" name="confirm_password" required minlength="8">
</div>
<div class="mb-3">
<small class="form-text text-muted">Password must be at least 8 characters, include an uppercase letter, a number, and a special character (!@#$%^&*).</small>
</div>
<button type="submit" class="btn btn-primary" id="password-submit">
Update Password
<span class="spinner spinner-border spinner-border-sm"></span>
</button>
</form>
</div>
</div>
</div>
<!-- Appearance Tab -->
<div class="tab-pane fade" id="appearance">
<div class="card">
<div class="card-body">
<h4 class="card-title">Theme Settings</h4>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="themeToggle"
<?php echo (isset($user['theme']) && $user['theme'] === 'dark') ? 'checked' : ''; ?>>
<label class="form-check-label" for="themeToggle">Dark Mode</label>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Mobile Bottom Navigation -->
<div class="mobile-bottom-nav">
<a href="index1.php" class="mobile-nav-item">
<i class="fas fa-home"></i>
<span>Home</span>
</a>
<a href="games.php" class="mobile-nav-item">
<i class="fas fa-gamepad"></i>
<span>Games</span>
</a>
<a href="wallet1.php" class="mobile-nav-item">
<i class="fas fa-wallet"></i>
<span>Earnings</span>
</a>
<a href="referrals.php" class="mobile-nav-item">
<i class="fas fa-users"></i>
<span>Refer</span>
</a>
<a href="settings.php" class="mobile-nav-item active">
<i class="fas fa-user"></i>
<span>Account</span>
</a>
<a href="logout.php" class="mobile-nav-item">
<i class="fas fa-sign-out-alt"></i>
<span>Log out</span>
</a>
</div>
<script>
// Toggle sidebar for desktop and mobile
function toggleSidebar() {
const sidebar = document.getElementById('sidebar');
const mainContent = document.getElementById('mainContent');
sidebar.classList.toggle('active');
mainContent.classList.toggle('main-content-expanded');
}
// Responsive navigation handling
function handleResize() {
const sidebar = document.getElementById('sidebar');
const mainContent = document.getElementById('mainContent');
if (window.innerWidth < 992) {
sidebar.classList.remove('active'); // Ensure sidebar is hidden on mobile
mainContent.classList.remove('main-content-expanded');
} else {
sidebar.classList.add('active'); // Show sidebar on desktop
mainContent.classList.remove('main-content-expanded');
}
}
window.addEventListener('resize', handleResize);
document.addEventListener('DOMContentLoaded', handleResize);
// Form Validation and Submission Handling
function showAlert(elementId, message, type) {
const alert = document.getElementById(elementId);
alert.className = `alert alert-${type}`;
alert.textContent = message;
alert.style.display = 'block';
setTimeout(() => (alert.style.display = 'none'), 5000);
}
function showSpinner(button, show) {
const spinner = button.querySelector('.spinner');
if (show) {
button.disabled = true;
spinner.style.display = 'inline-block';
} else {
button.disabled = false;
spinner.style.display = 'none';
}
}
document.getElementById('password-form').addEventListener('submit', function(event) {
const newPassword = document.getElementById('new_password').value;
const confirmPassword = document.getElementById('confirm_password').value;
const button = document.getElementById('password-submit');
if (newPassword !== confirmPassword) {
event.preventDefault();
showAlert('password-alert', 'Passwords do not match', 'danger');
return;
}
showSpinner(button, true);
setTimeout(() => showSpinner(button, false), 1000);
});
// Theme Toggle Handler
document.getElementById('themeToggle').addEventListener('change', function() {
const theme = this.checked ? 'dark' : 'light';
document.body.setAttribute('data-bs-theme', theme);
fetch('update_theme.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'theme=' + encodeURIComponent(theme)
})
.then(response => {
if (!response.ok) throw new Error('Failed to update theme');
})
.catch(error => {
console.error('Error:', error);
this.checked = !this.checked;S
document.body.setAttribute('data-bs-theme', this.checked ? 'dark' : 'light');
});
});
</script>
</body>
</html>