diff --git a/db.php b/db.php new file mode 100644 index 0000000..ef4cbff --- /dev/null +++ b/db.php @@ -0,0 +1,22 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, + ]; + + try { + return new PDO($dsn, $user, $pass, $options); + } catch (\PDOException $e) { + die("Database connection failed: " . $e->getMessage()); + } +} +?> diff --git a/home.php b/home.php index 3319270..826f2ed 100644 --- a/home.php +++ b/home.php @@ -1,4 +1,7 @@ - + +

AI Email Generator

diff --git a/inc/php/auth.php b/inc/php/auth.php new file mode 100644 index 0000000..42aa0f8 --- /dev/null +++ b/inc/php/auth.php @@ -0,0 +1,8 @@ + diff --git a/index.php b/index.php index e6aa82c..2e1dc1f 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,11 @@
@@ -19,13 +23,15 @@
- + diff --git a/landing.php b/landing.php new file mode 100644 index 0000000..44402bf --- /dev/null +++ b/landing.php @@ -0,0 +1,28 @@ + + +
+

Welcome to AI Email Generator

+

Craft professional emails in seconds. Please login or register to get started.

+ +
+ + +
+ +
+ +
+
+ + + diff --git a/login.php b/login.php new file mode 100644 index 0000000..c4e61ab --- /dev/null +++ b/login.php @@ -0,0 +1,29 @@ +prepare("SELECT id, username, password FROM Users WHERE email = ?"); + $stmt->execute([$email]); + $user = $stmt->fetch(); + + if ($user && password_verify($password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + $_SESSION['username'] = $user['username']; + header('Location: home.php'); + exit; + } else { + echo "Invalid credentials."; + } +} +?> + +
+ + + +
\ No newline at end of file diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..ca9c48c --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ + diff --git a/register.php b/register.php new file mode 100644 index 0000000..8a2bb2d --- /dev/null +++ b/register.php @@ -0,0 +1,36 @@ +prepare("SELECT id FROM Users WHERE email = ?"); + $stmt->execute([$email]); + if ($stmt->fetch()) { + die('Email already registered.'); + } + + $hashed = password_hash($password, PASSWORD_DEFAULT); + $stmt = $conn->prepare("INSERT INTO Users (username, email, password) VALUES (?, ?, ?)"); + $stmt->execute([$username, $email, $hashed]); + + header('Location: login.php'); + exit; +} +?> + +
+ + + + +
\ No newline at end of file