diff --git a/admin.php b/admin.php index 1a1cf7c..373afbf 100644 --- a/admin.php +++ b/admin.php @@ -1,6 +1,13 @@ My Awesome Blog Admin + Logout diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..6f6f98d --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,14 @@ +exec($sql); + echo "Migration 001: Users table created successfully.\n"; + } catch (PDOException $e) { + die("Migration 001 failed: " . $e->getMessage() . "\n"); + } +} + diff --git a/editor.php b/editor.php index 65eb820..f21a10b 100644 --- a/editor.php +++ b/editor.php @@ -1,6 +1,13 @@ null, 'title' => '', @@ -79,6 +86,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
My Awesome Blog Admin + Logout
diff --git a/index.php b/index.php index 410a073..3387fe7 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@
- © My Awesome Blog. All Rights Reserved. | Admin + © My Awesome Blog. All Rights Reserved. | + + Admin | Logout + + Login + +
diff --git a/login.php b/login.php new file mode 100644 index 0000000..1a0e3a6 --- /dev/null +++ b/login.php @@ -0,0 +1,89 @@ +prepare("SELECT * FROM users WHERE username = ?"); + $stmt->execute([$username]); + $user = $stmt->fetch(); + + if ($user && password_verify($password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + $_SESSION['username'] = $user['username']; + header("Location: admin.php"); + exit; + } else { + $error = 'Invalid username or password.'; + } + } catch (PDOException $e) { + $error = "Error: " . $e->getMessage(); + } + } +} +?> + + + + + + Login - My Blog + + + + + +
+
+

My Blog

+
+
+ +
+
+

Admin Login

+ + + +
+
+ + +
+
+ + +
+
+ + + Register + +
+
+
+
+ + + + + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..766a593 --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ +prepare("SELECT id FROM users WHERE username = ?"); + $stmt->execute([$username]); + if ($stmt->fetch()) { + $error = 'Username already exists.'; + } else { + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + $stmt = db()->prepare("INSERT INTO users (username, password) VALUES (?, ?)"); + $stmt->execute([$username, $hashed_password]); + $success = 'Registration successful! You can now log in.'; + } + } catch (PDOException $e) { + if ($e->getCode() === '42S02') { // Base table not found + $error = 'The application has not been fully set up. Please run the database migrations.'; + } else { + $error = "Error: " . $e->getMessage(); + } + } + } +} +?> + + + + + + Register - My Blog + + + + + +
+
+

My Blog

+
+
+ +
+
+

Create an Account

+ + + + + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + Login + +
+
+ +
+
+ + + + +