feat: add MVC base, with auth to ldap
This commit is contained in:
42
controllers/auth.php
Normal file
42
controllers/auth.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require_once __DIR__ . '/../models/LDAPAuth.php';
|
||||
|
||||
class AuthController
|
||||
{
|
||||
private $auth_model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->auth_model = new LDAPAuth();
|
||||
}
|
||||
|
||||
public function login()
|
||||
{
|
||||
if (isset($_POST['user_pseudo']) && isset($_POST['user_password'])) {
|
||||
$result = $this->auth_model->authenticate(
|
||||
$_POST['user_pseudo'],
|
||||
$_POST['user_password']
|
||||
);
|
||||
|
||||
if ($result['success']) {
|
||||
$_SESSION['login'] = true;
|
||||
$_SESSION['user_pseudo'] = $_POST['user_pseudo'];
|
||||
$_SESSION['is_admin'] = $result['is_admin'];
|
||||
$_SESSION['ldap_token'] = base64_encode($_POST['user_pseudo'] . ':' . $_POST['user_password']);
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
} else {
|
||||
$error_message = 'Identifiants incorrects';
|
||||
require_once __DIR__ . '/views/auth.php';
|
||||
}
|
||||
} else {
|
||||
require_once __DIR__ . '/views/auth.php';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
session_start(); // Assure-toi que la session est bien démarrée
|
||||
$controller = new AuthController();
|
||||
$controller->login();
|
||||
Reference in New Issue
Block a user