-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
33 lines (24 loc) · 871 Bytes
/
index.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
<?php
require_once 'src/Config/Database.php';
require_once 'src/Controllers/AuthController.php';
use src\Controllers\AuthController;
// Handle login form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['username'], $_POST['password'])) {
$authController = new AuthController();
$username = $_POST['username'];
$password = $_POST['password'];
$user = $authController->login($username, $password);
if ($user) {
print_r($user);
// Successful login, token and cookie are generated.
// Redirect to the protected page or handle the result accordingly
header('Location: protected_page.php');
exit();
} else {
// Handle login failure, show error message
$errorMessage = 'Invalid username or password';
}
}
// Render the login form
include 'src/views/login.php';
?>