Compare commits

..

5 Commits

Author SHA1 Message Date
Flatlogic Bot
7651c67bc8 j 2025-10-14 13:50:20 +00:00
Flatlogic Bot
480576a9e7 login 2025-10-14 13:44:29 +00:00
Flatlogic Bot
0853753dc1 Auto commit: 2025-10-14T13:34:39.654Z 2025-10-14 13:34:39 +00:00
Flatlogic Bot
c6bb8383dc ok 2025-10-14 13:29:07 +00:00
Flatlogic Bot
3fffc4fb08 AI add 2025-10-14 13:27:03 +00:00
10 changed files with 702 additions and 140 deletions

272
assets/css/custom.css Normal file
View File

@ -0,0 +1,272 @@
html {
scroll-behavior: smooth;
}
body {
font-family: 'Inter', sans-serif;
background-color: #f8f9fa;
}
.hero {
background: linear-gradient(45deg, #007bff, #82b4ff);
color: white;
padding: 100px 0;
text-align: center;
}
.feature-item {
background-color: #ffffff;
padding: 30px;
border-radius: 0.5rem;
box-shadow: 0 4px 12px rgba(0,0,0,0.08);
transition: transform 0.2s ease-in-out;
height: 100%;
}
.feature-item:hover {
transform: translateY(-5px);
}
.feature-item svg {
color: #007bff;
}
.chat-widget {
position: fixed;
bottom: 20px;
right: 20px;
background-color: #007bff;
color: white;
width: 60px;
height: 60px;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
.chat-widget-container {
position: fixed;
bottom: 20px;
right: 20px;
}
.chat-window {
display: none;
position: fixed;
bottom: 100px;
right: 20px;
width: 350px;
max-width: 90vw;
background-color: white;
border-radius: 0.5rem;
box-shadow: 0 8px 24px rgba(0,0,0,0.15);
flex-direction: column;
}
.chat-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem;
border-bottom: 1px solid #eee;
background-color: #f8f9fa;
border-top-left-radius: 0.5rem;
border-top-right-radius: 0.5rem;
}
.chat-header h5 {
margin: 0;
font-size: 1.1rem;
}
.chat-body {
padding: 1rem;
overflow-y: auto;
height: 300px;
display: flex;
flex-direction: column;
gap: 0.75rem;
}
.message {
padding: 0.5rem 1rem;
border-radius: 1rem;
max-width: 80%;
word-wrap: break-word;
}
.user-message {
background-color: #007bff;
color: white;
align-self: flex-end;
border-bottom-right-radius: 0.25rem;
}
.bot-message {
background-color: #f1f1f1;
color: #333;
align-self: flex-start;
border-bottom-left-radius: 0.25rem;
}
.chat-footer {
display: flex;
padding: 1rem;
border-top: 1px solid #eee;
}
.chat-footer .form-control {
flex-grow: 1;
margin-right: 0.5rem;
}
.typing-indicator {
display: flex;
align-items: center;
padding: 1rem;
}
.typing-indicator span {
height: 8px;
width: 8px;
background-color: #999;
border-radius: 50%;
display: inline-block;
margin: 0 2px;
animation: bounce 1s infinite;
}
.typing-indicator span:nth-child(2) {
animation-delay: 0.1s;
}
.typing-indicator span:nth-child(3) {
animation-delay: 0.2s;
}
@keyframes bounce {
0%, 80%, 100% {
transform: scale(0);
}
40% {
transform: scale(1.0);
}
}
#speech-to-text-btn.listening {
background-color: #dc3545;
border-color: #dc3545;
}
/* Auth Page Styles */
.auth-container {
display: flex;
justify-content: center;
align-items: center;
min-height: 90vh;
padding: 2rem;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.auth-form {
background: rgba(255, 255, 255, 0.1);
padding: 2.5rem;
border-radius: 1rem;
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.18);
width: 100%;
max-width: 420px;
color: white;
}
.auth-form h2 {
text-align: center;
margin-bottom: 2rem;
font-weight: 600;
}
.auth-form .form-group {
margin-bottom: 1.5rem;
position: relative;
}
.auth-form label {
display: block;
margin-bottom: 0.5rem;
font-weight: 500;
}
.auth-form input[type="email"],
.auth-form input[type="password"] {
width: 100%;
padding: 1rem;
background: rgba(255, 255, 255, 0.2);
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 0.5rem;
color: white;
transition: background 0.3s, border-color 0.3s;
}
.auth-form input[type="email"]::placeholder,
.auth-form input[type="password"]::placeholder {
color: rgba(255, 255, 255, 0.7);
}
.auth-form input[type="email"]:focus,
.auth-form input[type="password"]:focus {
outline: none;
background: rgba(255, 255, 255, 0.3);
border-color: rgba(255, 255, 255, 0.5);
}
.auth-form .btn-submit {
width: 100%;
padding: 1rem;
background: #667eea;
color: white;
border: none;
border-radius: 0.5rem;
font-size: 1.1rem;
font-weight: 600;
cursor: pointer;
transition: background 0.3s;
}
.auth-form .btn-submit:hover {
background: #5a6fd8;
}
.auth-form .errors, .auth-form .success {
background: rgba(255, 82, 82, 0.9);
color: white;
padding: 1rem;
border-radius: 0.5rem;
margin-bottom: 1.5rem;
text-align: center;
}
.auth-form .success {
background: rgba(40, 167, 69, 0.9);
}
.auth-form .auth-link {
text-align: center;
margin-top: 1.5rem;
}
.auth-form .auth-link a {
color: #f0f0f0;
text-decoration: none;
font-weight: 500;
transition: color 0.3s;
}
.auth-form .auth-link a:hover {
color: white;
text-decoration: underline;
}

