Adds login and registration messages and configs

main
Yasen Pramatarov 2024-08-01 11:12:54 +03:00
parent 06ffde67f4
commit 5d240b1dd8
3 changed files with 45 additions and 29 deletions

View File

@ -1,11 +1,13 @@
<?php
$config = [
'domain' => 'localhost',
'folder' => '/jilo-web/',
'database' => '/home/yasen/work/code/git/lindeas-code/jilo-web/jilo-web.db',
'jilo_database' => '/home/yasen/work/code/git/lindeas-code/jilo/jilo.db',
'version' => '0.1.1',
'domain' => 'localhost',
'folder' => '/jilo-web/',
'database' => '/home/yasen/work/code/git/lindeas-code/jilo-web/jilo-web.db',
'jilo_database' => '/home/yasen/work/code/git/lindeas-code/jilo/jilo.db',
'registration_enabled' => true,
'login_message' => '',
'version' => '0.1.1',
];
?>

View File

@ -68,6 +68,11 @@ try {
$error = $e->getMessage();
}
if (!empty($config['login_message'])) {
$notice = $config['login_message'];
include 'templates/block-message.php';
}
include 'templates/form-login.php';
?>

View File

@ -1,34 +1,43 @@
<?php
require_once 'classes/database.php';
require 'classes/user.php';
unset($error);
// registration is allowed, go on
if ($config['registration_enabled'] === true) {
try {
$db = new Database($config['database']);
$user = new User($db);
require_once 'classes/database.php';
require 'classes/user.php';
unset($error);
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$username = $_POST['username'];
$password = $_POST['password'];
try {
$db = new Database($config['database']);
$user = new User($db);
// redirect to login
if ( $user->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();
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$username = $_POST['username'];
$password = $_POST['password'];
// redirect to login
if ( $user->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) {
$error = $e->getMessage();
}
} catch (Exception $e) {
$error = $e->getMessage();
include 'templates/block-message.php';
include 'templates/form-register.php';
// registration disabled
} else {
$notice = 'Registration is disabled';
include 'templates/block-message.php';
}
include 'templates/block-message.php';
include 'templates/form-register.php';
?>