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-08-12 11:12:24 +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-06 16:34: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.";
header('Location: index.php');
exit();
// registration fail, redirect to login
} else {
2024-09-13 10:49:17 +00:00
$_SESSION['error'] = "Registration failed. $result";
header('Location: index.php');
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';
}
?>