135
assets/js/main.js Normal file
View File

@ -0,0 +1,135 @@
document.addEventListener('DOMContentLoaded', function() {
const chatWidget = document.querySelector('.chat-widget');
const chatWindow = document.querySelector('.chat-window');
const closeButton = document.querySelector('.chat-header .btn-close');
const sendButton = document.querySelector('.chat-footer .btn-primary');
const messageInput = document.querySelector('.chat-footer .form-control');
const chatBody = document.querySelector('.chat-body');
if (chatWidget) {
chatWidget.addEventListener('click', function() {
if (chatWindow.style.display === 'flex') {
chatWindow.style.display = 'none';
} else {
chatWindow.style.display = 'flex';
}
});
}
if (closeButton) {
closeButton.addEventListener('click', function() {
chatWindow.style.display = 'none';
});
}
function getBotResponse(message) {
const lowerMessage = message.toLowerCase();
if (lowerMessage.includes('hello') || lowerMessage.includes('hi')) {
return 'Hello there! How can I assist you today?';
}
if (lowerMessage.includes('help')) {
return 'I can help with a variety of topics. What do you need assistance with? You can ask me about images or voice control.';
}
if (lowerMessage.includes('image')) {
return 'I can generate images, but that feature is not implemented yet. Stay tuned!';
}
if (lowerMessage.includes('voice')) {
return 'I can handle voice commands, but that feature is not implemented yet. Stay tuned!';
}
if (lowerMessage.includes('bye')) {
return 'Goodbye! Have a great day!';
}
return 'Thanks for your message! I am a simple bot. More advanced AI features are coming soon.';
}
function sendMessage() {
const messageText = messageInput.value.trim();
if (messageText === '') return;
// Add user message to chat body
const userMessage = document.createElement('div');
userMessage.classList.add('message', 'user-message');
userMessage.textContent = messageText;
chatBody.appendChild(userMessage);
// Clear input
messageInput.value = '';
// Scroll to bottom
chatBody.scrollTop = chatBody.scrollHeight;
// Show typing indicator
const typingIndicator = document.createElement('div');
typingIndicator.classList.add('message', 'bot-message', 'typing-indicator');
typingIndicator.innerHTML = '<span></span><span></span><span></span>';
chatBody.appendChild(typingIndicator);
chatBody.scrollTop = chatBody.scrollHeight;
// Bot reply
setTimeout(() => {
const botResponse = getBotResponse(messageText);
typingIndicator.remove();
const botMessage = document.createElement('div');
botMessage.classList.add('message', 'bot-message');
botMessage.textContent = botResponse;
chatBody.appendChild(botMessage);
chatBody.scrollTop = chatBody.scrollHeight;
}, 1000);
}
if (sendButton) {
sendButton.addEventListener('click', sendMessage);
}
if (messageInput) {
messageInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
sendMessage();
}
});
}
const speechToTextButton = document.getElementById('speech-to-text-btn');
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
if (SpeechRecognition) {
const recognition = new SpeechRecognition();
recognition.continuous = false;
recognition.lang = 'en-US';
recognition.interimResults = false;
recognition.maxAlternatives = 1;
speechToTextButton.addEventListener('click', () => {
recognition.start();
speechToTextButton.classList.add('listening');
speechToTextButton.disabled = true;
});
recognition.onresult = (event) => {
const transcript = event.results[0][0].transcript;
messageInput.value = transcript;
};
recognition.onspeechend = () => {
recognition.stop();
};
recognition.onend = () => {
speechToTextButton.classList.remove('listening');
speechToTextButton.disabled = false;
};
recognition.onerror = (event) => {
console.error('Speech recognition error:', event.error);
alert(`Error occurred in speech recognition: ${event.error}`);
speechToTextButton.classList.remove('listening');
speechToTextButton.disabled = false;
};
} else {
if (speechToTextButton) {
speechToTextButton.style.display = 'none';
}
console.log('Speech Recognition not supported in this browser.');
alert('Speech Recognition not supported in this browser.');
}
});

