jilo-web/app/pages/register.php

46 lines
1.2 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'];
// redirect to login
2024-09-06 16:34:03 +00:00
if ( $userObject->register($username, $password) ) {
$_SESSION['notice'] = "Registration successful.<br />You can log in now.";
header('Location: index.php');
exit();
// registration fail, redirect to login
} else {
$_SESSION['error'] = "Registration failed.";
header('Location: index.php');
exit();
}
}
} catch (Exception $e) {
2024-08-17 08:20:08 +00:00
$error = getError('There was an unexpected error. Please try again.', $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';
}
?>