diff options
| author | polo <ordipolo@gmx.fr> | 2025-06-24 23:57:59 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2025-06-24 23:57:59 +0200 |
| commit | 7a13d53e43c7db7fe39474208ffa54ba2906d308 (patch) | |
| tree | 5bb9af2935c0e7c753c5eace6d9e4538c739a383 | |
| parent | 41adf94ebf868232aa43fe9b8b80029896da9da7 (diff) | |
| download | cms-7a13d53e43c7db7fe39474208ffa54ba2906d308.tar.gz cms-7a13d53e43c7db7fe39474208ffa54ba2906d308.tar.bz2 cms-7a13d53e43c7db7fe39474208ffa54ba2906d308.zip | |
petites améliorations au système de mot de passe
| -rw-r--r-- | public/css/calendar.css | 4 | ||||
| -rw-r--r-- | public/index.php | 8 | ||||
| -rw-r--r-- | src/controller/ajax_calendar_admin.php (renamed from src/controller/ajax_calendar.php) | 37 | ||||
| -rw-r--r-- | src/controller/ajax_calendar_visitor.php | 39 | ||||
| -rw-r--r-- | src/controller/password.php | 16 | ||||
| -rw-r--r-- | src/controller/post.php | 13 | ||||
| -rw-r--r-- | src/view/password.php | 4 |
7 files changed, 70 insertions, 51 deletions
diff --git a/public/css/calendar.css b/public/css/calendar.css index ba9a462..1cfb0fd 100644 --- a/public/css/calendar.css +++ b/public/css/calendar.css | |||
| @@ -34,6 +34,10 @@ td .fc-timegrid-axis{ | |||
| 34 | .fc-day-other{ | 34 | .fc-day-other{ |
| 35 | background-color: #f0f0f0; | 35 | background-color: #f0f0f0; |
| 36 | } | 36 | } |
| 37 | .fc-daygrid-day:not(.fc-day-other, .fc-day-today){ | ||
| 38 | background-color: #ffffff; | ||
| 39 | } | ||
| 40 | |||
| 37 | .fc-daygrid-day-top{ | 41 | .fc-daygrid-day-top{ |
| 38 | justify-content: center; | 42 | justify-content: center; |
| 39 | } | 43 | } |
diff --git a/public/index.php b/public/index.php index d6ca8d4..56af032 100644 --- a/public/index.php +++ b/public/index.php | |||
| @@ -31,6 +31,10 @@ ini_set('session.use_strict_mode', 'On'); | |||
| 31 | ini_set('session.cookie_secure', 'On'); | 31 | ini_set('session.cookie_secure', 'On'); |
| 32 | session_start(); | 32 | session_start(); |
| 33 | $_SESSION['admin'] = !isset($_SESSION['admin']) ? false : $_SESSION['admin']; // intialisation sur faux | 33 | $_SESSION['admin'] = !isset($_SESSION['admin']) ? false : $_SESSION['admin']; // intialisation sur faux |
| 34 | if($_SESSION['admin'] === false || empty($_SESSION['user'])){ // OUT !! | ||
| 35 | $_SESSION['user'] = ''; | ||
| 36 | $_SESSION['admin'] = false; | ||
| 37 | } | ||
| 34 | 38 | ||
| 35 | // login, mot de passe et captcha | 39 | // login, mot de passe et captcha |
| 36 | require '../src/controller/password.php'; | 40 | require '../src/controller/password.php'; |
| @@ -49,8 +53,8 @@ require '../src/controller/post.php'; | |||
| 49 | $id = ''; | 53 | $id = ''; |
| 50 | if(!empty($_GET['id'])) | 54 | if(!empty($_GET['id'])) |
| 51 | { | 55 | { |
| 52 | //$id = (int)$_GET['id']; // (int) = moyen basique d'éviter les injections | 56 | $id = (int)$_GET['id']; // (int) évite les injections, pas parfait d'après chatgpt |
| 53 | $id = Security::secureString($_GET['id']); | 57 | //$id = Security::quelqueChose($_GET['id']); |
| 54 | } | 58 | } |
| 55 | 59 | ||
| 56 | if(isset($_GET['action']) && $_GET['action'] === 'deconnexion') | 60 | if(isset($_GET['action']) && $_GET['action'] === 'deconnexion') |
diff --git a/src/controller/ajax_calendar.php b/src/controller/ajax_calendar_admin.php index 79268f6..0baf73e 100644 --- a/src/controller/ajax_calendar.php +++ b/src/controller/ajax_calendar_admin.php | |||
| @@ -1,45 +1,12 @@ | |||
| 1 | <?php | 1 | <?php |
| 2 | // src/controller/calendar.php | 2 | // src/controller/ajax_calendar_admin.php |
| 3 | 3 | ||
| 4 | declare(strict_types=1); | 4 | declare(strict_types=1); |
| 5 | 5 | ||
| 6 | use App\Entity\Event; | 6 | use App\Entity\Event; |
| 7 | 7 | ||
| 8 | // chargement des évènements à la création du calendrier | ||
| 9 | // et au changement de dates affichées (boutons flèches mais pas changement de vue) | ||
| 10 | if($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['action']) && $_GET['action'] === 'get_events' | ||
| 11 | && isset($_GET['start']) && isset($_GET['end']) && empty($_POST)) | ||
| 12 | { | ||
| 13 | // bornes début et fin du calendrier affiché à l'heure locale | ||
| 14 | // noter que la vue "planning" est similaire à la vue "semaine" | ||
| 15 | $start = new DateTime($_GET['start']); | ||
| 16 | $end = new DateTime($_GET['end']); | ||
| 17 | $start->setTimezone(new DateTimeZone('UTC')); | ||
| 18 | $end->setTimezone(new DateTimeZone('UTC')); | ||
| 19 | |||
| 20 | // affichage format ISO à l'heure UTC | ||
| 21 | //$date->format('Y-m-d\TH:i:s\Z'); | ||
| 22 | |||
| 23 | // on prend les évènements se finissant après le début ou commençant avant la fin de la fourchette | ||
| 24 | $dql = 'SELECT e FROM App\Entity\Event e WHERE e.end >= :start AND e.start <= :end'; | ||
| 25 | $bulk_data = $entityManager->createQuery($dql) | ||
| 26 | ->setParameter('start', $start) | ||
| 27 | ->setParameter('end', $end) | ||
| 28 | ->getResult(); | ||
| 29 | |||
| 30 | $events = []; | ||
| 31 | foreach($bulk_data as $one_entry){ | ||
| 32 | $event = new EventDTO($one_entry); | ||
| 33 | $events[] = $event->toArray(); | ||
| 34 | } | ||
| 35 | |||
| 36 | header('Content-Type: application/json'); | ||
| 37 | echo json_encode($events); | ||
| 38 | die; | ||
| 39 | } | ||
| 40 | |||
| 41 | // actions sur le calendrier | 8 | // actions sur le calendrier |
| 42 | elseif(isset($_SESSION['admin']) && $_SESSION['admin'] === true | 9 | if(isset($_SESSION['admin']) && $_SESSION['admin'] === true |
| 43 | && $_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/json') | 10 | && $_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/json') |
| 44 | { | 11 | { |
| 45 | $data = file_get_contents('php://input'); | 12 | $data = file_get_contents('php://input'); |
diff --git a/src/controller/ajax_calendar_visitor.php b/src/controller/ajax_calendar_visitor.php new file mode 100644 index 0000000..dcdbebd --- /dev/null +++ b/src/controller/ajax_calendar_visitor.php | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | <?php | ||
| 2 | // src/controller/ajax_calendar_visitor.php | ||
| 3 | |||
| 4 | declare(strict_types=1); | ||
| 5 | |||
| 6 | use App\Entity\Event; | ||
| 7 | |||
| 8 | // chargement des évènements à la création du calendrier | ||
| 9 | // et au changement de dates affichées (boutons flèches mais pas changement de vue) | ||
| 10 | if($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['action']) && $_GET['action'] === 'get_events' | ||
| 11 | && isset($_GET['start']) && isset($_GET['end']) && empty($_POST)) | ||
| 12 | { | ||
| 13 | // bornes début et fin du calendrier affiché à l'heure locale | ||
| 14 | // noter que la vue "planning" est similaire à la vue "semaine" | ||
| 15 | $start = new DateTime($_GET['start']); | ||
| 16 | $end = new DateTime($_GET['end']); | ||
| 17 | $start->setTimezone(new DateTimeZone('UTC')); | ||
| 18 | $end->setTimezone(new DateTimeZone('UTC')); | ||
| 19 | |||
| 20 | // affichage format ISO à l'heure UTC | ||
| 21 | //$date->format('Y-m-d\TH:i:s\Z'); | ||
| 22 | |||
| 23 | // on prend les évènements se finissant après le début ou commençant avant la fin de la fourchette | ||
| 24 | $dql = 'SELECT e FROM App\Entity\Event e WHERE e.end >= :start AND e.start <= :end'; | ||
| 25 | $bulk_data = $entityManager->createQuery($dql) | ||
| 26 | ->setParameter('start', $start) | ||
| 27 | ->setParameter('end', $end) | ||
| 28 | ->getResult(); | ||
| 29 | |||
| 30 | $events = []; | ||
| 31 | foreach($bulk_data as $one_entry){ | ||
| 32 | $event = new EventDTO($one_entry); | ||
| 33 | $events[] = $event->toArray(); | ||
| 34 | } | ||
| 35 | |||
| 36 | header('Content-Type: application/json'); | ||
| 37 | echo json_encode($events); | ||
| 38 | die; | ||
| 39 | } \ No newline at end of file | ||
diff --git a/src/controller/password.php b/src/controller/password.php index 5573a33..62b1542 100644 --- a/src/controller/password.php +++ b/src/controller/password.php | |||
| @@ -86,7 +86,7 @@ function createPassword(EntityManager $entityManager) | |||
| 86 | } | 86 | } |
| 87 | else | 87 | else |
| 88 | { | 88 | { |
| 89 | $error = 'bad_password'; | 89 | $error = 'bad_login_or_password'; |
| 90 | 90 | ||
| 91 | // compteur dans la session et blocage de compte | 91 | // compteur dans la session et blocage de compte |
| 92 | } | 92 | } |
| @@ -217,15 +217,6 @@ function changePassword(EntityManager $entityManager) | |||
| 217 | { | 217 | { |
| 218 | // fonction exécutée à priori deux fois d'affilée: affichage puis traitement de la saisie | 218 | // fonction exécutée à priori deux fois d'affilée: affichage puis traitement de la saisie |
| 219 | 219 | ||
| 220 | // OUT !! | ||
| 221 | if(empty($_SESSION['user']) || !$_SESSION['admin']) | ||
| 222 | { | ||
| 223 | $_SESSION['user'] = ''; | ||
| 224 | $_SESSION['admin'] = false; | ||
| 225 | header('Location: index.php'); | ||
| 226 | die; | ||
| 227 | } | ||
| 228 | |||
| 229 | // II - traitement | 220 | // II - traitement |
| 230 | $error = ''; | 221 | $error = ''; |
| 231 | $success = false; | 222 | $success = false; |
| @@ -254,6 +245,9 @@ function changePassword(EntityManager $entityManager) | |||
| 254 | { | 245 | { |
| 255 | $error = 'forbidden_characters'; | 246 | $error = 'forbidden_characters'; |
| 256 | } | 247 | } |
| 248 | elseif($login !== $_SESSION['user']){ | ||
| 249 | $error = 'bad_login_or_password'; | ||
| 250 | } | ||
| 257 | else | 251 | else |
| 258 | { | 252 | { |
| 259 | $user = getUser($login, $entityManager); | 253 | $user = getUser($login, $entityManager); |
| @@ -268,7 +262,7 @@ function changePassword(EntityManager $entityManager) | |||
| 268 | } | 262 | } |
| 269 | else | 263 | else |
| 270 | { | 264 | { |
| 271 | $error = 'bad_password'; | 265 | $error = 'bad_login_or_password'; |
| 272 | } | 266 | } |
| 273 | } | 267 | } |
| 274 | } | 268 | } |
diff --git a/src/controller/post.php b/src/controller/post.php index b0bc6a0..3ba0656 100644 --- a/src/controller/post.php +++ b/src/controller/post.php | |||
| @@ -220,6 +220,14 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
| 220 | header("Location: " . new URL(['page' => $_GET['from']])); | 220 | header("Location: " . new URL(['page' => $_GET['from']])); |
| 221 | die; | 221 | die; |
| 222 | } | 222 | } |
| 223 | elseif(isset($_GET['action']) && $_GET['action'] === 'modif_mdp' | ||
| 224 | && isset($_POST['login']) && isset($_POST['old_password']) && isset($_POST['new_password']) | ||
| 225 | && isset($_POST['modify_password_hidden']) && empty($_POST['modify_password_hidden'])) | ||
| 226 | { | ||
| 227 | changePassword($entityManager); | ||
| 228 | header("Location: " . new URL(['page' => $_GET['from']])); | ||
| 229 | die; | ||
| 230 | } | ||
| 223 | else{ | 231 | else{ |
| 224 | header("Location: " . new URL(['error' => 'paramètres inconnus'])); | 232 | header("Location: " . new URL(['error' => 'paramètres inconnus'])); |
| 225 | die; | 233 | die; |
| @@ -230,5 +238,8 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
| 230 | else{ | 238 | else{ |
| 231 | require '../src/controller/ajax.php'; | 239 | require '../src/controller/ajax.php'; |
| 232 | } | 240 | } |
| 241 | |||
| 242 | require '../src/controller/ajax_calendar_admin.php'; | ||
| 233 | } | 243 | } |
| 234 | require '../src/controller/ajax_calendar.php'; \ No newline at end of file | 244 | |
| 245 | require '../src/controller/ajax_calendar_visitor.php'; | ||
diff --git a/src/view/password.php b/src/view/password.php index ed99040..77f8736 100644 --- a/src/view/password.php +++ b/src/view/password.php | |||
| @@ -72,6 +72,7 @@ ob_start(); | |||
| 72 | <input id="old_password" type="password" name="old_password" required ><br><br> | 72 | <input id="old_password" type="password" name="old_password" required ><br><br> |
| 73 | <label for="new_password" >Nouveau mot de passe:</label> | 73 | <label for="new_password" >Nouveau mot de passe:</label> |
| 74 | <input id="new_password" type="password" name="new_password" required autocomplete="off"> | 74 | <input id="new_password" type="password" name="new_password" required autocomplete="off"> |
| 75 | <input type="hidden" name="modify_password_hidden"> | ||
| 75 | <br><br> | 76 | <br><br> |
| 76 | <input type="submit" value="Valider" > | 77 | <input type="submit" value="Valider" > |
| 77 | </form> | 78 | </form> |
| @@ -109,8 +110,7 @@ $header = ob_get_clean(); | |||
| 109 | $error_messages = [ | 110 | $error_messages = [ |
| 110 | 'error_non_valid_captcha' => '<p class="avertissement" >Erreur au test anti-robot, veuillez saisir un nombre entier.</p>', | 111 | 'error_non_valid_captcha' => '<p class="avertissement" >Erreur au test anti-robot, veuillez saisir un nombre entier.</p>', |
| 111 | 'bad_solution_captcha' => '<p class="avertissement" >Erreur au test anti-robot, veuillez réessayer.</p>', | 112 | 'bad_solution_captcha' => '<p class="avertissement" >Erreur au test anti-robot, veuillez réessayer.</p>', |
| 112 | 'bad_login_or_password' => '<p class="avertissement" >Mauvais identifiant ou mot de passe, veuillez réessayer.</p>', | 113 | 'bad_login_or_password' => '<p class="avertissement" >Mauvais identifiant ou mot de passe, veuillez réessayer.</p>', // ne pas indiquer où est l'erreur |
| 113 | 'bad_password' => '<p class="avertissement" >Mauvais mot de passe, veuillez réessayer.</p>', | ||
| 114 | 'forbidden_characters' => '<p class="avertissement" >Caractères interdits: espaces, tabulations, sauts CR/LF.</p>' | 114 | 'forbidden_characters' => '<p class="avertissement" >Caractères interdits: espaces, tabulations, sauts CR/LF.</p>' |
| 115 | ]; | 115 | ]; |
| 116 | 116 | ||
