diff --git a/.gitignore b/.gitignore index 0ec0287..4be7e6c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ tmp vendor composer.json composer.lock -#src/Framework/SwiftMailerFactory.php \ No newline at end of file +src/Framework/SwiftMailerFactory.php \ No newline at end of file diff --git a/public/js/connex.js b/public/js/connex.js index af783bb..ebe8e37 100644 --- a/public/js/connex.js +++ b/public/js/connex.js @@ -16,12 +16,12 @@ function connexion(nom_connecte, mdp, chemin) { $("#user-connecte").css('display',"inline-block"); $("#contenu_bouton").html(''); $("#contenu_bouton").append(result.username); - //$("#input_connecte").attr('value',result.username); $("#nom_connecte_bis").append(result.username); $('#formulaire').attr('action', '/profil/user/'+result.username); $("#deconnexion").css('display',"block"); $("#inscription").css('display',"none"); + window.location.reload(true); } else { $('.alert-danger').html(''); $(".alert-danger").css('display',"block"); diff --git a/public/models/connexion.php b/public/models/connexion.php index fed2ef4..df0df0a 100644 --- a/public/models/connexion.php +++ b/public/models/connexion.php @@ -18,7 +18,8 @@ try { $row = $query->fetch(PDO::FETCH_ASSOC); if (password_verify($_POST['mdp'],$row['password'])) { - $_SESSION['connecte']=$row['username']; + $_SESSION['connecte'] = $row['username']; + $_SESSION['logout'] = false; echo '{"valide":true,"username":"'.$row['username'].'"}'; } else { echo '{"valide":false}'; diff --git a/src/Admin/DashboardAction.php b/src/Admin/DashboardAction.php index 9f388c5..3a104a5 100644 --- a/src/Admin/DashboardAction.php +++ b/src/Admin/DashboardAction.php @@ -1,6 +1,8 @@ session->set('username',$username); $this->session->set('role',$role); } - + $sess = $_SESSION; return $this->renderer->render('@admin/dashboard', - compact('username','liste_adminGeneral', 'liste_users_suivi', + compact('sess','username','liste_adminGeneral', 'liste_users_suivi', 'liste_adminAntenne', 'listeAntennes')); } } diff --git a/src/Admin/DashboardUserAction.php b/src/Admin/DashboardUserAction.php index 894618b..8f81024 100644 --- a/src/Admin/DashboardUserAction.php +++ b/src/Admin/DashboardUserAction.php @@ -1,6 +1,8 @@ id; $actif_affiche = $user->actif; $listeAntennes = $this->antenneTable->findAllAntennes(); - + $sess = $_SESSION; return $this->renderer->render('@admin/dashboard_user', - compact('user_affiche','id_affiche', 'actif_affiche', 'user','liste_users_suivi','listeAntennes')); + compact('sess','user_affiche','id_affiche', 'actif_affiche', 'user','liste_users_suivi','listeAntennes')); } } } diff --git a/src/Auth/Action/LoginAction.php b/src/Auth/Action/LoginAction.php index 8a11870..ad2e9cb 100644 --- a/src/Auth/Action/LoginAction.php +++ b/src/Auth/Action/LoginAction.php @@ -1,6 +1,8 @@ renderer->render('@auth/login'); + if ($_SESSION['connecte']) { + $_SESSION['logout'] = false; + //echo "session co = valeur"; + //die(); + } else { + //echo "session co = vide"; + //die(); + } + return $this->renderer->render('@auth/login', ['sess' => $_SESSION]); } } diff --git a/src/Auth/Action/LoginAttemptAction.php b/src/Auth/Action/LoginAttemptAction.php index ee5e30c..e968b71 100644 --- a/src/Auth/Action/LoginAttemptAction.php +++ b/src/Auth/Action/LoginAttemptAction.php @@ -1,6 +1,8 @@ test_user($user, $params); + $_SESSION['logout']= false; return $this->renderer->render('@gmarche/index'); } else { (new FlashService($this->session))->error('Identifiant ou mot de passe incorrect'); diff --git a/src/Auth/Action/LogoutAction.php b/src/Auth/Action/LogoutAction.php index ee22020..5f2086d 100644 --- a/src/Auth/Action/LogoutAction.php +++ b/src/Auth/Action/LogoutAction.php @@ -1,6 +1,8 @@ "; + var_dump($request); + echo ""; + die();*/ unset($_SESSION['user']); - unset($_SESSION['connecte']); + $_SESSION['connecte']='---'; + $_SESSION['logout']=true; if ($this->session->get('username')) { $this->session->delete('username'); } diff --git a/src/Contact/ContactAction.php b/src/Contact/ContactAction.php index 7e67ac6..deaf409 100644 --- a/src/Contact/ContactAction.php +++ b/src/Contact/ContactAction.php @@ -35,7 +35,15 @@ class ContactAction $nom_user = ''; $role = '3'; } - $sess = $_SESSION; + if ($_SESSION['logout']) { + //echo "logout"; + //die(); + $sess = null; + } else { + //echo "non logout"; + //die(); + $sess = $_SESSION; + } return $this->renderer->render('@contact/contact',compact('sess','nom_user','role')); } } diff --git a/src/Framework/Auth/LoggedInMiddleware.php b/src/Framework/Auth/LoggedInMiddleware.php index 36658ca..2da7773 100644 --- a/src/Framework/Auth/LoggedInMiddleware.php +++ b/src/Framework/Auth/LoggedInMiddleware.php @@ -1,5 +1,8 @@ getServerParams()['HTTP_REFERER'] ?? '/'); $username = $url_part[5]; - - if (is_null($username)) { - $user = $this->auth->getUser() ?: $this->userTable->findBy('username', $request->getAttribute('user')); + if (!$_SESSION['logout']) { + // echo "logout = false"; + // die(); } else { - $user = $this->auth->getUser() ?: $this->userTable->findBy('username', $username); + // echo "logout = true"; + // die(); } - if (is_null($user)) { + + if (!$_SESSION['logout']) { + if (is_null($username)) { + $user = $this->auth->getUser() ?: $this->userTable->findBy('username', $request->getAttribute('user')); + } else { + $user = $this->auth->getUser() ?: $this->userTable->findBy('username', $username); + } + } + // var_dump($user); + // die(); + if (is_null($user) or $_SESSION['logout']) { (new FlashService($this->session))->error('Vous devez vous connecter pour accéder à cette page'); return new RedirectResponse($this->router->generateUri('auth.login')); } diff --git a/src/Product/views/admin/products/index.twig b/src/Product/views/admin/products/index.twig index f83ae70..5e8146a 100644 --- a/src/Product/views/admin/products/index.twig +++ b/src/Product/views/admin/products/index.twig @@ -50,7 +50,7 @@ Mettez bien le pseudo, la clé publique, le bien ou service, et le prix en june.

- {% if affiche_username() != '' or sess.connecte != '' %} + {% if affiche_username() != '' or (sess.connecte != '' and sess.connecte != '---') %}

diff --git a/views/layout.twig b/views/layout.twig index 7f55575..6f08a48 100644 --- a/views/layout.twig +++ b/views/layout.twig @@ -45,10 +45,18 @@ Accueil - {% if (affiche_role()==0 or affiche_role()==1 or affiche_role()==2) and affiche_username()!='' %} + {% if (affiche_role()==0 or affiche_role()==1 or affiche_role()==2) and (affiche_username() !='' + or (sess.connecte != '' and sess.connecte != '---')) %} {% endif %}