diff --git a/db.php b/db.php index aed489c..4a29862 100644 --- a/db.php +++ b/db.php @@ -1,13 +1,13 @@ PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, diff --git a/home.php b/home.php index 826f2ed..3603299 100644 --- a/home.php +++ b/home.php @@ -1,4 +1,12 @@ - diff --git a/inc/css/style.css b/inc/css/style.css index 29f00e6..2e5c45c 100644 --- a/inc/css/style.css +++ b/inc/css/style.css @@ -151,3 +151,29 @@ button + button { white-space: pre-wrap; word-wrap: break-word; } + +.auth-box { + max-width: 400px; + margin: auto; + padding: 20px; + border-radius: 10px; + background: #fff; + transition: all 0.5s ease; + box-shadow: 0 0 10px rgba(0,0,0,0.1); +} +.auth-box.hidden { + display: none; +} +.auth-box h2 { + text-align: center; +} +.auth-box .error { + color: red; + text-align: center; + margin-bottom: 10px; +} +.auth-box input, .auth-box button { + display: block; + width: 100%; + margin: 10px 0; +} \ No newline at end of file diff --git a/inc/php/login.php b/inc/php/login.php index 55b4f10..ef91bd9 100644 --- a/inc/php/login.php +++ b/inc/php/login.php @@ -5,13 +5,23 @@ require_once($_SERVER['DOCUMENT_ROOT'] . '/db.php'); $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $user = trim($_POST['user'] ?? ''); - $password = $_POST['password'] ?? ''; + $user = trim($_POST['login_email'] ?? ''); + $password = $_POST['login_password'] ?? ''; + $captcha = $_POST['g-recaptcha-response'] ?? ''; if (empty($user) || empty($password)) { $errors[] = "All fields are required."; } + // CAPTCHA validation + $captcha_secret = '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe'; // Google's test secret key + $captcha_response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$captcha_secret}&response={$captcha}"); + $captcha_data = json_decode($captcha_response); + + if (!$captcha_data->success) { + $errors[] = "CAPTCHA verification failed."; + } + if (empty($errors)) { $conn = getConnection(); $stmt = $conn->prepare("SELECT id, password, uniqueid FROM users WHERE email = :user OR username = :user"); @@ -27,17 +37,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $errors[] = "Invalid credentials."; } } + + $_SESSION['login_error'] = implode("
", $errors); + header("Location: /landing.php"); + exit(); } ?> - - -

Login

-
-
-
- -
- - - - diff --git a/inc/php/register.php b/inc/php/register.php index 521ce61..c7f15cb 100644 --- a/inc/php/register.php +++ b/inc/php/register.php @@ -7,13 +7,20 @@ $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username = trim($_POST['username'] ?? ''); $email = trim($_POST['email'] ?? ''); + $confirm_email = trim($_POST['confirm_email'] ?? ''); $password = $_POST['password'] ?? ''; + $age = (int) ($_POST['age'] ?? 0); + $captcha = $_POST['g-recaptcha-response'] ?? ''; - // Validate inputs - if (empty($username) || empty($email) || empty($password)) { + // Basic validation + if (empty($username) || empty($email) || empty($confirm_email) || empty($password) || empty($age)) { $errors[] = "All fields are required."; } + if ($email !== $confirm_email) { + $errors[] = "Emails do not match."; + } + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors[] = "Invalid email format."; } @@ -22,10 +29,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $errors[] = "Password must be at least 6 characters."; } + if ($age < 16) { + $errors[] = "You must be at least 16 years old to register."; + } + + // CAPTCHA validation + $captcha_secret = '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe'; // Google's test secret key + $captcha_response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$captcha_secret}&response={$captcha}"); + $captcha_data = json_decode($captcha_response); + + if (!$captcha_data->success) { + $errors[] = "CAPTCHA verification failed."; + } + if (empty($errors)) { $conn = getConnection(); - // Check if email or username already exists + // Check for existing user $stmt = $conn->prepare("SELECT id FROM users WHERE email = :email OR username = :username"); $stmt->execute(['email' => $email, 'username' => $username]); @@ -33,7 +53,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $errors[] = "Email or username already in use."; } else { $hash = password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]); - $uniqueId = bin2hex(random_bytes(16)); // session ID + $uniqueId = bin2hex(random_bytes(16)); $insert = $conn->prepare("INSERT INTO users (username, email, password, uniqueid) VALUES (:username, :email, :password, :uniqueid)"); $insert->execute([ @@ -50,18 +70,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { exit(); } } + + $_SESSION['register_error'] = implode("
", $errors); + header("Location: /landing.php"); + exit(); } ?> - - -

Register

-
-
-
-
- -
- - - - diff --git a/landing.php b/landing.php index 44402bf..cb06b73 100644 --- a/landing.php +++ b/landing.php @@ -1,28 +1,83 @@ - - -
-

Welcome to AI Email Generator

-

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

- -
- - -
-
- -
+ + + + +
+

AI Email Generator

+ + +
+
+

Login

+ + +

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

Don't have an account? Register here

+
- + + +
+ + +