diff --git a/ENV_TEMPLATE b/ENV_TEMPLATE
deleted file mode 100644
index f77e5d7..0000000
--- a/ENV_TEMPLATE
+++ /dev/null
@@ -1 +0,0 @@
-APIKEY=123
diff --git a/config.php b/config.php
index f28fb96..47318ab 100644
--- a/config.php
+++ b/config.php
@@ -1,11 +1,12 @@
$api_key);
- }else{
- return false;
+ if ($api_key) {
+ return $api_key;
+ } else {
+ // fallback hardcoded key for testing
+ return "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";
}
}
-?>
\ No newline at end of file
+?>
diff --git a/db.php b/db.php
index 4a29862..0e6fc12 100644
--- a/db.php
+++ b/db.php
@@ -1,10 +1,10 @@
+?>
-
-
AI Email Generator
-
Effortlessly craft polished, professional emails in seconds.
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+ 📧 Connected Accounts
+ Link your email provider to read & send directly:
+
+
+
+
+ 📥 Inbox
+ (This will show your connected emails once integration is done)
+
+ | From | Subject | Date | Action |
+
+ | Alice |
+ Hello about our meeting |
+ 2025-08-20 |
+ |
+
+
+ | Bob |
+ Invoice Reminder |
+ 2025-08-19 |
+ |
+
+
+
+
+
+
+
diff --git a/inc/css/style.css b/inc/css/style.css
index 2e5c45c..3ef02e0 100644
--- a/inc/css/style.css
+++ b/inc/css/style.css
@@ -176,4 +176,170 @@ button + button {
display: block;
width: 100%;
margin: 10px 0;
-}
\ No newline at end of file
+}
+
+/* Navbar styling */
+.navbar {
+ display: flex;
+ justify-content: space-between; /* logo left, links right */
+ align-items: center;
+ background-color: #fff;
+ padding: 15px 30px;
+ border-bottom: 1px solid #ddd;
+ box-shadow: 0 2px 4px rgba(0,0,0,0.05);
+}
+
+.navbar .logo {
+ font-size: 1.5em;
+ font-weight: bold;
+ color: #333;
+}
+
+.navbar .nav-links {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+ display: flex;
+ gap: 20px;
+}
+
+.navbar .nav-links li {
+ display: inline;
+}
+
+.navbar .nav-links a {
+ text-decoration: none;
+ color: #333;
+ font-weight: 500;
+ transition: color 0.2s ease;
+}
+
+.navbar .nav-links a:hover,
+.navbar .nav-links a.active {
+ color: #007bff; /* highlight */
+}
+
+.connect-buttons button {
+ margin: 8px;
+ padding: 10px 18px;
+ font-size: 14px;
+ border-radius: 8px;
+ border: none;
+ cursor: pointer;
+ background: #444;
+ color: #fff;
+ transition: background 0.2s;
+}
+
+.connect-buttons button:hover {
+ background: #666;
+}
+
+table.inbox {
+ width: 100%;
+ margin-top: 15px;
+ border-collapse: collapse;
+}
+
+table.inbox th, table.inbox td {
+ padding: 10px;
+ border-bottom: 1px solid #333;
+ text-align: left;
+}
+
+table.inbox tr:hover {
+ background: #222;
+}
+
+/* Dashboard Layout */
+.dashboard {
+ display: flex;
+ min-height: 100vh;
+}
+
+/* Sidebar */
+.sidebar {
+ width: 220px;
+ background: #111827; /* dark slate */
+ color: #fff;
+ padding: 20px;
+ display: flex;
+ flex-direction: column;
+}
+
+.sidebar .logo {
+ font-size: 20px;
+ font-weight: bold;
+ margin-bottom: 30px;
+ text-align: center;
+}
+
+.sidebar ul {
+ list-style: none;
+ padding: 0;
+ margin: 0;
+}
+
+.sidebar ul li {
+ margin: 15px 0;
+}
+
+.sidebar ul li a {
+ color: #d1d5db;
+ text-decoration: none;
+ font-size: 16px;
+ display: block;
+ padding: 8px;
+ border-radius: 8px;
+ transition: 0.2s;
+}
+
+.sidebar ul li a:hover {
+ background: #374151;
+ color: #fff;
+}
+
+/* Main Content */
+.main-content {
+ flex: 1;
+ padding: 40px;
+ background: #f3f4f6;
+}
+
+.dark-mode .main-content {
+ background: #1f2937;
+ color: #f3f4f6;
+}
+
+/* Force full-width flex layout */
+body, html {
+ margin: 0;
+ padding: 0;
+ height: 100%;
+}
+
+/* Dashboard wrapper */
+.dashboard {
+ display: flex;
+ min-height: 100vh;
+}
+
+/* Sidebar */
+.sidebar {
+ width: 220px;
+ background: #0f172a;
+ color: #fff;
+ padding: 20px;
+ margin: 0; /* REMOVE spacing */
+ position: fixed; /* Stick to left */
+ top: 0;
+ left: 0;
+ bottom: 0;
+}
+
+/* Main content area */
+.main-content {
+ margin-left: 220px; /* Push content to the right of sidebar */
+ padding: 30px;
+ flex: 1;
+}
diff --git a/inc/js/theme.js b/inc/js/theme.js
index 0feaa0e..11841ca 100644
--- a/inc/js/theme.js
+++ b/inc/js/theme.js
@@ -1,9 +1,61 @@
-document.addEventListener('DOMContentLoaded', () =>{
+document.addEventListener('DOMContentLoaded', () => {
+ // Dark mode toggle
const toggleBtn = document.getElementById('darkModeBtn');
- if(toggleBtn){
- toggleBtn.addEventListener('click', (e) =>{
+ if (toggleBtn) {
+ toggleBtn.addEventListener('click', (e) => {
e.preventDefault();
document.body.classList.toggle('dark-mode');
- })
+ });
}
-})
\ No newline at end of file
+
+ // Copy email button
+ const copyBtn = document.getElementById('copyBtn');
+ if (copyBtn) {
+ copyBtn.addEventListener('click', () => {
+ const text = document.getElementById('aiEmail')?.innerText;
+ if (text) {
+ if (navigator.clipboard && navigator.clipboard.writeText) {
+ // Modern way (requires HTTPS or localhost)
+ navigator.clipboard.writeText(text).then(() => {
+ showToast();
+ }).catch(err => {
+ alert("Failed to copy: " + err);
+ });
+ } else {
+ // Fallback for HTTP
+ const textarea = document.createElement('textarea');
+ textarea.value = text;
+ document.body.appendChild(textarea);
+ textarea.select();
+ document.execCommand('copy');
+ document.body.removeChild(textarea);
+ showToast();
+ }
+ }
+ });
+ }
+
+ // Save email button
+ const saveBtn = document.getElementById('saveBtn');
+ if (saveBtn) {
+ saveBtn.addEventListener('click', () => {
+ const text = document.getElementById('aiEmail')?.innerText;
+ if (text) {
+ const blob = new Blob([text], { type: 'text/plain' });
+ const link = document.createElement('a');
+ link.href = URL.createObjectURL(blob);
+ link.download = 'email.txt';
+ link.click();
+ }
+ });
+ }
+
+ // Toast helper
+ function showToast() {
+ const toast = document.getElementById('toast');
+ if (toast) {
+ toast.classList.add('show');
+ setTimeout(() => toast.classList.remove('show'), 2000);
+ }
+ }
+});
diff --git a/inc/php/auth.php b/inc/php/auth.php
index e8841cf..b47478c 100644
--- a/inc/php/auth.php
+++ b/inc/php/auth.php
@@ -1,24 +1,32 @@
prepare("SELECT id FROM users WHERE id = :id AND uniqueid = :uniqueid");
- $stmt->execute([
- 'id' => $_SESSION['user_id'],
- 'uniqueid' => $_SESSION['uniqueid'],
- ]);
+ try {
+ $conn = getConnection();
+ $stmt = $conn->prepare("SELECT id FROM users WHERE id = :id AND uniqueid = :uniqueid");
+ $stmt->execute([
+ 'id' => $_SESSION['user_id'],
+ 'uniqueid' => $_SESSION['uniqueid'],
+ ]);
- return $stmt->fetch() !== false;
+ return $stmt->fetch() !== false;
+ } catch (PDOException $e) {
+ return false; // fail safe
+ }
}
-if (!isAuthenticated()) {
- header("Location: /landing.php");
- exit();
+function requireLogin() {
+ if (!isAuthenticated()) {
+ header("Location: /landing.php");
+ exit();
+ }
}
-?>
diff --git a/inc/php/delete_email.php b/inc/php/delete_email.php
new file mode 100644
index 0000000..6928f3d
--- /dev/null
+++ b/inc/php/delete_email.php
@@ -0,0 +1,18 @@
+prepare("DELETE FROM saved_emails WHERE id = ? AND user_id = ?");
+$stmt->bind_param("ii", $id, $user_id);
+$stmt->execute();
+
+header("Location: /inc/php/saved.php?deleted=1");
+exit;
diff --git a/inc/php/generate.php b/inc/php/generate.php
new file mode 100644
index 0000000..92fc354
--- /dev/null
+++ b/inc/php/generate.php
@@ -0,0 +1,37 @@
+
+
+
+
+
+
diff --git a/inc/php/login.php b/inc/php/login.php
index ef91bd9..8ac94a9 100644
--- a/inc/php/login.php
+++ b/inc/php/login.php
@@ -1,5 +1,10 @@
success) {
- $errors[] = "CAPTCHA verification failed.";
- }
+ $ch = curl_init("https://www.google.com/recaptcha/api/siteverify");
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, [
+ 'secret' => $captcha_secret,
+ 'response' => $captcha,
+ 'remoteip' => $_SERVER['REMOTE_ADDR'] ?? null
+ ]);
- if (empty($errors)) {
- $conn = getConnection();
- $stmt = $conn->prepare("SELECT id, password, uniqueid FROM users WHERE email = :user OR username = :user");
- $stmt->execute(['user' => $user]);
- $result = $stmt->fetch();
+ $captcha_response = curl_exec($ch);
+ curl_close($ch);
- if ($result && password_verify($password, $result['password'])) {
- $_SESSION['user_id'] = $result['id'];
- $_SESSION['uniqueid'] = $result['uniqueid'];
- header("Location: /home.php");
- exit();
- } else {
- $errors[] = "Invalid credentials.";
+ $captcha_data = json_decode($captcha_response, true);
+ $captcha_success = !empty($captcha_data['success']);
}
}
+ if (!$captcha_success) {
+ $errors[] = "CAPTCHA verification failed.";
+ }
+
+ // 3. Authentication
+ if (empty($errors)) {
+ try {
+ $conn = getConnection();
+ $stmt = $conn->prepare("
+ SELECT id, username, password, uniqueid
+ FROM users
+ WHERE email = :email OR username = :username
+ LIMIT 1
+ ");
+ $stmt->execute([
+ 'email' => $user,
+ 'username' => $user
+ ]);
+ $result = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if ($result && password_verify($password, $result['password'])) {
+ // Regenerate session ID on login (security)
+ session_regenerate_id(true);
+
+ $_SESSION['user_id'] = $result['id'];
+ $_SESSION['username'] = $result['username'];
+ $_SESSION['uniqueid'] = $result['uniqueid'];
+
+ header("Location: /home.php");
+ exit;
+ } else {
+ $errors[] = "Invalid email/username or password.";
+ }
+ } catch (Exception $e) {
+ $errors[] = "Database error: " . $e->getMessage();
+ }
+ }
+
+ // If failed
$_SESSION['login_error'] = implode("
", $errors);
header("Location: /landing.php");
- exit();
+ exit;
}
?>
diff --git a/inc/php/register.php b/inc/php/register.php
index c7f15cb..3376356 100644
--- a/inc/php/register.php
+++ b/inc/php/register.php
@@ -9,11 +9,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = trim($_POST['email'] ?? '');
$confirm_email = trim($_POST['confirm_email'] ?? '');
$password = $_POST['password'] ?? '';
- $age = (int) ($_POST['age'] ?? 0);
+ $dob = $_POST['dob'] ?? ''; // from
$captcha = $_POST['g-recaptcha-response'] ?? '';
// Basic validation
- if (empty($username) || empty($email) || empty($confirm_email) || empty($password) || empty($age)) {
+ if (empty($username) || empty($email) || empty($confirm_email) || empty($password) || empty($dob)) {
$errors[] = "All fields are required.";
}
@@ -29,8 +29,27 @@ 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.";
+ // Date of Birth validation
+ if ($dob) {
+ try {
+ $birthDate = new DateTime($dob);
+ $today = new DateTime();
+
+ if ($birthDate > $today) {
+ $errors[] = "Date of birth cannot be in the future.";
+ }
+
+ if ($birthDate < new DateTime('1900-01-01')) {
+ $errors[] = "Please enter a valid birth year (1900 or later).";
+ }
+
+ $age = $today->diff($birthDate)->y;
+ if ($age < 16) {
+ $errors[] = "You must be at least 16 years old to register.";
+ }
+ } catch (Exception $e) {
+ $errors[] = "Invalid date of birth.";
+ }
}
// CAPTCHA validation
@@ -55,11 +74,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$hash = password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]);
$uniqueId = bin2hex(random_bytes(16));
- $insert = $conn->prepare("INSERT INTO users (username, email, password, uniqueid) VALUES (:username, :email, :password, :uniqueid)");
+ $insert = $conn->prepare("INSERT INTO users (username, email, password, dob, uniqueid)
+ VALUES (:username, :email, :password, :dob, :uniqueid)");
$insert->execute([
'username' => $username,
'email' => $email,
'password' => $hash,
+ 'dob' => $dob,
'uniqueid' => $uniqueId,
]);
diff --git a/inc/php/save_email.php b/inc/php/save_email.php
new file mode 100644
index 0000000..c5a7bdf
--- /dev/null
+++ b/inc/php/save_email.php
@@ -0,0 +1,39 @@
+prepare("
+ INSERT INTO saved_emails (user_id, subject, body, created_at)
+ VALUES (:user_id, :subject, :body, NOW())
+");
+
+if ($stmt->execute([
+ ':user_id' => $user_id,
+ ':subject' => $subject,
+ ':body' => $email_body
+])) {
+ header("Location: /home.php?success=1");
+ exit;
+} else {
+ $error = $stmt->errorInfo();
+ echo "Error saving email: " . $error[2];
+}
+
diff --git a/inc/php/view_email.php b/inc/php/view_email.php
new file mode 100644
index 0000000..4de765c
--- /dev/null
+++ b/inc/php/view_email.php
@@ -0,0 +1,33 @@
+prepare("SELECT subject, body, created_at FROM saved_emails WHERE id = ? AND user_id = ?");
+$stmt->bind_param("ii", $id, $user_id);
+$stmt->execute();
+$result = $stmt->get_result();
+$email = $result->fetch_assoc();
+
+include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/header.php');
+?>
+
+
+
+
+
= htmlspecialchars($email['subject'] ?: '(No Subject)') ?>
+
Saved on = $email['created_at'] ?>
+
= htmlspecialchars($email['body']) ?>
+
+
+
Email not found ❌
+
+
+
diff --git a/index.php b/index.php
index 2e1dc1f..5ed9bcc 100644
--- a/index.php
+++ b/index.php
@@ -1,37 +1,3 @@
-
-
-
AI Email Generator
-
-
-
-
-
+header("Location: /landing.php");
+exit();
diff --git a/landing.php b/landing.php
index cb06b73..5523982 100644
--- a/landing.php
+++ b/landing.php
@@ -9,74 +9,87 @@ include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/header.php');
+
+
-
AI Email Generator
+
AI Email Generator
-
-
+
+
+
+
diff --git a/process.php b/process.php
index d7fe7a7..e0298bb 100644
--- a/process.php
+++ b/process.php
@@ -1,21 +1,24 @@
'Write this email in a formal tone',
@@ -27,12 +30,11 @@
die('Invalid Input.');
}
- // Improved Prompt with strict language response
+ // Build prompt
$prompt = $allowedTones[$tone] . ". Transform this rough text into a polished, professional email in " . $language . ". ONLY reply in " . $language . ":\n\n" . $emailInput;
- // Prepare API request
+ // API call
$apiurl = 'https://api.openai.com/v1/chat/completions';
-
$data = [
'model' => 'gpt-3.5-turbo',
'messages' => [
@@ -47,7 +49,6 @@
'Authorization: Bearer ' . $apikey,
];
- // Make API request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -58,18 +59,31 @@
$response = curl_exec($ch);
curl_close($ch);
- // Handle response
$result = json_decode($response, true);
if (isset($result['choices'][0]['message']['content'])) {
- $aiEmail = htmlspecialchars($result['choices'][0]['message']['content']);
+ $aiEmail = trim($result['choices'][0]['message']['content']);
+ $safeEmail = htmlspecialchars($aiEmail);
+
echo "
Your AI-Generated Email:
";
echo "
";
- echo "
$aiEmail
";
+ echo "
$safeEmail
";
+
+ // Copy / Save / Navigation
echo "
";
echo "
";
- echo "
";
- echo "
← Generate Another Email";
+ echo "
";
+ echo "
← Generate Another Email";
+
+ // NEW: Save to DB form
+ if ($user_id) {
+ echo "
";
+ }
+
echo "
";
} else {
echo "Error: Failed to generate email. Try again later.";
@@ -81,7 +95,6 @@
-
diff --git a/saved_emails.php b/saved_emails.php
new file mode 100644
index 0000000..a864d76
--- /dev/null
+++ b/saved_emails.php
@@ -0,0 +1,46 @@
+prepare("
+ SELECT id, subject, body, created_at
+ FROM saved_emails
+ WHERE user_id = :user_id
+ ORDER BY created_at DESC
+");
+$stmt->execute([':user_id' => $user_id]);
+$emails = $stmt->fetchAll(PDO::FETCH_ASSOC);
+?>
+
+
+
+
+
+
📑 Saved Emails
+
+
+
+ | Subject | Preview | Date | Action |
+
+
+ | = htmlspecialchars($email['subject'] ?: '(No Subject)') ?> |
+ = htmlspecialchars(substr($email['body'], 0, 50)) ?>... |
+ = $email['created_at'] ?> |
+
+
+
+ |
+
+
+
+
+
No saved emails yet.
+
+
+