26
db/migrate.php Normal file
View File

@ -0,0 +1,26 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once 'config.php';
try {
$pdo = db();
$migrations = glob(__DIR__ . '/migrations/*.sql');
sort($migrations);
foreach ($migrations as $migration) {
$sql = file_get_contents($migration);
if ($sql) {
$pdo->exec($sql);
echo "Executed migration: " . basename($migration) . "<br>";
}
}
echo "All migrations executed successfully.<br>";
} catch (PDOException $e) {
header('HTTP/1.1 500 Internal Server Error');
die("Database migration failed: " . $e->getMessage());
}

View File

@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`google_id` varchar(255) DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

3
footer.php Normal file
View File

@ -0,0 +1,3 @@
</div>
</body>
</html>

10
header.php Normal file
View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My App</title>
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<div class="container">

219
index.php
View File

@ -1,150 +1,91 @@
<?php <?php
declare(strict_types=1); session_start();
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
$phpVersion = PHP_VERSION; if (!isset($_SESSION['user_id'])) {
$now = date('Y-m-d H:i:s'); header('Location: login.php');
exit;
}
?> ?>
<!doctype html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Style</title> <title>Hariom Dhakad</title>
<?php <meta name="description" content="Built with Flatlogic Generator">
// Read project preview data from environment <meta name="keywords" content="ai chat, customer support, image generation, voice to text, text to voice, flatlogic">
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? ''; <meta property="og:title" content="Hariom Dhakad">
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? ''; <meta property="og:description" content="Built with Flatlogic Generator">
?> <meta property="og:image" content="">
<?php if ($projectDescription): ?> <meta name="twitter:card" content="summary_large_image">
<!-- Meta description --> <meta name="twitter:image" content="">
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' /> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Open Graph meta tags --> <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap">
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" /> <link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<!-- Twitter meta tags -->
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<?php endif; ?>
<?php if ($projectImageUrl): ?>
<!-- Open Graph image -->
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<!-- Twitter image -->
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<?php endif; ?>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}
.loader {
margin: 1.25rem auto 1.25rem;
width: 48px;
height: 48px;
border: 3px solid rgba(255, 255, 255, 0.25);
border-top-color: #fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.hint {
opacity: 0.9;
}
.sr-only {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; border: 0;
}
h1 {
font-size: 3rem;
font-weight: 700;
margin: 0 0 1rem;
letter-spacing: -1px;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
}
code {
background: rgba(0,0,0,0.2);
padding: 2px 6px;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
footer {
position: absolute;
bottom: 1rem;
font-size: 0.8rem;
opacity: 0.7;
}
</style>
</head> </head>
<body> <body>
<main>
<div class="card"> <div class="hero">
<h1>Analyzing your requirements and generating your website…</h1> <div class="container">
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes"> <h1>Welcome to Your AI-Powered Assistant</h1>
<span class="sr-only">Loading…</span> <p class="lead">Ask questions, generate images, and interact with voice commands.</p>
<a href="#features" class="btn btn-light btn-lg">Get Started</a>
<a href="logout.php" class="btn btn-danger btn-lg">Logout</a>
</div> </div>
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
<p class="hint">This page will update automatically as the plan is implemented.</p>
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
</div> </div>
</main>
<footer> <div id="features" class="container mt-5 mb-5">
Page updated: <?= htmlspecialchars($now) ?> (UTC) <h2 class="text-center">Features</h2>
</footer> <div class="row text-center mt-4">
<div class="col-md-4">
<div class="feature-item">
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-message-circle"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"></path></svg>
<h5 class="mt-3">AI Chat</h5>
<p>Get instant answers from our smart chatbot.</p>
</div>
</div>
<div class="col-md-4">
<div class="feature-item">
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-image"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect><circle cx="8.5" cy="8.5" r="1.5"></circle><polyline points="21 15 16 10 5 21"></polyline></svg>
<h5 class="mt-3">Image Generation</h5>
<p>Create images from text descriptions.</p>
</div>
</div>
<div class="col-md-4">
<div class="feature-item">
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-mic"><path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"></path><path d="M19 10v2a7 7 0 0 1-14 0v-2"></path><line x1="12" y1="19" x2="12" y2="22"></line></svg>
<h5 class="mt-3">Voice Control</h5>
<p>Interact with the assistant using your voice.</p>
</div>
</div>
</div>
</div>
<div class="chat-widget-container">
<div class="chat-widget">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-message-square"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path></svg>
</div>
<div class="chat-window">
<div class="chat-header">
<h5>AI Assistant</h5>
<button class="btn-close" aria-label="Close"></button>
</div>
<div class="chat-body">
<div class="message bot-message">
Hello! How can I help you today?
</div>
</div>
<div class="chat-footer">
<input type="text" class="form-control" placeholder="Type a message...">
<button class="btn btn-secondary" id="speech-to-text-btn">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-mic"><path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"></path><path d="M19 10v2a7 7 0 0 1-14 0v-2"></path><line x1="12" y1="19" x2="12" y2="22"></line></svg>
</button>
<button class="btn btn-primary">Send</button>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body> </body>
</html> </html>

78
login.php Normal file
View File

@ -0,0 +1,78 @@
<?php
session_start();
require_once 'db/config.php';
$errors = [];
if (isset($_SESSION['user_id'])) {
header('Location: index.php');
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = 'A valid email is required.';
}
if (empty($password)) {
$errors[] = 'Password is required.';
}
if (empty($errors)) {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT id, password FROM users WHERE email = ?");
$stmt->execute([$email]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
header('Location: index.php');
exit;
} else {
$errors[] = 'Invalid email or password.';
}
} catch (PDOException $e) {
$errors[] = 'Database error: ' . $e->getMessage();
}
}
}
include 'header.php';
?>
<div class="auth-container">
<div class="auth-form">
<h2>Login</h2>
<?php if (!empty($errors)): ?>
<div class="errors">
<?php foreach ($errors as $error): ?>
<p><?php echo htmlspecialchars($error); ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<form action="login.php" method="post">
<div class="form-group">
<label for="email">Email</label>
<input type="email" name="email" id="email" required placeholder="you@example.com">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" id="password" required placeholder="••••••••">
</div>
<button type="submit" class="btn-submit">Login</button>
</form>
<p class="auth-link">Don't have an account? <a href="register.php">Register here</a>.</p>
</div>
</div>
<?php
include 'footer.php';
?>

