<?php
// Include database configuration
require_once 'db_config.php';
// Set up error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Display header
echo "<!DOCTYPE html>
<html>
<head>
<title>Creating Verification Tables</title>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; margin: 20px; }
h1 { color: #333; }
.success { color: green; }
.error { color: red; }
.info { color: blue; }
</style>
</head>
<body>
<h1>Creating Verification Tables</h1>";
try {
// Add email_verified column to users table if it doesn't exist
$check_column = $conn->query("SHOW COLUMNS FROM users LIKE 'email_verified'");
if ($check_column->num_rows == 0) {
$conn->query("ALTER TABLE users ADD COLUMN email_verified TINYINT(1) DEFAULT 0");
echo "<p class='success'>✅ Added email_verified column to users table.</p>";
} else {
echo "<p class='info'>ℹ️ email_verified column already exists in users table.</p>";
}
// Create user_verifications table if it doesn't exist
$check_table = $conn->query("SHOW TABLES LIKE 'user_verifications'");
if ($check_table->num_rows == 0) {
$sql = "CREATE TABLE user_verifications (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
token VARCHAR(255) NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
expires_at DATETIME,
INDEX (user_id),
INDEX (token),
UNIQUE (user_id, token)
)";
if ($conn->query($sql)) {
echo "<p class='success'>✅ Created user_verifications table.</p>";
} else {
throw new Exception("Failed to create user_verifications table: " . $conn->error);
}
} else {
echo "<p class='info'>ℹ️ user_verifications table already exists.</p>";
}
// Create password_resets table if it doesn't exist
$check_table = $conn->query("SHOW TABLES LIKE 'password_resets'");
if ($check_table->num_rows == 0) {
$sql = "CREATE TABLE password_resets (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
token VARCHAR(255) NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
expires_at DATETIME,
INDEX (user_id),
INDEX (token),
UNIQUE (user_id, token)
)";
if ($conn->query($sql)) {
echo "<p class='success'>✅ Created password_resets table.</p>";
} else {
throw new Exception("Failed to create password_resets table: " . $conn->error);
}
} else {
echo "<p class='info'>ℹ️ password_resets table already exists.</p>";
}
// Create oauth_providers table for social login
$check_table = $conn->query("SHOW TABLES LIKE 'oauth_providers'");
if ($check_table->num_rows == 0) {
$sql = "CREATE TABLE oauth_providers (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
provider VARCHAR(50) NOT NULL,
provider_user_id VARCHAR(255) NOT NULL,
email VARCHAR(255),
display_name VARCHAR(255),
profile_url VARCHAR(512),
photo_url VARCHAR(512),
access_token TEXT,
refresh_token TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX (user_id),
UNIQUE (provider, provider_user_id)
)";
if ($conn->query($sql)) {
echo "<p class='success'>✅ Created oauth_providers table for social login.</p>";
} else {
throw new Exception("Failed to create oauth_providers table: " . $conn->error);
}
} else {
echo "<p class='info'>ℹ️ oauth_providers table already exists.</p>";
}
echo "<p class='success'>✅ All verification tables have been created successfully!</p>";
} catch (Exception $e) {
echo "<p class='error'>❌ Error: " . $e->getMessage() . "</p>";
}
echo "
<p><a href='../index.php'>Back to Admin Dashboard</a></p>
</body>
</html>";