working on login
This commit is contained in:
parent
d8446b7d3c
commit
a20c443178
|
@ -19,3 +19,6 @@ if ($route == 'gate') return GateModule::handle();
|
|||
// 404
|
||||
http_response_code(404);
|
||||
echo '404: ' . $route;
|
||||
|
||||
// cleanup
|
||||
$app->cleanup();
|
||||
|
|
|
@ -20,12 +20,11 @@ class App
|
|||
self::$dbPath = $dbPath; // the database path
|
||||
self::$auth = new Auth();
|
||||
|
||||
// stuff that can only be loaded if the database is installed
|
||||
if (INSTALLED) {
|
||||
// load game settings
|
||||
$s = self::$db->q('SELECT * FROM settings WHERE id = 1;');
|
||||
self::$s = $s ? $s->fetch() : [];
|
||||
// load game settings
|
||||
$s = self::$db->q('SELECT * FROM settings WHERE id = 1;');
|
||||
self::$s = $s ? $s->fetch() : [];
|
||||
|
||||
if (INSTALLED) {
|
||||
// load the player's auth
|
||||
self::$auth->good();
|
||||
}
|
||||
|
@ -57,9 +56,10 @@ class App
|
|||
self::$flashes[$key] = $value;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
public function cleanup()
|
||||
{
|
||||
// clean up flash messages
|
||||
$_SESSION['flash'] = [];
|
||||
unset($_SESSION['flash']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ class Auth
|
|||
return $data;
|
||||
}
|
||||
|
||||
private function logout(): void
|
||||
public function logout(): void
|
||||
{
|
||||
if (isset($_SESSION['player_id'])) unset($_SESSION['player_id']);
|
||||
if (isset($_COOKIE[self::COOKIE_NAME])) setcookie(self::COOKIE_NAME, '', time() - 86400, '/', '', true, true);
|
||||
|
|
|
@ -9,7 +9,10 @@ class GateModule
|
|||
$s = App::$req->uri(1) ?? ''; // second segment
|
||||
$m = App::$req->method; // request method
|
||||
|
||||
if (App::$auth->good() && in_array($s, self::GUEST)) redirect('/');
|
||||
|
||||
if ($s == '' || $s == 'login') return self::login($m);
|
||||
if ($s == 'logout' && $m == 'POST') return self::logout();
|
||||
}
|
||||
|
||||
public static function login(string $method)
|
||||
|
@ -42,4 +45,11 @@ class GateModule
|
|||
redirect('/gate/login');
|
||||
}
|
||||
}
|
||||
|
||||
private static function logout()
|
||||
{
|
||||
App::$auth->logout();
|
||||
App::flash('success', 'You have been logged out.');
|
||||
redirect('/');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,13 @@ class HomeModule
|
|||
{
|
||||
public static function home()
|
||||
{
|
||||
foreach ($_SESSION['flash'] as $key => $value) {
|
||||
echo '<div class="alert ' . $key . '">- ' . $value . '</div>';
|
||||
}
|
||||
|
||||
if (App::auth()) {
|
||||
echo 'You are already logged in!<br>';
|
||||
echo '<form action="/gate/logout" method="post"><button>Logout</button></form>';
|
||||
} else {
|
||||
echo 'You are not logged in!<br>';
|
||||
}
|
||||
|
|
|
@ -254,9 +254,6 @@ class InstallModule
|
|||
'expires' DATETIME NOT NULL
|
||||
);");
|
||||
|
||||
// Create the .installed file in the server folder
|
||||
file_put_contents(SERVER.'/.installed', 'Installed on '.date('Y-m-d H:i:s'));
|
||||
|
||||
echo render('install/layout', ['title' => 'Database Setup', 'step' => 'second', 'complete' => $complete, 'start' => $istart]);
|
||||
}
|
||||
|
||||
|
@ -300,9 +297,11 @@ class InstallModule
|
|||
// login the admin
|
||||
App::$auth->login($_POST['username'], $_POST['password']);
|
||||
|
||||
// Create the .installed file in the server folder
|
||||
file_put_contents(SERVER.'/.installed', 'Installed on '.date('Y-m-d H:i:s'));
|
||||
|
||||
// Render the finished page!
|
||||
echo render('install/layout', ['title' => 'Finished!', 'step' => 'done', 'name' => $_POST['username'], 'complete' => $_POST['complete'] ?? false]);
|
||||
|
||||
}
|
||||
|
||||
private static function fourOhFour()
|
||||
|
|
|
@ -1 +1,7 @@
|
|||
hello
|
||||
<form action="/gate/login" method="post">
|
||||
<input type="text" name="id" placeholder="Email or Username">
|
||||
<input type="password" name="pw" placeholder="Password">
|
||||
<input type="checkbox" name="remember" id="remember">
|
||||
<label for="remember">Remember me</label>
|
||||
<button>Login</button>
|
||||
</form>
|
||||
|
|
|
@ -14,7 +14,9 @@
|
|||
|
||||
<div id="content">
|
||||
<aside id="left">
|
||||
left
|
||||
<?php if (App::$auth->good()) {
|
||||
echo render('partials/left', $data);
|
||||
} ?>
|
||||
</aside>
|
||||
|
||||
<main>
|
||||
|
@ -22,7 +24,9 @@
|
|||
</main>
|
||||
|
||||
<aside id="right">
|
||||
right
|
||||
<?php if (App::$auth->good()) {
|
||||
echo render('partials/right', $data);
|
||||
} ?>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
|
|
1
server/templates/partials/left.php
Normal file
1
server/templates/partials/left.php
Normal file
|
@ -0,0 +1 @@
|
|||
Left
|
1
server/templates/partials/right.php
Normal file
1
server/templates/partials/right.php
Normal file
|
@ -0,0 +1 @@
|
|||
Right
|
Loading…
Reference in New Issue
Block a user