Files
maria_uslugi/connexion_back.php

182 lines
7.9 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/public/includes/init_auth.php';
$erreur = '';
$email = '';
$mot_de_passe = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = trim($_POST['email'] ?? '');
$mot_de_passe = $_POST['mot_de_passe'] ?? '';
if ($email === '' || $mot_de_passe === '') {
$erreur = $translations['erreur_champs_vides'];
} else {
// 1) On vérifie l’utilisateur
$stmt = $pdo->prepare("SELECT * FROM compte WHERE email = :email LIMIT 1");
$stmt->execute(['email' => $email]);
$compte = $stmt->fetch();
if ($compte && password_verify($mot_de_passe, $compte['mot_de_passe'])) {
if (empty($compte['email_valide'])) {
$erreur = $translations['erreur_email_non_valide'];
} else {
session_regenerate_id(true); // ✅ anti session fixation
// 2) Connexion OK → on initialise la session
$_SESSION['compte_id'] = $compte['id'];
$_SESSION['role'] = strtolower(trim($compte['role'] ?? ''));
$_SESSION['reference_id'] = $compte['reference_id'];
$_SESSION['email'] = $compte['email'];
$_SESSION['last_activity'] = time();
// 3) On gère la redirection prioritaire vers la page demandée
$next = $_POST['next'] ?? $_GET['next'] ?? ($_SESSION['redirect_to'] ?? null);
$next = next_safe($next);
if ($next) {
unset($_SESSION['redirect_to']);
header('Location: ' . $next);
exit;
}
// 4) Sinon, fallback par rôle
if ($_SESSION['role'] === 'client') {
header('Location: /public/client/mes_rendez_vous.php');exit;
} elseif ($_SESSION['role'] === 'admin') {
header('Location: /admin/index.php');exit;
} elseif ($_SESSION['role'] === 'secretaire') {
header('Location: /public/cabinet/dashboard.php');exit;
} else {
header('Location: /public/praticien/agenda.php');exit;
}
}
} else {
$erreur = $translations['erreur_identifiants'];
}
}
}
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title><?php echo htmlspecialchars($translations['seo_connexion_title'], ENT_QUOTES, 'UTF-8')?></title>
<meta name="description" content="<?php echo htmlspecialchars($translations['seo_connexion_desc'], ENT_QUOTES, 'UTF-8')?>">
<meta name="keywords" content="<?php echo htmlspecialchars($translations['seo_connexion_keywords'], ENT_QUOTES, 'UTF-8')?>">
<meta name="author" content="Uslugi.fr">
<!-- Recommandé pour une page de login -->
<meta name="robots" content="noindex, nofollow, noarchive, nosnippet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="<?= asset('/includes/site_style.css') ?>">
<link rel="stylesheet" href="<?= asset('/includes/custom_style.css') ?>">
<link rel="stylesheet" href="<?= asset('/includes/mobil_style.css') ?>">
</head>
<body>
<header class="site-header">
<div class="container">
<div class="header-left">
<div class="brand">
<a href="/index.php"><img src="/public/uploads/img/logo_u.png"
alt="uslugi.fr"
class="logo-mobile"></a>
<a href="/index.php"><img src="/public/uploads/img/logo.png"
alt="uslugi.fr"
class="logo-desktop"></a>
</div>
<div class="lang-switch">
<?php require __DIR__ . '/includes/menu_langue.php'; ?>
</div>
</div>
<nav class="header-actions">
<div class="dropdown">
<button class="btn btn-logo rounded-circle d-inline-flex align-items-center justify-content-center question-btn"
type="button" data-bs-toggle="dropdown" data-bs-auto-close="true"
aria-expanded="false" aria-label="Помощь">?</button>
<ul class="dropdown-menu dropdown-menu-end shadow help-menu menu-panel">
<li><a href="/how-it-work.php"><?= $translations['kak_rabotaet'] ?></a></a></li>
<li><a href="/about.php"><?= $translations['pro_nas'] ?></a></li>
<li><a href="/faq.php"><?= $translations['faq'] ?></a></li>
<li><a href="/contact.php"><?= $translations['nam_pisat'] ?></a></li>
</ul>
</div>
</nav>
</div>
</header>
<div class="main">
<div class="card shadow-sm p-4" style="min-width:380px; max-width:520px; margin:40px auto;">
<h3 class="mb-4 text-center text-dark"><?php echo $translations['connexion_titre']?></h3>
<?php if ($erreur): ?>
<div class="alert alert-danger py-2"><?php echo htmlspecialchars($erreur)?></div>
<?php endif; ?>
<form method="POST">
<div class="mb-3">
<input type="email" name="email" class="form-control"
placeholder="<?php echo $translations['email_placeholder']?>"
value="<?php echo htmlspecialchars($email)?>" required>
</div>
<div class="mb-3 position-relative">
<input id="mot_de_passe" type="password" name="mot_de_passe" class="form-control"
placeholder="<?php echo $translations['motdepasse_placeholder']?>"
required autocomplete="current-password">
<span class="toggle-password"
id="eyePwd"
onmouseenter="revealPwd('mot_de_passe')"
onmouseleave="hidePwd('mot_de_passe')"
onmousedown="revealPwd('mot_de_passe')"
onmouseup="hidePwd('mot_de_passe')"
ontouchstart="revealPwd('mot_de_passe')"
ontouchend="hidePwd('mot_de_passe')"
title="Наведите, чтобы показать">
👁️
</span>
</div>
<!-- on propage le "next" -->
<input type="hidden" name="next"
value="<?php echo htmlspecialchars($_GET['next'] ?? ($_SESSION['redirect_to'] ?? ''), ENT_QUOTES)?>">
<button type="submit" class="btn btn-primary w-100"><?php echo $translations['btn_se_connecter']?></button>
<div class="text-center mt-3">
<a href="mdp_oublie.php" class="me-2"><?php echo $translations['lien_mdp_oublie']?></a> |
<a href="choix_inscr.php" class="ms-2"><?php echo $translations['lien_inscription']?></a>
</div>
</form>
</div>
</div>
<footer class="site-footer">
<div class="container">
<p><?php echo $translations['copyr']?></p>
</div>
</footer>
<script>
function revealPwd(id){ var el = document.getElementById(id); if(el) el.type = 'text'; }
function hidePwd(id){ var el = document.getElementById(id); if(el) el.type = 'password'; }
(function(){
var eye = document.getElementById('eyePwd');
var input = document.getElementById('mot_de_passe');
if(!eye || !input) return;
// Mobile (iOS/Android) — empêche sélection/callout et révèle/masque
eye.addEventListener('touchstart', function(e){ e.preventDefault(); revealPwd('mot_de_passe'); }, {passive:false});
eye.addEventListener('touchend', function(e){ e.preventDefault(); hidePwd('mot_de_passe'); }, {passive:false});
eye.addEventListener('touchcancel',function(){ hidePwd('mot_de_passe'); });
// Desktop / trackpad — empêche sélection au maintien
eye.addEventListener('mousedown', function(e){ e.preventDefault(); revealPwd('mot_de_passe'); });
eye.addEventListener('mouseup', function(e){ e.preventDefault(); hidePwd('mot_de_passe'); });
eye.addEventListener('mouseleave',function(){ hidePwd('mot_de_passe'); });
})();
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>