89 lines
3.4 KiB
PHP
89 lines
3.4 KiB
PHP
<?php
|
|
session_start();
|
|
require_once __DIR__ . '/lib.php';
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
if (is_logged_in()) {
|
|
header('Location: /admin/');
|
|
exit;
|
|
}
|
|
|
|
$error = null;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$name = $_POST['name'] ?? '';
|
|
$username = $_POST['username'] ?? '';
|
|
$email = $_POST['email'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
$confirm_password = $_POST['confirm_password'] ?? '';
|
|
|
|
if ($password !== $confirm_password) {
|
|
$error = 'Passwords do not match';
|
|
} else {
|
|
$user_id = register($name, $username, $email, $password);
|
|
if ($user_id) {
|
|
$_SESSION['user_id'] = $user_id;
|
|
header('Location: /admin/');
|
|
exit;
|
|
} else {
|
|
$error = 'Username or email already exists';
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Register</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-6">
|
|
<div class="card mt-5">
|
|
<div class="card-header">
|
|
<h3 class="text-center">Register</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger"><?= $error ?></div>
|
|
<?php endif; ?>
|
|
<form action="/registration.php" method="post">
|
|
<div class="mb-3">
|
|
<label for="name" class="form-label">Name</label>
|
|
<input type="text" class="form-control" id="name" name="name" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="username" class="form-label">Username</label>
|
|
<input type="text" class="form-control" id="username" name="username" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label">Email</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>
|
|
<div class="mb-3">
|
|
<label for="confirm_password" class="form-label">Confirm Password</label>
|
|
<input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
|
|
</div>
|
|
<div class="d-grid">
|
|
<button type="submit" class="btn btn-primary">Register</button>
|
|
</div>
|
|
</form>
|
|
<div class="text-center mt-3">
|
|
<p>Already have an account? <a href="/admin/login.php">Login here</a></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|