Path : /home/vishqocm/pcib.in/
File Upload :
Current File : /home/vishqocm////pcib.in/verify_email.php

<?php
// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Start session
session_start();

// Include database configuration
require_once 'admin/database/db_config.php';

// Get site settings
$site_logo = 'assets/img/logo.png'; // Default logo
$site_name = 'Popular Computer';
$primary_color = '#4e73df';
$secondary_color = '#224abe';

// Try to fetch settings from database
try {
    $settings_query = "SELECT * FROM site_settings";
    $settings_result = $conn->query($settings_query);
    
    if ($settings_result && $settings_result->num_rows > 0) {
        while ($row = $settings_result->fetch_assoc()) {
            if ($row['setting_key'] == 'site_logo') {
                $site_logo = $row['setting_value'];
            } else if ($row['setting_key'] == 'site_name') {
                $site_name = $row['setting_value'];
            } else if ($row['setting_key'] == 'primary_color') {
                $primary_color = $row['setting_value'];
            } else if ($row['setting_key'] == 'secondary_color') {
                $secondary_color = $row['setting_value'];
            }
        }
    }
} catch (Exception $e) {
    error_log("Error fetching site settings: " . $e->getMessage());
}

// Initialize variables
$success = false;
$error = '';
$verified = false;

// Check if token and user ID are provided
if (isset($_GET['token']) && isset($_GET['id'])) {
    $token = mysqli_real_escape_string($conn, $_GET['token']);
    $user_id = intval($_GET['id']);
    
    // First check in user_verifications table
    $check_query = "SELECT * FROM user_verifications WHERE user_id = ? AND token = ?";
    $check_stmt = $conn->prepare($check_query);
    $check_stmt->bind_param("is", $user_id, $token);
    $check_stmt->execute();
    $result = $check_stmt->get_result();
    
    if ($result->num_rows > 0) {
        $verification = $result->fetch_assoc();
        
        // Check if token is expired
        if (isset($verification['expires_at']) && strtotime($verification['expires_at']) < time()) {
            $error = "Verification link has expired. Please request a new one.";
        } else {
            // Update user verification status
            $update_query = "UPDATE users SET email_verified = 1, status = CASE WHEN status = 'pending' THEN 'active' ELSE status END WHERE id = ?";
            $update_stmt = $conn->prepare($update_query);
            $update_stmt->bind_param("i", $user_id);
            
            if ($update_stmt->execute()) {
                // Delete verification token
                $delete_query = "DELETE FROM user_verifications WHERE user_id = ?";
                $delete_stmt = $conn->prepare($delete_query);
                $delete_stmt->bind_param("i", $user_id);
                $delete_stmt->execute();
                
                // Set success message
                $success = "Your email has been successfully verified. You can now login to your account.";
                $verified = true;
            } else {
                $error = "Failed to verify your email. Please try again or contact support.";
            }
        }
    } else {
        // For backward compatibility, check directly in users table
        $check_direct_query = "SELECT * FROM users WHERE id = ?";
        $check_direct_stmt = $conn->prepare($check_direct_query);
        $check_direct_stmt->bind_param("i", $user_id);
        $check_direct_stmt->execute();
        $direct_result = $check_direct_stmt->get_result();
        
        if ($direct_result->num_rows > 0) {
            $user = $direct_result->fetch_assoc();
            
            // Check if user is already verified
            if (isset($user['email_verified']) && $user['email_verified'] == 1) {
                $success = "Your email is already verified. You can login to your account.";
                $verified = true;
            } else {
                // Add email_verified column if it doesn't exist
                $alter_query = "ALTER TABLE users ADD COLUMN IF NOT EXISTS email_verified TINYINT(1) DEFAULT 0";
                $conn->query($alter_query);
                
                // Update user verification status
                $update_query = "UPDATE users SET email_verified = 1, status = CASE WHEN status = 'pending' THEN 'active' ELSE status END WHERE id = ?";
                $update_stmt = $conn->prepare($update_query);
                $update_stmt->bind_param("i", $user_id);
                
                if ($update_stmt->execute()) {
                    $success = "Your email has been successfully verified. You can now login to your account.";
                    $verified = true;
                } else {
                    $error = "Failed to verify your email. Please try again or contact support.";
                }
            }
        } else {
            $error = "Invalid verification link. Please check your email or contact support.";
        }
    }
} else {
    $error = "Invalid verification link. Please check your email or contact support.";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Email Verification - <?php echo htmlspecialchars($site_name); ?></title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        :root {
            --primary-color: <?php echo $primary_color; ?>;
            --secondary-color: <?php echo $secondary_color; ?>;
        }
        
        body {
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
            background-size: 400% 400%;
            animation: gradient 15s ease infinite;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            padding: 20px;
        }
        
        @keyframes gradient {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }
        
        .verification-container {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
            padding: 40px;
            width: 100%;
            max-width: 500px;
            text-align: center;
            backdrop-filter: blur(10px);
        }
        
        .verification-logo {
            margin-bottom: 30px;
        }
        
        .verification-logo img {
            max-height: 80px;
            animation: float 3s ease-in-out infinite;
        }
        
        @keyframes float {
            0% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
            100% { transform: translateY(0px); }
        }
        
        .verification-icon {
            font-size: 60px;
            margin-bottom: 20px;
        }
        
        .verification-icon.success {
            color: #28a745;
        }
        
        .verification-icon.error {
            color: #dc3545;
        }
        
        .verification-message {
            margin-bottom: 30px;
        }
        
        .verification-message h2 {
            margin-bottom: 15px;
            color: #333;
        }
        
        .verification-message p {
            color: #666;
        }
        
        .btn-login {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
            border: none;
            border-radius: 10px;
            padding: 12px 20px;
            font-weight: 600;
            color: white;
            text-decoration: none;
            display: inline-block;
            transition: all 0.3s ease;
        }
        
        .btn-login:hover {
            transform: translateY(-3px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            color: white;
        }
    </style>
</head>
<body>
    <div class="verification-container">
        <div class="verification-logo">
            <img src="<?php echo htmlspecialchars($site_logo); ?>" alt="<?php echo htmlspecialchars($site_name); ?> Logo">
        </div>
        
        <?php if ($verified): ?>
        <div class="verification-icon success">
            <i class="fas fa-check-circle"></i>
        </div>
        <div class="verification-message">
            <h2>Email Verified</h2>
            <p><?php echo htmlspecialchars($success); ?></p>
        </div>
        <a href="login.php" class="btn-login">
            <i class="fas fa-sign-in-alt me-2"></i> Login to Your Account
        </a>
        <?php else: ?>
        <div class="verification-icon error">
            <i class="fas fa-exclamation-circle"></i>
        </div>
        <div class="verification-message">
            <h2>Verification Failed</h2>
            <p><?php echo htmlspecialchars($error); ?></p>
        </div>
        <a href="login.php" class="btn-login">
            <i class="fas fa-arrow-left me-2"></i> Back to Login
        </a>
        <?php endif; ?>
    </div>
</body>
</html>