-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
49 lines (38 loc) · 1.39 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/util/database.php';
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
$loader = new FilesystemLoader(__DIR__ . '/templates');
$twig = new Environment($loader);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$data = preventXSS($_POST, true);
$missing = checkMissingData($data, true);
if(!empty($missing)){
echo $twig->render('error.html.twig', ['missing' => $missing, 'login' => "true"]);
return;
}
// Connect to the DB
$mysqli = new mysqli('localhost', 'root', 'root', 'my_alex0');
// Verify connection to the DB
if ($mysqli->connect_error) {
die('Connection failed: ' . $mysqli->connect_error);
}
$response = loginUser($data, $mysqli);
if(!is_null($response))
if($response === "User not Found")
echo $twig->render('error.html.twig', ['notFound' => 'USER', 'login' => "true"]);
else {
$response = (array) $response;
unset($response['password_hash']);
unset($response['ID']);
unset($response['created_at']);
echo $twig->render('index.html.twig', ['data' => $response]);
}
else
echo $twig->render('error.html.twig', ['wrongCredentials' => "Password", 'login' => "true"]);
$mysqli->close();
return;
}
echo $twig->render('login.html.twig');
?>