<?php
/**
 * Resend verification email
 * PHP User Registration - https://rskworld.in
 * Developer: Molla Samser | RSK World
 * Contact: help@rskworld.in | +91 93305 39277
 * Year: 2026
 */

require_once __DIR__ . '/includes/init.php';
require_once __DIR__ . '/includes/functions.php';
requireLogin();

$user = getCurrentUser();
if ($user !== null && empty($user['email_verified'])) {
    $pdo = getDbConnection();
    $token = generateVerificationToken();
    $expires = date('Y-m-d H:i:s', time() + 86400);
    $stmt = $pdo->prepare('UPDATE users SET verification_token = ?, token_expires_at = ? WHERE id = ?');
    $stmt->execute([$token, $expires, $user['id']]);
    sendVerificationEmail($user['email'], $user['name'], $token);
    setFlash('success', 'Verification email sent. Please check your inbox.');
}
header('Location: dashboard.php');
exit;
