9622f9aeca
Six fixes from a codebase review: - Consolidate the ad hoc install.php + migrate_v2..v6.php chain into one canonical schema.sql (structure reference) plus a simplified install.php that creates all tables and seeds site_settings, the superadmin account, and the standard prayer library. The six migrate_v*.php scripts are deleted — their cumulative effect is now fully captured in schema.sql. - Delete the two root-level setup.php/novena_group.php files that existed only to redirect to their admin/ equivalents of the same name; confirmed unreferenced by any link or .htaccess rule. - Decouple includes/build_slides.php from data/prayers.php's implicit `global $opening, $mysteries, ...` contract. data/prayers.php now explicitly returns its arrays; build_slides.php loads them through a small memoized get_prayer_data() and destructures them by key. - Add CSRF protection (includes/csrf.php: csrf_token/csrf_field/csrf_verify) across every POST-handling endpoint — 10 form pages and 7 API endpoints — plus token wiring in the JS/inline scripts that call the FormData- and JSON-body API endpoints (builder.js, setup.js, and the inline scripts in admin/audio.php, admin/novena_group.php, and index.php). - Stop round-tripping the SMTP password in plaintext through the settings form: the field now renders blank with a "currently set" hint, and a blank submission leaves the stored password unchanged instead of clearing it. - Add login rate-limiting: users.failed_login_attempts / locked_until columns, is_locked_out()/record_login_failure()/record_login_success() helpers in includes/auth.php, and lockout handling in login.php (5 failed attempts locks the account for 15 minutes). README documents the one manual ALTER TABLE needed to add these columns to an existing production database. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
89 lines
3.9 KiB
PHP
89 lines
3.9 KiB
PHP
<?php
|
|
require_once __DIR__ . '/config/db.php';
|
|
require_once __DIR__ . '/includes/mailer.php';
|
|
require_once __DIR__ . '/includes/csrf.php';
|
|
|
|
$sent = false;
|
|
$site_name = get_setting('site_name', APP_NAME);
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
csrf_verify();
|
|
$email = trim($_POST['email'] ?? '');
|
|
|
|
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$pdo = get_pdo();
|
|
$stmt = $pdo->prepare('SELECT id, display_name, username FROM users WHERE email = ? LIMIT 1');
|
|
$stmt->execute([$email]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user) {
|
|
$token = bin2hex(random_bytes(32));
|
|
$expires = date('Y-m-d H:i:s', strtotime('+1 hour'));
|
|
|
|
$pdo->prepare('UPDATE users SET reset_token = ?, reset_expires = ? WHERE id = ?')
|
|
->execute([$token, $expires, $user['id']]);
|
|
|
|
$site_url = rtrim(get_setting('site_url'), '/');
|
|
$link = $site_url . '/reset-password?token=' . urlencode($token);
|
|
$name = $user['display_name'] ?: $user['username'];
|
|
|
|
$body_html = "
|
|
<h2 style='margin-top:0;color:#1e3a5f'>Reset your password</h2>
|
|
<p>Hello, <strong>" . htmlspecialchars($name) . "</strong>!</p>
|
|
<p>We received a request to reset your password for your {$site_name} account.</p>
|
|
<p style='text-align:center;margin:28px 0'>
|
|
<a href='" . htmlspecialchars($link) . "' style='display:inline-block;background:#1e3a5f;color:#fff;padding:12px 28px;border-radius:6px;text-decoration:none;font-weight:600'>Reset Password</a>
|
|
</p>
|
|
<p style='color:#6b7280;font-size:13px'>This link expires in 1 hour.</p>
|
|
<p style='color:#6b7280;font-size:13px'>Or copy this link: " . htmlspecialchars($link) . "</p>
|
|
<p style='color:#6b7280;font-size:13px'>If you did not request a password reset, ignore this email.</p>
|
|
";
|
|
$html = email_template('Reset your password — ' . $site_name, $body_html);
|
|
send_email($email, $name, 'Reset your password — ' . $site_name, $html);
|
|
}
|
|
// Always show success to prevent email enumeration
|
|
}
|
|
$sent = true;
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<link rel="icon" type="image/svg+xml" href="<?= BASE_URL ?>/favicon.svg">
|
|
<title>Forgot Password — <?= htmlspecialchars($site_name) ?></title>
|
|
<link rel="stylesheet" href="<?= BASE_URL ?>/assets/css/setup.css">
|
|
</head>
|
|
<body class="login-page">
|
|
<div class="login-box">
|
|
<h1>✝ <?= htmlspecialchars($site_name) ?></h1>
|
|
<h2>Forgot Password</h2>
|
|
|
|
<?php if ($sent): ?>
|
|
<div class="alert alert-success">
|
|
If that email address exists in our system, you'll receive a password reset link shortly. Check your inbox.
|
|
</div>
|
|
<div style="margin-top:20px;text-align:center">
|
|
<a href="<?= BASE_URL ?>/login" class="btn btn-ghost">Back to Login</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<p style="color:#6b7280;margin-bottom:20px;font-size:14px">
|
|
Enter your email address and we'll send you a link to reset your password.
|
|
</p>
|
|
<form method="post" action="<?= BASE_URL ?>/forgot-password">
|
|
<?= csrf_field() ?>
|
|
<div class="form-group">
|
|
<label for="email">Email Address</label>
|
|
<input type="email" id="email" name="email" autofocus required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary btn-full">Send Reset Link</button>
|
|
</form>
|
|
<div style="margin-top:20px;text-align:center;font-size:14px">
|
|
<a href="<?= BASE_URL ?>/login" style="color:#1e3a5f">Back to Login</a>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</body>
|
|
</html>
|