diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..2ba9fb9 --- /dev/null +++ b/dashboard.php @@ -0,0 +1,16 @@ + +
+ +

Welcome to your Dashboard

+

You are logged in as .

+ + diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..8a67627 --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,20 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + ]); + $pdo->exec("CREATE DATABASE IF NOT EXISTS ".DB_NAME); + echo "Database created successfully (if it didn't exist).\n"; + + // Now connect to the database and run migrations + $pdo = db(); + $sql = file_get_contents(__DIR__ . '/migrations/001_create_users_table.sql'); + $pdo->exec($sql); + echo "Migration successful!\n"; +} catch (PDOException $e) { + die("Migration failed: " . $e->getMessage() . "\n"); +} \ No newline at end of file diff --git a/db/migrations/001_create_users_table.sql b/db/migrations/001_create_users_table.sql new file mode 100644 index 0000000..16fc33d --- /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, + 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 37e25cc..54e1127 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,7 @@ -
- -
+
diff --git a/login.php b/login.php new file mode 100644 index 0000000..e43522b --- /dev/null +++ b/login.php @@ -0,0 +1,71 @@ +prepare("SELECT * FROM users WHERE email = ?"); + $stmt->execute([$email]); + $user = $stmt->fetch(); + + if ($user && password_verify($password, $user['password'])) { + session_start(); + $_SESSION['user_id'] = $user['id']; + $_SESSION['user_email'] = $user['email']; + header("Location: dashboard.php"); + exit; + } else { + $errors[] = 'Invalid email or password.'; + } + } catch (PDOException $e) { + $errors[] = "Database error: " . $e->getMessage(); + } + } +} + +require_once __DIR__ . '/partials/header.php'; +?> +
+ +
+
+
+
Login
+
+ +
Registration successful! Please login.
+ + +
+ +

+ +
+ +
+
+ + +
+
+ + +
+ +
+
+
+
+
+ + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..766a593 --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/partials/header.php b/partials/header.php new file mode 100644 index 0000000..7fa34f4 --- /dev/null +++ b/partials/header.php @@ -0,0 +1,11 @@ + + + + + + webCreatorSaas + + + + + \ No newline at end of file diff --git a/partials/navigation.php b/partials/navigation.php new file mode 100644 index 0000000..4bf5008 --- /dev/null +++ b/partials/navigation.php @@ -0,0 +1,28 @@ + + \ No newline at end of file diff --git a/register.php b/register.php new file mode 100644 index 0000000..66c4ae7 --- /dev/null +++ b/register.php @@ -0,0 +1,70 @@ +prepare("SELECT * FROM users WHERE email = ?"); + $stmt->execute([$email]); + if ($stmt->fetch()) { + $errors[] = 'Email already in use.'; + } else { + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + $stmt = $pdo->prepare("INSERT INTO users (email, password) VALUES (?, ?)"); + $stmt->execute([$email, $hashed_password]); + header("Location: login.php?registered=true"); + exit; + } + } catch (PDOException $e) { + $errors[] = "Database error: " . $e->getMessage(); + } + } +} + +require_once __DIR__ . '/partials/header.php'; +?> +
+ +
+
+
+
Register
+
+ +
+ +

+ +
+ +
+
+ + +
+
+ + +
+ +
+
+
+
+
+ +