2024-06-28 17:05:32 +00:00
|
|
|
<?php
|
|
|
|
|
2024-08-01 08:12:54 +00:00
|
|
|
// registration is allowed, go on
|
|
|
|
if ($config['registration_enabled'] === true) {
|
|
|
|
|
2024-09-16 16:08:03 +00:00
|
|
|
// require '../app/classes/user.php';
|
2024-08-01 08:12:54 +00:00
|
|
|
unset($error);
|
|
|
|
|
|
|
|
try {
|
2024-08-10 18:42:44 +00:00
|
|
|
|
|
|
|
// connect to database
|
2024-09-04 09:53:02 +00:00
|
|
|
$dbWeb = connectDB($config);
|
2024-08-10 18:42:44 +00:00
|
|
|
|
2024-09-16 16:08:03 +00:00
|
|
|
// $userObject = new User($dbWeb);
|
2024-08-01 08:12:54 +00:00
|
|
|
|
|
|
|
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
|
|
|
|
$username = $_POST['username'];
|
|
|
|
$password = $_POST['password'];
|
|
|
|
|
2024-09-13 10:49:17 +00:00
|
|
|
// registering
|
|
|
|
$result = $userObject->register($username, $password);
|
|
|
|
|
2024-08-01 08:12:54 +00:00
|
|
|
// redirect to login
|
2024-09-13 10:49:17 +00:00
|
|
|
if ($result === true) {
|
2024-08-01 08:12:54 +00:00
|
|
|
$_SESSION['notice'] = "Registration successful.<br />You can log in now.";
|
2024-10-23 12:28:45 +00:00
|
|
|
header('Location: ' . htmlspecialchars($app_root));
|
2024-08-01 08:12:54 +00:00
|
|
|
exit();
|
|
|
|
// registration fail, redirect to login
|
|
|
|
} else {
|
2024-09-13 10:49:17 +00:00
|
|
|
$_SESSION['error'] = "Registration failed. $result";
|
2024-10-23 12:28:45 +00:00
|
|
|
header('Location: ' . htmlspecialchars($app_root));
|
2024-08-01 08:12:54 +00:00
|
|
|
exit();
|
|
|
|
}
|
2024-06-28 17:05:32 +00:00
|
|
|
}
|
2024-08-01 08:12:54 +00:00
|
|
|
} catch (Exception $e) {
|
2024-09-13 10:49:17 +00:00
|
|
|
$error = $e->getMessage();
|
2024-06-28 17:05:32 +00:00
|
|
|
}
|
|
|
|
|
2024-08-12 11:12:24 +00:00
|
|
|
include '../app/templates/block-message.php';
|
|
|
|
include '../app/templates/form-register.php';
|
2024-08-01 08:12:54 +00:00
|
|
|
|
|
|
|
// registration disabled
|
|
|
|
} else {
|
|
|
|
$notice = 'Registration is disabled';
|
2024-08-12 11:12:24 +00:00
|
|
|
include '../app/templates/block-message.php';
|
2024-08-01 08:12:54 +00:00
|
|
|
}
|
2024-06-28 17:05:32 +00:00
|
|
|
|
|
|
|
?>
|