2024-06-28 17:05:32 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'classes/database.php';
|
|
|
|
require 'classes/user.php';
|
|
|
|
unset($error);
|
|
|
|
|
|
|
|
try {
|
2024-07-01 09:45:07 +00:00
|
|
|
$db = new Database($config['database']);
|
2024-06-28 17:05:32 +00:00
|
|
|
$user = new User($db);
|
|
|
|
|
|
|
|
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
|
|
|
|
$username = $_POST['username'];
|
|
|
|
$password = $_POST['password'];
|
|
|
|
|
2024-07-01 09:45:07 +00:00
|
|
|
// redirect to login
|
2024-06-28 17:05:32 +00:00
|
|
|
if ( $user->register($username, $password) ) {
|
2024-07-01 09:45:07 +00:00
|
|
|
$_SESSION['notice'] = "Registration successful.<br />You can log in now.";
|
|
|
|
header('Location: index.php');
|
|
|
|
exit();
|
|
|
|
// registration fail, redirect to login
|
2024-06-28 17:05:32 +00:00
|
|
|
} else {
|
2024-07-01 09:45:07 +00:00
|
|
|
$_SESSION['error'] = "Registration failed.";
|
|
|
|
header('Location: index.php');
|
|
|
|
exit();
|
2024-06-28 17:05:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$error = $e->getMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
include 'templates/form-register.php';
|
|
|
|
|
|
|
|
?>
|