diff --git a/db/migrations/001_create_users_table.sql b/db/migrations/001_create_users_table.sql new file mode 100644 index 0000000..c375f13 --- /dev/null +++ b/db/migrations/001_create_users_table.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/index.php b/index.php index bb80f44..2c2525a 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,4 @@ + @@ -37,8 +38,19 @@ - - + + + + + + @@ -200,4 +212,4 @@ - \ No newline at end of file + diff --git a/login.php b/login.php index b11b795..cce8621 100644 --- a/login.php +++ b/login.php @@ -1,3 +1,46 @@ +prepare("SELECT * FROM users WHERE email = ?"); + $stmt->execute([$email]); + $user = $stmt->fetch(); + + if ($user && password_verify($password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + $_SESSION['user_name'] = $user['name']; + header("Location: index.php"); + exit; + } else { + $errors[] = 'Invalid email or password.'; + } + } catch (PDOException $e) { + $errors[] = 'Database error: ' . $e->getMessage(); + } + } +} +?> @@ -44,13 +87,20 @@

Login

-
+ +
+ +

+ +
+ +
- +
- +
@@ -78,4 +128,4 @@ - \ No newline at end of file + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..f83284d --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ +prepare("SELECT * FROM users WHERE email = ?"); + $stmt->execute([$email]); + if ($stmt->fetch()) { + $errors[] = 'Email already registered.'; + } else { + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + $stmt = $pdo->prepare("INSERT INTO users (name, email, password) VALUES (?, ?, ?)"); + if ($stmt->execute([$name, $email, $hashed_password])) { + $success = 'Registration successful! You can now login.'; + } else { + $errors[] = 'Something went wrong. Please try again later.'; + } + } + } catch (PDOException $e) { + $errors[] = 'Database error: ' . $e->getMessage(); + } + } +} +?> @@ -44,25 +94,37 @@

Create Account

- + +
+ +

+ +
+ + +
+

+
+ +
- +
- +
- +
- +
@@ -71,6 +133,7 @@
+