192 lines
5.3 KiB
PHP
192 lines
5.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
@ini_set('display_errors', '1');
|
|
@error_reporting(E_ALL);
|
|
|
|
session_start();
|
|
|
|
$data_dir = __DIR__ . '/data';
|
|
if (!is_dir($data_dir)) {
|
|
mkdir($data_dir, 0777, true);
|
|
}
|
|
$users_file = $data_dir . '/users.json';
|
|
if (!file_exists($users_file)) {
|
|
file_put_contents($users_file, json_encode([]));
|
|
}
|
|
|
|
$errors = [];
|
|
$success_message = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$business_name = trim($_POST['business_name'] ?? '');
|
|
$email = trim($_POST['email'] ?? '');
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if (empty($business_name)) {
|
|
$errors[] = 'Business 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)) {
|
|
$users = json_decode(file_get_contents($users_file), true);
|
|
|
|
foreach ($users as $user) {
|
|
if ($user['email'] === $email) {
|
|
$errors[] = 'An account with this email already exists.';
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (empty($errors)) {
|
|
$users[] = [
|
|
'business_name' => $business_name,
|
|
'email' => $email,
|
|
'password' => password_hash($password, PASSWORD_DEFAULT),
|
|
];
|
|
file_put_contents($users_file, json_encode($users, JSON_PRETTY_PRINT));
|
|
|
|
$_SESSION['success_message'] = 'Registration successful! You can now log in.';
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>Sign Up - Digital Marketing Suite</title>
|
|
<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;700&display=swap" rel="stylesheet">
|
|
<style>
|
|
:root {
|
|
--bg-color: #f8f9fa;
|
|
--text-color: #343a40;
|
|
--heading-color: #212529;
|
|
--primary-color: #007bff;
|
|
--border-color: #dee2e6;
|
|
--card-bg: #ffffff;
|
|
--shadow: 0 0 15px rgba(0, 0, 0, 0.05);
|
|
}
|
|
body {
|
|
margin: 0;
|
|
font-family: 'Inter', sans-serif;
|
|
background-color: var(--bg-color);
|
|
color: var(--text-color);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
height: 100vh;
|
|
}
|
|
.register-container {
|
|
width: 100%;
|
|
max-width: 400px;
|
|
padding: 2.5rem;
|
|
background-color: var(--card-bg);
|
|
border-radius: 12px;
|
|
box-shadow: var(--shadow);
|
|
}
|
|
h1 {
|
|
font-size: 2rem;
|
|
font-weight: 700;
|
|
color: var(--heading-color);
|
|
text-align: center;
|
|
margin-bottom: 2rem;
|
|
}
|
|
.form-group {
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
.form-group label {
|
|
display: block;
|
|
font-weight: 500;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
.form-group input {
|
|
width: 100%;
|
|
padding: 0.8rem;
|
|
border-radius: 8px;
|
|
border: 1px solid var(--border-color);
|
|
font-size: 1rem;
|
|
transition: border-color 0.2s, box-shadow 0.2s;
|
|
}
|
|
.form-group input:focus {
|
|
outline: none;
|
|
border-color: var(--primary-color);
|
|
box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
|
|
}
|
|
.submit-btn {
|
|
display: block;
|
|
width: 100%;
|
|
padding: 0.8rem;
|
|
border: none;
|
|
border-radius: 8px;
|
|
background: var(--primary-color);
|
|
color: #ffffff;
|
|
font-size: 1rem;
|
|
font-weight: 700;
|
|
cursor: pointer;
|
|
transition: background-color 0.2s;
|
|
}
|
|
.submit-btn:hover {
|
|
background-color: #0056b3;
|
|
}
|
|
.message {
|
|
padding: 1rem;
|
|
border-radius: 8px;
|
|
margin-bottom: 1.5rem;
|
|
font-weight: 500;
|
|
text-align: center;
|
|
}
|
|
.message.error {
|
|
background-color: #f8d7da;
|
|
color: #721c24;
|
|
border: 1px solid #f5c6cb;
|
|
}
|
|
.form-footer {
|
|
text-align: center;
|
|
margin-top: 1.5rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<div class="card">
|
|
<h1>Create Account</h1>
|
|
<?php if (!empty($errors)): ?>
|
|
<div class="errors">
|
|
<?php foreach ($errors as $error): ?>
|
|
<p><?= htmlspecialchars($error) ?></p>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<form action="register.php" method="post">
|
|
<div class="form-group">
|
|
<label for="business_name">Business Name</label>
|
|
<input type="text" id="business_name" name="business_name" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="email">Email</label>
|
|
<input type="email" id="email" name="email" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<input type="password" id="password" name="password" required minlength="8">
|
|
</div>
|
|
<button type="submit">Sign Up</button>
|
|
</form>
|
|
<div class="login-link">
|
|
<p>Already have an account? <a href="login.php">Log In</a></p>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</body>
|
|
</html>
|