Add login

This commit is contained in:
Jay 2021-11-15 12:32:44 +01:00
parent dce62230b5
commit 52bbe64d73
4 changed files with 65 additions and 6 deletions

View file

@ -30,17 +30,19 @@ class Database
}
}
public function query(string $query): void
public function query(string $query)
{
$this->pdo->query($query);
return $this->pdo->query(
$query,
\PDO::FETCH_ASSOC
);
}
public function getOption(string $key): string
{
$option = $this->pdo->query(
$option = $this->query(
'SELECT * FROM `options`
WHERE `key` = "' . $key . '";',
\PDO::FETCH_ASSOC
WHERE `key` = "' . $key . '";'
)->fetch();
return $option['value'];

49
includes/pages/login.php Normal file
View file

@ -0,0 +1,49 @@
<?php
/**
* login.php
*
* @author Jay Trees <github.jay@grandel.anonaddy.me>
*/
use wishthis\Page;
$page = new page(__FILE__, 'Home');
if (isset($_POST['email'], $_POST['password'])) {
$user = $database->query(
'SELECT * FROM `users`
WHERE `email` = "' . $_POST['email'] . '"
AND `password` = "' . sha1($_POST['password']) . '";'
)->fetch();
$_SESSION['user'] = $user;
header('Location: ?page=home');
die();
}
$page->header();
?>
<main>
<section>
<h1>Login</h1>
<form method="post">
<fieldset>
<label>Email</label>
<input type="email" name="email" placeholder="john.doe@domain.tld" />
</fieldset>
<fieldset>
<label>Password</label>
<input type="password" name="password" />
</fieldset>
<input type="submit" value="Login" />
</form>
</section>
</main>
<?php
$page->footer();

View file

@ -9,15 +9,18 @@
use wishthis\Page;
$page = new page(__FILE__, 'Home');
$page->header();
if (isset($_POST['email'], $_POST['password'])) {
$database->query('INSERT INTO `users`
(`email`, `password`) VALUES
("' . $_POST['email'] . '", "' . sha1($_POST['password']) . '")
;');
header('Location: ?page=login');
die();
}
$page->header();
?>
<main>
<section>

View file

@ -53,6 +53,11 @@ if ($database) {
}
}
/**
* Session
*/
session_start();
/**
* Page
*/