Add login
This commit is contained in:
parent
dce62230b5
commit
52bbe64d73
4 changed files with 65 additions and 6 deletions
|
@ -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
49
includes/pages/login.php
Normal 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();
|
|
@ -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>
|
||||
|
|
|
@ -53,6 +53,11 @@ if ($database) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Session
|
||||
*/
|
||||
session_start();
|
||||
|
||||
/**
|
||||
* Page
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue