Auto commit: 2025-10-02T02:05:50.307Z
This commit is contained in:
parent
4ded33d0ad
commit
9636ae332b
42
dashboard.php
Normal file
42
dashboard.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// If the user is not logged in, redirect to the login page.
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$pageTitle = "Dashboard";
|
||||
include 'partials/header.php';
|
||||
?>
|
||||
|
||||
<div class="container my-5">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1 class="h2 fw-bold">Dashboard</h1>
|
||||
<a href="logout.php" class="btn btn-outline-secondary">Logout</a>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm mb-4">
|
||||
<div class="card-body p-4">
|
||||
<h2 class="h5">Welcome, <?php echo htmlspecialchars($_SESSION['user_name']); ?>!</h2>
|
||||
<p class="text-muted">You are logged in as <?php echo htmlspecialchars($_SESSION['user_email']); ?>.</p>
|
||||
<?php if ($_SESSION['user_role'] === 'admin'): ?>
|
||||
<span class="badge bg-primary">Administrator</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header">
|
||||
<h3 class="h5 mb-0">AI App Generator</h3>
|
||||
</div>
|
||||
<div class="card-body text-center p-5">
|
||||
<p class="lead">This is where the AI-powered application generator will be. <br>You'll be able to describe your app idea and see it come to life!</p>
|
||||
<button class="btn btn-primary btn-lg" disabled>Coming Soon</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<?php include 'partials/footer.php'; ?>
|
||||
32
database.sql
Normal file
32
database.sql
Normal file
@ -0,0 +1,32 @@
|
||||
--
|
||||
-- Database: `app_30908`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `contact_submissions`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `contact_submissions` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`email` VARCHAR(255) NOT NULL,
|
||||
`message` TEXT NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `users`
|
||||
--
|
||||
|
||||
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,
|
||||
`role` VARCHAR(50) NOT NULL DEFAULT 'user',
|
||||
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
@ -6,12 +6,40 @@ define('DB_USER', 'app_30908');
|
||||
define('DB_PASS', '98b730aa-be6c-479d-a47d-e5e7abc49229');
|
||||
|
||||
function db() {
|
||||
static $pdo;
|
||||
if (!$pdo) {
|
||||
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
}
|
||||
return $pdo;
|
||||
static $pdo;
|
||||
if (!$pdo) {
|
||||
try {
|
||||
$pdo = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
|
||||
// Create users table if it doesn't exist
|
||||
$pdo->exec("
|
||||
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,
|
||||
`role` VARCHAR(50) NOT NULL DEFAULT 'user',
|
||||
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
");
|
||||
|
||||
// Create a default admin user if one doesn't exist
|
||||
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
|
||||
$stmt->execute(['admin']);
|
||||
if ($stmt->fetchColumn() === false) {
|
||||
$stmt = $pdo->prepare("INSERT INTO users (name, email, password, role) VALUES (?, ?, ?, ?)");
|
||||
$stmt->execute(['Admin', 'admin', password_hash('admin123', PASSWORD_DEFAULT), 'admin']);
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
// If the database doesn't exist, this will fail.
|
||||
// This is a simple setup, so we'll just die.
|
||||
// In a real app, you'd have a proper installer.
|
||||
die("DB connection failed: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
69
index.php
69
index.php
@ -1,59 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<title>AI Web App Generator</title>
|
||||
<meta name="description" content="AI Web App Generator: Effortlessly create full-stack web apps with AI-driven design and modern tech stacks.">
|
||||
<meta name="keywords" content="ai web app generator, full-stack generator, react generator, node.js generator, database schema builder, crud generator, ai coding assistant, custom web application, low-code development, source code ownership, instant preview, automatic deployment">
|
||||
<?php
|
||||
$pageTitle = "Home";
|
||||
include 'partials/header.php';
|
||||
?>
|
||||
|
||||
<!-- Open Graph / Facebook -->
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:title" content="AI Web App Generator">
|
||||
<meta property="og:description" content="AI Web App Generator: Effortlessly create full-stack web apps with AI-driven design and modern tech stacks.">
|
||||
<meta property="og:image" content="https://project-screens.s3.amazonaws.com/screenshots/34578/app-hero-20251002-012850.png">
|
||||
|
||||
<!-- Twitter -->
|
||||
<meta property="twitter:card" content="summary_large_image">
|
||||
<meta property="twitter:title" content="AI Web App Generator">
|
||||
<meta property="twitter:description" content="AI Web App Generator: Effortlessly create full-stack web apps with AI-driven design and modern tech stacks.">
|
||||
<meta property="twitter:image" content="https://project-screens.s3.amazonaws.com/screenshots/34578/app-hero-20251002-012850.png">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&family=Georgia:wght@700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-lg navbar-light fixed-top">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="#">GenApp</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<li class="nav-item"><a class="nav-link" href="#features">Features</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#contact">Contact</a></li>
|
||||
<li class="nav-item"><a class="nav-link btn btn-primary text-white ms-lg-2" href="#">Get Started</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section class="hero text-center">
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-9">
|
||||
<h1 class="display-3 mb-3">Build Your Web App in Minutes, Not Months</h1>
|
||||
<p class="lead mb-4">Describe your vision. Our AI generates the full-stack code, from frontend to database. You own it all.</p>
|
||||
<a href="#" class="btn btn-primary btn-lg">Start Building for Free</a>
|
||||
<a href="register.php" class="btn btn-primary btn-lg">Start Building for Free</a>
|
||||
<a href="#features" class="btn btn-secondary btn-lg">Explore Features</a>
|
||||
</div>
|
||||
</div>
|
||||
@ -126,18 +82,5 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer class="text-center">
|
||||
<div class="container">
|
||||
<p class="mb-0">© <?php echo date("Y"); ?> GenApp. All rights reserved.</p>
|
||||
<p><a href="/privacy.php">Privacy Policy</a></p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<div id="toast-container" class="toast-container"></div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
<?php include 'partials/footer.php'; ?>
|
||||
88
login.php
Normal file
88
login.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
header("Location: dashboard.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$email = trim($_POST['email']);
|
||||
$password = $_POST['password'];
|
||||
|
||||
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[] = 'A valid email is required.';
|
||||
}
|
||||
if (empty($password)) {
|
||||
$errors[] = 'Password is required.';
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->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'];
|
||||
$_SESSION['user_email'] = $user['email'];
|
||||
$_SESSION['user_role'] = $user['role'];
|
||||
header("Location: dashboard.php");
|
||||
exit();
|
||||
} else {
|
||||
$errors[] = 'Invalid email or password.';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$pageTitle = "Login";
|
||||
include 'partials/header.php';
|
||||
?>
|
||||
|
||||
<div class="container my-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-5">
|
||||
<div class="card shadow-lg">
|
||||
<div class="card-body p-5">
|
||||
<h1 class="h3 fw-bold text-center mb-4">Log In to Your Account</h1>
|
||||
|
||||
<?php if (!empty($errors)):
|
||||
?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p class="mb-0"><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="login.php" method="POST" novalidate>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email Address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required value="<?php echo isset($_POST['email']) ? htmlspecialchars($_POST['email']) : 'admin'; ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required value="<?php echo isset($_POST['password']) ? '' : 'admin123'; ?>">
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary btn-lg">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
<div class="text-center mt-4">
|
||||
<p class="mb-0">Don't have an account? <a href="register.php">Register here</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'partials/footer.php'; ?>
|
||||
22
logout.php
Normal file
22
logout.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Unset all of the session variables.
|
||||
$_SESSION = [];
|
||||
|
||||
// If it's desired to kill the session, also delete the session cookie.
|
||||
// Note: This will destroy the session, and not just the session data!
|
||||
if (ini_get("session.use_cookies")) {
|
||||
$params = session_get_cookie_params();
|
||||
setcookie(session_name(), '', time() - 42000,
|
||||
$params["path"], $params["domain"],
|
||||
$params["secure"], $params["httponly"]
|
||||
);
|
||||
}
|
||||
|
||||
// Finally, destroy the session.
|
||||
session_destroy();
|
||||
|
||||
// Redirect to the homepage.
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
41
partials/footer.php
Normal file
41
partials/footer.php
Normal file
@ -0,0 +1,41 @@
|
||||
</main>
|
||||
|
||||
<footer class="footer-main bg-light py-5 mt-auto">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3 mb-md-0">
|
||||
<h5 class="fw-bold">AI Web App Generator</h5>
|
||||
<p class="text-muted">Create, customize, and deploy full-stack web applications using the power of AI.</p>
|
||||
</div>
|
||||
<div class="col-md-3 col-6">
|
||||
<h6 class="text-uppercase fw-bold">Links</h6>
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="index.php#features" class="text-muted text-decoration-none">Features</a></li>
|
||||
<li><a href="privacy.php" class="text-muted text-decoration-none">Privacy Policy</a></li>
|
||||
<li><a href="index.php#contact" class="text-muted text-decoration-none">Contact</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-md-3 col-6">
|
||||
<h6 class="text-uppercase fw-bold">Account</h6>
|
||||
<ul class="list-unstyled">
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<li><a href="dashboard.php" class="text-muted text-decoration-none">Dashboard</a></li>
|
||||
<li><a href="logout.php" class="text-muted text-decoration-none">Logout</a></li>
|
||||
<?php else: ?>
|
||||
<li><a href="login.php" class="text-muted text-decoration-none">Login</a></li>
|
||||
<li><a href="register.php" class="text-muted text-decoration-none">Register</a></li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<hr class="my-4">
|
||||
<div class="text-center text-muted">
|
||||
<p>© <?php echo date("Y"); ?> AI Web App Generator. All rights reserved.</p>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
56
partials/header.php
Normal file
56
partials/header.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?php echo isset($pageTitle) ? htmlspecialchars($pageTitle) . ' - ' : ''; ?>AI Web App Generator</title>
|
||||
<meta name="description" content="Generate full-stack web applications from a text prompt.">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&family=Georgia:wght@700&display=swap" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header class="header-main sticky-top">
|
||||
<nav class="navbar navbar-expand-lg">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="index.php">AI Web App Generator</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto align-items-center">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="index.php#features">Features</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="index.php#contact">Contact</a>
|
||||
</li>
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="dashboard.php">Dashboard</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="logout.php" class="btn btn-outline-secondary ms-2">Logout</a>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="login.php">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="register.php" class="btn btn-primary ms-2">Register</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
57
privacy.php
57
privacy.php
@ -1,28 +1,35 @@
|
||||
<?php
|
||||
http_response_code(501); // Not Implemented
|
||||
$pageTitle = "Privacy Policy";
|
||||
include 'partials/header.php';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Privacy Policy</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
flex-direction: column;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container text-center">
|
||||
<h1 class="display-4">Privacy Policy</h1>
|
||||
<p class="lead">This page is under construction.</p>
|
||||
<a href="/" class="btn btn-primary">Go to Homepage</a>
|
||||
|
||||
<div class="container my-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-8">
|
||||
<h1 class="fw-bold mb-4">Privacy Policy</h1>
|
||||
<p class="text-muted">Last updated: <?php echo date("F j, Y"); ?></p>
|
||||
|
||||
<p>This page is under construction. A full privacy policy will be available here soon.</p>
|
||||
|
||||
<h2 class="h4 mt-5">1. Information We Collect</h2>
|
||||
<p>We will detail the information we collect, such as personal data provided during registration (name, email) and data collected automatically (IP address, browser type).</p>
|
||||
|
||||
<h2 class="h4 mt-4">2. How We Use Your Information</h2>
|
||||
<p>We will explain how we use the collected data, for purposes like providing and improving our service, communicating with users, and ensuring security.</p>
|
||||
|
||||
<h2 class="h4 mt-4">3. Data Sharing and Disclosure</h2>
|
||||
<p>We will clarify the circumstances under which user data might be shared with third parties, such as service providers or for legal reasons.</p>
|
||||
|
||||
<h2 class="h4 mt-4">4. Data Security</h2>
|
||||
<p>We will describe the measures we take to protect user data from unauthorized access or disclosure.</p>
|
||||
|
||||
<h2 class="h4 mt-4">5. Your Rights</h2>
|
||||
<p>We will outline the rights users have regarding their data, such as accessing, correcting, or deleting their personal information.</p>
|
||||
|
||||
<h2 class="h4 mt-4">Contact Us</h2>
|
||||
<p>If you have any questions about this Privacy Policy, you can contact us via the <a href="index.php#contact">contact form</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</div>
|
||||
|
||||
<?php include 'partials/footer.php'; ?>
|
||||
|
||||
105
register.php
Normal file
105
register.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
require_once 'mail/MailService.php';
|
||||
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
header("Location: dashboard.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
$success = '';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$name = trim($_POST['name']);
|
||||
$email = trim($_POST['email']);
|
||||
$password = $_POST['password'];
|
||||
|
||||
if (empty($name)) {
|
||||
$errors[] = 'Name is required.';
|
||||
}
|
||||
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[] = 'A valid email is required.';
|
||||
}
|
||||
if (empty($password) || strlen($password) < 8) {
|
||||
$errors[] = 'Password must be at least 8 characters long.';
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
|
||||
$stmt->execute([$email]);
|
||||
if ($stmt->fetch()) {
|
||||
$errors[] = 'An account with this email already exists.';
|
||||
} else {
|
||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$stmt = $pdo->prepare("INSERT INTO users (name, email, password) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$name, $email, $hashed_password]);
|
||||
|
||||
// Send welcome email
|
||||
$subject = "Welcome to AI Web App Generator!";
|
||||
$htmlBody = "<h1>Welcome, {$name}!</h1><p>Thank you for registering. You can now log in and start creating your web application.</p>";
|
||||
$textBody = "Welcome, {$name}! Thank you for registering. You can now log in and start creating your web application.";
|
||||
MailService::sendMail($email, $subject, $htmlBody, $textBody);
|
||||
|
||||
$success = 'Registration successful! You can now <a href="login.php">log in</a>.';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$pageTitle = "Register";
|
||||
include 'partials/header.php';
|
||||
?>
|
||||
|
||||
<div class="container my-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-6">
|
||||
<div class="card shadow-lg">
|
||||
<div class="card-body p-5">
|
||||
<h1 class="h3 fw-bold text-center mb-4">Create Your Account</h1>
|
||||
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p class="mb-0"><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($success): ?>
|
||||
<div class="alert alert-success">
|
||||
<p class="mb-0"><?php echo $success; ?></p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<form action="register.php" method="POST" novalidate>
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Full Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email Address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
<div class="form-text">Password must be at least 8 characters long.</div>
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary btn-lg">Register</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'partials/footer.php'; ?>
|
||||
Loading…
x
Reference in New Issue
Block a user