7
logout.php Normal file
View File

@ -0,0 +1,7 @@
<?php
session_start();
session_unset();
session_destroy();
header('Location: login.php');
exit;
?>

81
register.php Normal file
View File

@ -0,0 +1,81 @@
<?php
session_start();
require_once 'db/config.php';
$errors = [];
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = 'A valid email is required.';
}
if (empty($password) || strlen($password) < 8) {
$errors[] = 'Password must be at least 8 characters long.';
}
if (empty($errors)) {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->fetch()) {
$errors[] = 'Email already exists.';
} else {
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (email, password) VALUES (?, ?)");
$stmt->execute([$email, $hashed_password]);
$success = 'Registration successful! You can now <a href="login.php">login</a>.';
}
} catch (PDOException $e) {
$errors[] = 'Database error: ' . $e->getMessage();
}
}
}
include 'header.php';
?>
<div class="auth-container">
<div class="auth-form">
<h2>Register</h2>
<?php if (!empty($errors)): ?>
<div class="errors">
<?php foreach ($errors as $error): ?>
<p><?php echo htmlspecialchars($error); ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if ($success): ?>
<div class="success">
<p><?php echo $success; ?></p>
</div>
<?php else: ?>
<form action="register.php" method="post">
<div class="form-group">
<label for="email">Email</label>
<input type="email" name="email" id="email" required placeholder="you@example.com">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" id="password" required placeholder="Minimum 8 characters">
</div>
<button type="submit" class="btn-submit">Register</button>
</form>
<?php endif; ?>
<p class="auth-link">Already have an account? <a href="login.php">Login here</a>.</p>
</div>
</div>
<?php
include 'footer.php';
?>