128 lines
6.5 KiB
PHP
128 lines
6.5 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
require_once 'mail/MailService.php';
|
|
|
|
$project_name = $_SERVER['PROJECT_NAME'] ?? 'LPA Online';
|
|
$error = '';
|
|
$success = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' || isset($_GET['email'])) {
|
|
$email = trim($_POST['email'] ?? $_GET['email'] ?? '');
|
|
|
|
if (empty($email)) {
|
|
$error = 'Please enter your email address.';
|
|
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$error = 'Please enter a valid email address.';
|
|
} else {
|
|
$db = db();
|
|
$stmt = $db->prepare('SELECT id, name, is_verified FROM users WHERE email = ?');
|
|
$stmt->execute([$email]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user) {
|
|
if ($user['is_verified'] == 1) {
|
|
$error = 'This account is already verified. You can log in now.';
|
|
} else {
|
|
$token = bin2hex(random_bytes(32));
|
|
$stmt = $db->prepare('UPDATE users SET verification_token = ? WHERE id = ?');
|
|
if ($stmt->execute([$token, $user['id']])) {
|
|
// Send verification email
|
|
$proto = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
|
|
$host = $_SERVER['HTTP_HOST'];
|
|
$verify_link = "$proto://$host/verify.php?token=$token";
|
|
|
|
$subject = "Verify your account - $project_name";
|
|
$html = "
|
|
<h1>Hello, " . htmlspecialchars($user['name']) . "!</h1>
|
|
<p>You requested a new verification link for $project_name. Please click the button below to verify your email address and activate your account:</p>
|
|
<p><a href='$verify_link' style='display:inline-block; padding:12px 24px; background-color:#007bff; color:#fff; text-decoration:none; border-radius:50px; font-weight:bold;'>Verify Email Address</a></p>
|
|
<p>If the button doesn't work, copy and paste this link into your browser:</p>
|
|
<p><a href='$verify_link'>$verify_link</a></p>
|
|
<p>Best regards,<br>The $project_name Team</p>
|
|
";
|
|
$text = "Hello, " . $user['name'] . "!\n\nPlease verify your email address by clicking this link: $verify_link\n\nBest regards,\nThe $project_name Team";
|
|
|
|
$res = MailService::sendMail($email, $subject, $html, $text);
|
|
|
|
if (!empty($res['success'])) {
|
|
$success = 'A new verification link has been sent to your email address.';
|
|
} else {
|
|
$error = 'We failed to send the verification email. Please try again later or contact support.';
|
|
error_log('Resend verification email failed: ' . ($res['error'] ?? 'unknown error'));
|
|
}
|
|
} else {
|
|
$error = 'Failed to generate a new token. Please try again.';
|
|
}
|
|
}
|
|
} else {
|
|
// We don't want to reveal if an email exists, but in this specific context (resend activation),
|
|
// it's usually okay or we can say "If an account exists, a link was sent".
|
|
// However, the original signup reveals it, so let's just say not found for simplicity here.
|
|
$error = 'No account found with this email address.';
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Resend Verification — <?php echo htmlspecialchars($project_name); ?></title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="assets/css/custom.css" rel="stylesheet">
|
|
</head>
|
|
<body class="bg-light d-flex flex-column min-vh-100">
|
|
<nav class="navbar navbar-expand-lg bg-white border-bottom shadow-sm">
|
|
<div class="container justify-content-center">
|
|
<a class="navbar-brand d-flex align-items-center m-0" href="/">
|
|
<img src="assets/pasted-20260228-235417-eedda424.png" alt="<?php echo htmlspecialchars($project_name); ?>" height="40">
|
|
</a>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container py-5 flex-grow-1 d-flex align-items-center">
|
|
<div class="row justify-content-center w-100 m-0">
|
|
<div class="col-md-6 col-lg-5">
|
|
<div class="card shadow-lg border-0 p-4 p-md-5 rounded-4">
|
|
<div class="text-center mb-4">
|
|
<h1 class="h3 fw-bold">Resend verification</h1>
|
|
<p class="text-muted small">Enter your email and we'll send you a new link.</p>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger small py-2"><?php echo htmlspecialchars($error); ?></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($success): ?>
|
|
<div class="alert alert-success small py-3 text-center">
|
|
<p class="mb-0"><?php echo htmlspecialchars($success); ?></p>
|
|
<a href="login.php" class="btn btn-sm btn-outline-success rounded-pill px-3 mt-3">Back to Login</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<form action="resend-verification.php" method="POST">
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label small fw-bold">Email Address</label>
|
|
<input type="email" class="form-control form-control-lg" id="email" name="email" placeholder="name@company.com" required value="<?php echo htmlspecialchars($_POST['email'] ?? $_GET['email'] ?? ''); ?>">
|
|
</div>
|
|
<button type="submit" class="btn btn-primary btn-lg w-100 rounded-pill">Resend Link</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
|
|
<div class="text-center mt-4 pt-2 border-top">
|
|
<p class="text-muted small mb-0">Remembered your password? <a href="login.php" class="text-primary text-decoration-none fw-semibold">Sign In</a></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<footer class="py-4 text-center text-muted">
|
|
<div class="container">
|
|
<p class="small mb-0">© <?php echo date('Y'); ?> <?php echo htmlspecialchars($project_name); ?>. All rights reserved.</p>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|