This commit is contained in:
Flatlogic Bot 2025-10-14 13:44:29 +00:00
parent 0853753dc1
commit 480576a9e7
9 changed files with 309 additions and 1 deletions

View File

@ -160,3 +160,92 @@ body {
background-color: #dc3545; background-color: #dc3545;
border-color: #dc3545; border-color: #dc3545;
} }
/* Login Page Styles */
.login-container {
display: flex;
justify-content: center;
align-items: center;
min-height: 80vh;
padding: 2rem;
}
.login-form {
background-color: #ffffff;
padding: 2.5rem;
border-radius: 0.5rem;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
}
.login-form h2 {
text-align: center;
margin-bottom: 1.5rem;
color: #333;
}
.login-form .form-group {
margin-bottom: 1.5rem;
}
.login-form label {
display: block;
margin-bottom: 0.5rem;
color: #555;
font-weight: 500;
}
.login-form input[type="email"],
.login-form input[type="password"] {
width: 100%;
padding: 0.75rem;
border: 1px solid #ccc;
border-radius: 0.25rem;
transition: border-color 0.2s;
}
.login-form input[type="email"]:focus,
.login-form input[type="password"]:focus {
outline: none;
border-color: #007bff;
}
.login-form .btn-submit {
width: 100%;
padding: 0.75rem;
background-color: #007bff;
color: white;
border: none;
border-radius: 0.25rem;
font-size: 1rem;
cursor: pointer;
transition: background-color 0.2s;
}
.login-form .btn-submit:hover {
background-color: #0056b3;
}
.login-form .errors {
background-color: #f8d7da;
color: #721c24;
padding: 1rem;
border: 1px solid #f5c6cb;
border-radius: 0.25rem;
margin-bottom: 1.5rem;
}
.login-form .register-link {
text-align: center;
margin-top: 1.5rem;
}
.login-form .register-link a {
color: #007bff;
text-decoration: none;
}
.login-form .register-link a:hover {
text-decoration: underline;
}

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">

View File

@ -1,3 +1,11 @@
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@ -22,6 +30,7 @@
<h1>Welcome to Your AI-Powered Assistant</h1> <h1>Welcome to Your AI-Powered Assistant</h1>
<p class="lead">Ask questions, generate images, and interact with voice commands.</p> <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="#features" class="btn btn-light btn-lg">Get Started</a>
<a href="logout.php" class="btn btn-danger btn-lg">Logout</a>
</div> </div>
</div> </div>
@ -79,4 +88,4 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <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> <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="login-container">
<div class="login-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>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" id="password" required>
</div>
<button type="submit" class="btn-submit">Login</button>
</form>
<p class="register-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;
?>

77
register.php Normal file
View File

@ -0,0 +1,77 @@
<?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';
?>
<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>
<label for="email">Email</label>
<input type="email" name="email" id="email" required>
</div>
<div>
<label for="password">Password</label>
<input type="password" name="password" id="password" required>
</div>
<button type="submit">Register</button>
</form>
<?php endif; ?>
<p>Already have an account? <a href="login.php">Login here</a>.</p>
<?php
include 'footer.php';
?>