52 lines
1.7 KiB
PHP
52 lines
1.7 KiB
PHP
<?php
|
|
session_start();
|
|
require __DIR__ . '/../inc/db.php';
|
|
$error=null;
|
|
if($_SERVER['REQUEST_METHOD']==='POST'){
|
|
$login=isset($_POST['login'])?trim($_POST['login']):'';
|
|
$password=$_POST['password']??'';
|
|
$stmt=$pdo->prepare("SELECT * FROM utilisateur WHERE login=?");
|
|
$stmt->execute([$login]);
|
|
$user=$stmt->fetch();
|
|
if($user && password_verify($password,$user['password'])){
|
|
$_SESSION['user_id']=$user['id'];
|
|
$_SESSION['user_login']=$user['login'];
|
|
header('Location: admin.php'); exit;
|
|
} else { $error='Identifiants incorrects.'; }
|
|
}
|
|
?>
|
|
<!doctype html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>Connexion</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="assets/style.css" rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
<nav class="navbar">
|
|
<div class="container container-narrow">
|
|
<a class="navbar-brand fw-semibold" href="/">CMS Simplifié</a>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container container-narrow py-5" style="max-width:520px">
|
|
<div class="card p-4">
|
|
<h1 class="h4 mb-3">Connexion</h1>
|
|
<?php if($error): ?><div class="alert alert-danger"><?= htmlspecialchars($error) ?></div><?php endif; ?>
|
|
<form method="post" class="vstack gap-3">
|
|
<div>
|
|
<label class="form-label">Login</label>
|
|
<input class="form-control" type="text" name="login" required>
|
|
</div>
|
|
<div>
|
|
<label class="form-label">Mot de passe</label>
|
|
<input class="form-control" type="password" name="password" required>
|
|
</div>
|
|
<button class="btn btn-accent">Se connecter</button>
|
|
</form>
|
|
</div>
|
|
</main>
|
|
</body>
|
|
</html>
|