Adds login and registration messages and configs
parent
06ffde67f4
commit
5d240b1dd8
|
@ -1,11 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$config = [
|
$config = [
|
||||||
'domain' => 'localhost',
|
'domain' => 'localhost',
|
||||||
'folder' => '/jilo-web/',
|
'folder' => '/jilo-web/',
|
||||||
'database' => '/home/yasen/work/code/git/lindeas-code/jilo-web/jilo-web.db',
|
'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',
|
'jilo_database' => '/home/yasen/work/code/git/lindeas-code/jilo/jilo.db',
|
||||||
'version' => '0.1.1',
|
'registration_enabled' => true,
|
||||||
|
'login_message' => '',
|
||||||
|
'version' => '0.1.1',
|
||||||
];
|
];
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -68,6 +68,11 @@ try {
|
||||||
$error = $e->getMessage();
|
$error = $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($config['login_message'])) {
|
||||||
|
$notice = $config['login_message'];
|
||||||
|
include 'templates/block-message.php';
|
||||||
|
}
|
||||||
|
|
||||||
include 'templates/form-login.php';
|
include 'templates/form-login.php';
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -1,34 +1,43 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'classes/database.php';
|
// registration is allowed, go on
|
||||||
require 'classes/user.php';
|
if ($config['registration_enabled'] === true) {
|
||||||
unset($error);
|
|
||||||
|
|
||||||
try {
|
require_once 'classes/database.php';
|
||||||
$db = new Database($config['database']);
|
require 'classes/user.php';
|
||||||
$user = new User($db);
|
unset($error);
|
||||||
|
|
||||||
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
|
try {
|
||||||
$username = $_POST['username'];
|
$db = new Database($config['database']);
|
||||||
$password = $_POST['password'];
|
$user = new User($db);
|
||||||
|
|
||||||
// redirect to login
|
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
|
||||||
if ( $user->register($username, $password) ) {
|
$username = $_POST['username'];
|
||||||
$_SESSION['notice'] = "Registration successful.<br />You can log in now.";
|
$password = $_POST['password'];
|
||||||
header('Location: index.php');
|
|
||||||
exit();
|
// redirect to login
|
||||||
// registration fail, redirect to login
|
if ( $user->register($username, $password) ) {
|
||||||
} else {
|
$_SESSION['notice'] = "Registration successful.<br />You can log in now.";
|
||||||
$_SESSION['error'] = "Registration failed.";
|
header('Location: index.php');
|
||||||
header('Location: index.php');
|
exit();
|
||||||
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';
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue