jilo-web/app/pages/register.php

49 lines
1.3 KiB
PHP
Raw Normal View History

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