From 2a01413fabd6e6861bd69e359effbd15a29f4b66 Mon Sep 17 00:00:00 2001 From: nox Date: Sun, 5 Jan 2020 04:16:48 +0100 Subject: [PATCH] =?UTF-8?q?Affichage=20de=20l'utilisateur=20connect=C3=A9?= =?UTF-8?q?=20correct=20en=20connexion=20modale=20ou=20autre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- public/js/connex.js | 3 +++ public/js/script.js | 7 ++++-- public/models/connexion.php | 6 ++++- public/models/readRecords.php | 2 +- public/models/readRecords2.php | 2 +- src/Auth/Action/LogoutAction.php | 8 +++--- src/Contact/ContactAction.php | 14 +++++------ .../Renderer/TwigRendererFactory.php | 1 + src/Framework/SwiftMailerFactory.php | 4 +-- src/Gmarche/Actions/AntenneShowAction.php | 25 ++++++++++--------- src/Gmarche/Actions/RegionIndexAction.php | 12 +++++---- src/Product/Actions/ProductIndexAction.php | 15 +++++------ src/Product/Actions/RechIndexAction.php | 17 ++++++------- src/Product/views/admin/products/index.twig | 2 +- views/layout.twig | 18 +++++++------ 16 files changed, 77 insertions(+), 61 deletions(-) diff --git a/.gitignore b/.gitignore index 4be7e6c..0ec0287 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 59ff434..af783bb 100644 --- a/public/js/connex.js +++ b/public/js/connex.js @@ -16,6 +16,9 @@ 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"); diff --git a/public/js/script.js b/public/js/script.js index d05d0ba..992e667 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -231,8 +231,11 @@ $(document).ready(function () { var url = document.location.href; var antenne_slug = url.split('/')[5]; var affichage_slug = url.split('/')[6]; - var nom_connecte = $("#nom_connecte").text(); - + var nom_connecte = $("#contenu_bouton").text().trim(); + if (nom_connecte == '') { + nom_connecte = $("#nom_connecte_bis").text(); + nom_connecte = nom_connecte.trim(); + } if (affichage_slug == 'produits') { $("#hidden_antenne_slug").val(antenne_slug); readRecords(antenne_slug, nom_connecte); diff --git a/public/models/connexion.php b/public/models/connexion.php index 08a8220..fed2ef4 100644 --- a/public/models/connexion.php +++ b/public/models/connexion.php @@ -1,5 +1,7 @@ prepare($requete); $query->execute($params); $row = $query->fetch(PDO::FETCH_ASSOC); + if (password_verify($_POST['mdp'],$row['password'])) { + $_SESSION['connecte']=$row['username']; echo '{"valide":true,"username":"'.$row['username'].'"}'; } else { echo '{"valide":false}'; diff --git a/public/models/readRecords.php b/public/models/readRecords.php index 76ae9c6..594e2ff 100644 --- a/public/models/readRecords.php +++ b/public/models/readRecords.php @@ -3,7 +3,7 @@ ini_set('display_errors', 0); include '../../config/config.php'; $antenne_slug = $_GET['antenne_slug']; - $nom_connecte = $_SESSION['user']; + $nom_connecte = $_GET['nom_connecte']; $bdd = new \PDO("mysql:host=$db_server;dbname=$db_name", $db_username, $db_password); // Affichage des intitulés de colonnes diff --git a/public/models/readRecords2.php b/public/models/readRecords2.php index f560335..9114b9e 100644 --- a/public/models/readRecords2.php +++ b/public/models/readRecords2.php @@ -3,7 +3,7 @@ ini_set('display_errors', 0); include '../../config/config.php'; $antenne_slug = $_GET['antenne_slug']; - $nom_connecte = $_SESSION['user']; + $nom_connecte = $_GET['nom_connecte']; $bdd = new \PDO("mysql:host=$db_server;dbname=$db_name", $db_username, $db_password); // Affichage des intitulés de colonnes diff --git a/src/Auth/Action/LogoutAction.php b/src/Auth/Action/LogoutAction.php index 740b392..ee22020 100644 --- a/src/Auth/Action/LogoutAction.php +++ b/src/Auth/Action/LogoutAction.php @@ -2,6 +2,7 @@ namespace App\Auth\Action; use App\Auth\DatabaseAuth; +use App\Framework\Response\RedirectBackResponse; use Framework\Renderer\RendererInterface; use Framework\Response\RedirectResponse; use Framework\Session\FlashService; @@ -43,16 +44,13 @@ class LogoutAction public function __invoke(ServerRequestInterface $request) { - $gmarchePrefix = $this->container->get('gmarche.prefix'); - if(!isset($_SESSION)) { - //session_start(); - } unset($_SESSION['user']); + unset($_SESSION['connecte']); if ($this->session->get('username')) { $this->session->delete('username'); } $this->auth->logout(); $this->flashService->success('Vous êtes maintenant déconnecté'); - return new RedirectResponse("$gmarchePrefix"); + return new RedirectBackResponse($request); } } diff --git a/src/Contact/ContactAction.php b/src/Contact/ContactAction.php index fd6b785..7e67ac6 100644 --- a/src/Contact/ContactAction.php +++ b/src/Contact/ContactAction.php @@ -1,6 +1,8 @@ getMethod() === 'GET') { - if (!isset($_SESSION)) { - //session_start(); - } - if (isset($_SESSION['user'])) { - $nom_user = $_SESSION['user']; + if (isset($_SESSION['connecte'])) { + $nom_user = $_SESSION['connecte']; $role = $_SESSION['role']; } else { $nom_user = ''; $role = '3'; } - return $this->renderer->render('@contact/contact',compact('nom_user','role')); + $sess = $_SESSION; + return $this->renderer->render('@contact/contact',compact('sess','nom_user','role')); } } } diff --git a/src/Framework/Renderer/TwigRendererFactory.php b/src/Framework/Renderer/TwigRendererFactory.php index 8a8d76f..0f414fd 100644 --- a/src/Framework/Renderer/TwigRendererFactory.php +++ b/src/Framework/Renderer/TwigRendererFactory.php @@ -20,6 +20,7 @@ class TwigRendererFactory 'auto_reload' => $debug ]); $twig->addExtension(new DebugExtension()); + //$twig->addGlobal('session', $_SESSION); if ($container->has('twig.extensions')) { foreach ($container->get('twig.extensions') as $extension) { $twig->addExtension($extension); diff --git a/src/Framework/SwiftMailerFactory.php b/src/Framework/SwiftMailerFactory.php index b80d127..00af7f4 100644 --- a/src/Framework/SwiftMailerFactory.php +++ b/src/Framework/SwiftMailerFactory.php @@ -9,8 +9,8 @@ class SwiftMailerFactory public function __invoke(ContainerInterface $container): \Swift_Mailer { if ($container->get('env') === 'production') { - $transport = new \Swift_SmtpTransport('localhost', 1025); - //$transport = new \Swift_SendmailTransport(); + //$transport = new \Swift_SmtpTransport('localhost', 1025); + $transport = new \Swift_SendmailTransport(); } else { $transport = new \Swift_SmtpTransport('localhost', 1025); } diff --git a/src/Gmarche/Actions/AntenneShowAction.php b/src/Gmarche/Actions/AntenneShowAction.php index 4b5a33b..53781fd 100644 --- a/src/Gmarche/Actions/AntenneShowAction.php +++ b/src/Gmarche/Actions/AntenneShowAction.php @@ -1,14 +1,14 @@ "; + var_dump($container); + echo ""; + die();*/ if ($request->getMethod() === 'GET') { $params = $request->getQueryParams(); $gmarchePrefix = $this->container->get('gmarche.prefix'); @@ -55,21 +59,18 @@ class AntenneShowAction $antennes = $this->antenneTable->findAllbyRegion($region_id)->paginate(25, $page); $region = $this->regionTable->findBy('slug', $request->getAttribute('slug')); + $var_test = 'test'; + //var_dump($antennes); + //die(); /*if ($region->slug !== $slug) { return $this->redirect('gmarche.show', [ 'slug' => $region->slug, 'id' => $region->id ]); }*/ - if (!isset($_SESSION)) { - //session_start(); - } - if (isset($_SESSION['user'])) { - $nom_user = $_SESSION['user']; - } else { - $nom_user = ''; - } - return $this->renderer->render('@gmarche/antenne', compact('nom_user', 'slug', 'region', 'gmarchePrefix', 'antennes', 'page')); + $sess = $_SESSION; + + return $this->renderer->render('@gmarche/antenne', compact('sess','page', 'gmarchePrefix','region', 'antennes')); } } } diff --git a/src/Gmarche/Actions/RegionIndexAction.php b/src/Gmarche/Actions/RegionIndexAction.php index 2e8345d..cda03a3 100644 --- a/src/Gmarche/Actions/RegionIndexAction.php +++ b/src/Gmarche/Actions/RegionIndexAction.php @@ -1,6 +1,8 @@ userTable->findBy('username', $params['username'])->role; //var_dump($role); //die(); - if (!isset($_SESSION)) { - //session_start(); - } + $accueil = true; + if (isset($_SESSION['user'])) { $nom_user = $_SESSION['user']; $role = $_SESSION['role']; @@ -45,7 +46,8 @@ class RegionIndexAction $nom_user = ''; $role = '3'; } - return $this->renderer->render('@gmarche/index', compact('nom_user', 'accueil', 'role')); + $sess = $_SESSION; + return $this->renderer->render('@gmarche/index', compact('sess','nom_user', 'accueil', 'role')); } } } diff --git a/src/Product/Actions/ProductIndexAction.php b/src/Product/Actions/ProductIndexAction.php index 127f44c..e1985b9 100644 --- a/src/Product/Actions/ProductIndexAction.php +++ b/src/Product/Actions/ProductIndexAction.php @@ -1,6 +1,8 @@ productTable->findByAntenneId('antenne_id', $antenne_id)->paginate(20, $page); - if (!isset($_SESSION)) { - //session_start(); - } - if (isset($_SESSION['user'])) { - $nom_user = $_SESSION['user']; + + if (isset($_SESSION['connecte'])) { + $nom_user = $_SESSION['connecte']; $requete_user = $this->userTable->findBy('username', $nom_user); $user_id = $requete_user->id; } else { $nom_user = ''; $user_id = ''; } - return $this->renderer->render($viewPath.'/index', compact('nom_user','user_id', 'antenne_slug','gmarchePrefix','region_name','region_slug','antenne_id','antenne_name','viewPath', 'items' )); + $sess = $_SESSION; + return $this->renderer->render($viewPath.'/index', compact('sess','nom_user','user_id', 'antenne_slug','gmarchePrefix','region_name','region_slug','antenne_id','antenne_name','viewPath', 'items' )); } } diff --git a/src/Product/Actions/RechIndexAction.php b/src/Product/Actions/RechIndexAction.php index 5c957d3..fb918a9 100644 --- a/src/Product/Actions/RechIndexAction.php +++ b/src/Product/Actions/RechIndexAction.php @@ -1,6 +1,8 @@ regionTable->findBy('slug', $region_slug); $region_name = $requete_region->name; $page = $params['p'] ?? 1; - //$routePrefix = 'product.admin'; - //$routePrefix = 'product.index'; $viewPath = '@product/admin/recherches'; $items = $this->rechTable->findByAntenneId('antenne_id', $antenne_id)->paginate(20, $page); - if (!isset($_SESSION)) { - //session_start(); - } - if (isset($_SESSION['user'])) { - $nom_user = $_SESSION['user']; + + if (isset($_SESSION['connecte'])) { + $nom_user = $_SESSION['connecte']; $requete_user = $this->userTable->findBy('username', $nom_user); $user_id = $requete_user->id; } else { $nom_user = ''; $user_id = ''; } - return $this->renderer->render($viewPath.'/index', compact('nom_user','user_id','antenne_slug','gmarchePrefix','region_name','region_slug','antenne_id','antenne_name','viewPath', 'items' )); + $sess = $_SESSION; + return $this->renderer->render($viewPath.'/index', compact('sess','nom_user','user_id','antenne_slug','gmarchePrefix','region_name','region_slug','antenne_id','antenne_name','viewPath', 'items' )); } } diff --git a/src/Product/views/admin/products/index.twig b/src/Product/views/admin/products/index.twig index 9ca1f39..f83ae70 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 nom_user != '' %} + {% if affiche_username() != '' or sess.connecte != '' %} +

{{ field('email', affiche_mail(), "", {type: 'hidden'}) }}
@@ -75,12 +80,11 @@ {% else %} -
+
@@ -119,7 +123,7 @@