📄 Source: profile.php
<?php
require_once 'includes/config.php';
require_once 'includes/db.php';
require_once 'includes/auth.php';
require_once 'includes/functions.php';
requireLogin();
$user = getCurrentUser();
$error = '';
$success = '';
// Handle password change
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
if ($_POST['action'] === 'change_password') {
$currentPassword = $_POST['current_password'] ?? '';
$newPassword = $_POST['new_password'] ?? '';
$confirmPassword = $_POST['confirm_password'] ?? '';
// Verify current password
if (!password_verify($currentPassword, $user['password'])) {
$error = 'Current password is incorrect';
} elseif (strlen($newPassword) < 6) {
$error = 'New password must be at least 6 characters';
} elseif ($newPassword !== $confirmPassword) {
$error = 'Passwords do not match';
} else {
updateUser($user['id'], [
'password' => password_hash($newPassword, PASSWORD_DEFAULT)
]);
$success = 'Password updated successfully!';
// Refresh user data
$user = getCurrentUser();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Profile - <?php echo SITE_NAME; ?></title>
<link href="https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,300;400;500;600;700;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/style.css">
<style>
.profile-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1.5rem;
}
.profile-card {
background: var(--bg-card);
border-radius: 1.5rem;
padding: 1.5rem;
border: 1px solid var(--border-color);
box-shadow: var(--card-shadow);
}
.profile-card h3 {
margin-bottom: 1rem;
font-size: 1.1rem;
}
.profile-info {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.profile-info .label {
font-size: 0.8rem;
color: var(--text-secondary);
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.profile-info .value {
font-size: 1rem;
font-weight: 500;
padding: 0.5rem 0.8rem;
background: var(--code-bg);
border-radius: 0.5rem;
}
.link-btn {
display: inline-block;
padding: 0.5rem 1rem;
border-radius: 2rem;
text-decoration: none;
font-weight: 600;
font-size: 0.9rem;
transition: all 0.2s;
margin-top: 0.5rem;
}
.link-btn.discord {
background: #5865F2;
color: white;
}
.link-btn.discord:hover {
background: #4752c4;
}
.link-btn.google {
background: #EA4335;
color: white;
}
.link-btn.google:hover {
background: #d33426;
}
.link-btn.linked {
background: var(--success);
color: white;
cursor: default;
}
.link-btn.linked:hover {
opacity: 0.9;
}
.badge-connected {
display: inline-block;
padding: 0.2rem 0.6rem;
border-radius: 2rem;
font-size: 0.7rem;
background: var(--success);
color: white;
margin-left: 0.5rem;
}
.badge-not-connected {
display: inline-block;
padding: 0.2rem 0.6rem;
border-radius: 2rem;
font-size: 0.7rem;
background: var(--text-secondary);
color: white;
margin-left: 0.5rem;
}
.role-badge {
display: inline-block;
padding: 0.2rem 0.8rem;
border-radius: 2rem;
font-size: 0.7rem;
background: var(--warning);
color: white;
}
.role-badge.admin {
background: var(--error);
}
.role-badge.staff {
background: var(--info);
}
@media (max-width: 768px) {
.profile-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="theme-switcher">
<button class="theme-btn" data-theme="light" title="Light mode">☀️</button>
<button class="theme-btn" data-theme="dark" title="Dark mode">🌙</button>
</div>
<!-- Forums User Manages -->
<div class="profile-card" style="grid-column: 1 / -1;">
<h3>📊 Forums You Manage</h3>
<?php
$managedForums = getForumsByUser($user['id']);
if (empty($managedForums)):
?>
<p style="color: var(--text-secondary);">You don't manage any forums yet.</p>
<a href="create-forum.php" class="btn-primary" style="margin-top: 0.5rem; display: inline-block;">Create a Forum</a>
<?php else: ?>
<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 0.5rem; margin-top: 0.5rem;">
<?php foreach ($managedForums as $forum): ?>
<div style="background: var(--code-bg); padding: 0.8rem; border-radius: 0.5rem; border: 1px solid var(--border-color);">
<div style="font-weight: 600;"><?php echo htmlspecialchars($forum['title']); ?></div>
<div style="font-size: 0.8rem; color: var(--text-secondary);">
<?php if (isForumOwner($forum['id'], $user['id'])): ?>
<span class="owner-badge">👑 Owner</span>
<?php else: ?>
<span class="admin-badge">👔 Admin</span>
<?php endif; ?>
<?php echo count($forum['submissions']); ?> submissions
</div>
<a href="dashboard.php?forum_id=<?php echo $forum['id']; ?>" style="font-size: 0.8rem; color: var(--info);">Manage →</a>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<div class="container">
<header class="header">
<div class="header-top">
<h1>👤 My Profile</h1>
<div class="header-actions">
<a href="index.php" class="back-link">← Back</a>
<a href="my-applications.php" class="btn-secondary">📄 My Apps</a>
<?php if ($user['is_staff'] || $user['is_admin']): ?>
<a href="dashboard.php" class="btn-secondary">📊 Dashboard</a>
<?php endif; ?>
<?php if ($user['is_admin']): ?>
<a href="create-forum.php" class="btn-primary">➕ New Forum</a>
<?php endif; ?>
<a href="logout.php" class="btn-secondary" style="background: var(--error); color: white;">🚪 Logout</a>
</div>
</div>
<p class="subhead">Manage your account and linked services</p>
</header>
<?php if ($error): ?>
<div class="error-message">⚠️ <?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<?php if ($success): ?>
<div class="success-message">✅ <?php echo htmlspecialchars($success); ?></div>
<?php endif; ?>
<div class="profile-grid">
<!-- Account Info -->
<div class="profile-card">
<h3>📋 Account Information</h3>
<div class="profile-info">
<div>
<div class="label">Username</div>
<div class="value"><?php echo htmlspecialchars($user['username']); ?></div>
</div>
<div>
<div class="label">User ID</div>
<div class="value" style="font-size: 0.8rem; font-family: monospace;"><?php echo htmlspecialchars($user['id']); ?></div>
</div>
<div>
<div class="label">Account Type</div>
<div class="value">
<?php if ($user['is_admin']): ?>
<span class="role-badge admin">🔑 Admin</span>
<?php elseif ($user['is_staff']): ?>
<span class="role-badge staff">👔 Staff</span>
<?php else: ?>
<span class="role-badge">👤 User</span>
<?php endif; ?>
</div>
</div>
<div>
<div class="label">Account Created</div>
<div class="value"><?php echo htmlspecialchars($user['created_at']); ?></div>
</div>
</div>
</div>
<!-- Linked Accounts -->
<div class="profile-card">
<h3>🔗 Linked Accounts</h3>
<div class="profile-info">
<div>
<div class="label">Discord</div>
<div class="value">
<?php if (!empty($user['discord_id'])): ?>
✅ Connected
<span class="badge-connected">ID: <?php echo htmlspecialchars(substr($user['discord_id'], 0, 8)) . '...'; ?></span>
<?php if (!empty($user['discord_data'])):
$discordData = json_decode($user['discord_data'], true);
if ($discordData): ?>
<div style="font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.2rem;">
<?php echo htmlspecialchars($discordData['username'] ?? 'Unknown'); ?>#<?php echo htmlspecialchars($discordData['discriminator'] ?? '0000'); ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php else: ?>
❌ Not connected
<span class="badge-not-connected">Link your Discord</span>
<?php endif; ?>
</div>
<?php if (empty($user['discord_id'])): ?>
<a href="login.php?action=link&redirect=profile.php" class="link-btn discord">🔗 Link Discord Account</a>
<?php else: ?>
<div style="font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.3rem;">
Already linked. Use Discord to login anytime.
</div>
<?php endif; ?>
</div>
<div style="margin-top: 1rem;">
<div class="label">Google</div>
<div class="value">
<?php if (!empty($user['google_id'])): ?>
✅ Connected
<span class="badge-connected">ID: <?php echo htmlspecialchars(substr($user['google_id'], 0, 8)) . '...'; ?></span>
<?php else: ?>
❌ Not connected
<span class="badge-not-connected">Link your Google</span>
<?php endif; ?>
</div>
<?php if (empty($user['google_id'])): ?>
<a href="login.php?action=link&redirect=profile.php" class="link-btn google">🔗 Link Google Account</a>
<?php else: ?>
<div style="font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.3rem;">
Already linked. Use Google to login anytime.
</div>
<?php endif; ?>
</div>
</div>
</div>
<!-- Change Password -->
<div class="profile-card" style="grid-column: 1 / -1;">
<h3>🔐 Change Password</h3>
<form method="POST" action="">
<input type="hidden" name="action" value="change_password">
<div class="input-field">
<label>Current Password</label>
<input type="password" name="current_password" placeholder="Enter current password" required>
</div>
<div class="input-field">
<label>New Password</label>
<input type="password" name="new_password" placeholder="Min 6 characters" required minlength="6">
</div>
<div class="input-field">
<label>Confirm New Password</label>
<input type="password" name="confirm_password" placeholder="Re-enter new password" required>
</div>
<button type="submit" class="btn-primary">Update Password</button>
</form>
</div>
</div>
<footer class="footer">
<p>👤 Profile Management | <?php echo SITE_NAME; ?> v1.0</p>
</footer>
</div>
<script src="assets/script.js"></script>
</body>
</html>
← Back