Ajustement de la deconnexion et du desaffichage de l'utilisateur qui etait connecte

master
nox 3 years ago
parent 2a01413fab
commit 0ab166726c
  1. 2
      .gitignore
  2. 2
      public/js/connex.js
  3. 3
      public/models/connexion.php
  4. 8
      src/Admin/DashboardAction.php
  5. 8
      src/Admin/DashboardUserAction.php
  6. 14
      src/Auth/Action/LoginAction.php
  7. 5
      src/Auth/Action/LoginAttemptAction.php
  8. 11
      src/Auth/Action/LogoutAction.php
  9. 10
      src/Contact/ContactAction.php
  10. 24
      src/Framework/Auth/LoggedInMiddleware.php
  11. 2
      src/Product/views/admin/products/index.twig
  12. 12
      src/Product/views/admin/recherches/index.twig
  13. 14
      views/layout.twig

2
.gitignore vendored

@ -8,4 +8,4 @@ tmp
vendor
composer.json
composer.lock
#src/Framework/SwiftMailerFactory.php
src/Framework/SwiftMailerFactory.php

@ -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");

@ -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}';

@ -1,6 +1,8 @@
<?php
namespace App\Admin;
if (!isset($_SESSION)) {
session_start();
}
use App\Admin\Table\UserTable;
use App\Gmarche\Table\AntenneTable;
use Framework\Renderer\RendererInterface;
@ -64,9 +66,9 @@ class DashboardAction
$this->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'));
}
}

@ -1,6 +1,8 @@
<?php
namespace App\Admin;
if (!isset($_SESSION)) {
session_start();
}
use App\Auth\UserTable;
use App\Admin\Table\UserTable as UserTableAdmin;
use App\Gmarche\Table\AntenneTable;
@ -58,9 +60,9 @@ class DashboardUserAction
$id_affiche = $user->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'));
}
}
}

@ -1,6 +1,8 @@
<?php
namespace App\Auth\Action;
if (!isset($_SESSION)) {
session_start();
}
use Framework\Renderer\RendererInterface;
use Psr\Http\Message\ServerRequestInterface;
@ -19,6 +21,14 @@ class LoginAction
public function __invoke(ServerRequestInterface $request)
{
return $this->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]);
}
}

@ -1,6 +1,8 @@
<?php
namespace App\Auth\Action;
if (!isset($_SESSION)) {
session_start();
}
use App\Admin\Table\UserTable;
use App\Auth\DatabaseAuth;
use Framework\Actions\RouterAwareAction;
@ -57,6 +59,7 @@ class LoginAttemptAction
if ($user) {
$this->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');

@ -1,6 +1,8 @@
<?php
namespace App\Auth\Action;
if (!isset($_SESSION)) {
session_start();
}
use App\Auth\DatabaseAuth;
use App\Framework\Response\RedirectBackResponse;
use Framework\Renderer\RendererInterface;
@ -44,8 +46,13 @@ class LogoutAction
public function __invoke(ServerRequestInterface $request)
{
/*echo "<pre>";
var_dump($request);
echo "</pre>";
die();*/
unset($_SESSION['user']);
unset($_SESSION['connecte']);
$_SESSION['connecte']='---';
$_SESSION['logout']=true;
if ($this->session->get('username')) {
$this->session->delete('username');
}

@ -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'));
}
}

@ -1,5 +1,8 @@
<?php
namespace Framework\Auth;
if (!isset($_SESSION)) {
session_start();
}
error_reporting(E_ALL & ~E_NOTICE);
use App\Auth\UserTable;
use Framework\Auth;
@ -40,13 +43,24 @@ class LoggedInMiddleware implements MiddlewareInterface
{
$url_part = explode('/',$request->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 (!$_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);
}
}
if (is_null($user)) {
// 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'));
}

@ -50,7 +50,7 @@
Mettez bien le pseudo, la clé publique, le bien ou service, et le prix en june.
</div>
<p>
{% if affiche_username() != '' or sess.connecte != '' %}
{% if affiche_username() != '' or (sess.connecte != '' and sess.connecte != '---') %}
<button style="color:white; font-size: 14px;" class="btn btn-primary" data-toggle="modal" data-target="#add_new_record_modal">Ajouter un bien ou service
{% else %}
<p>

@ -49,13 +49,13 @@
Mettez bien le pseudo, la clé publique, le bien ou service, et le prix en june.
</div>
<p>
{% if nom_user != '' %}
<button style="color:white; font-size: 14px;" class="btn btn-primary" data-toggle="modal" data-target="#add_new_record_modal">Ajouter un bien ou service
{% else %}
<p>
<span style="color:lightgray;">Veuillez vous identifier dans la barre à droite
{% if affiche_username() != '' or (sess.connecte != '' and sess.connecte != '---') %}
<button style="color:white; font-size: 14px;" class="btn btn-primary" data-toggle="modal" data-target="#add_new_record_modal">Ajouter un bien ou service
{% else %}
<p>
<span style="color:lightgray;">Veuillez vous identifier dans la barre à droite
ci-dessus pour ajouter/modifier/supprimer des éléments</span>
</p>
</p>
{% endif %}
</button>
</p>

@ -45,10 +45,18 @@
<a class="nav-link {% if accueil %} active{% endif %}" style="font-size:14px;"
href="{{ path('gmarche.index') }}">Accueil</a>
</li>
{% 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 != '---')) %}
<li class="nav-item">
{% if affiche_username() !='' %}
<a class="nav-link {% if explodeUrl()[1]=='dashboard' %} active{% endif %}" style="font-size:14px;"
href="{{ path('dashboard',{user:affiche_username()}) }}">Administration</a>
{% else %}
{% if (sess.connecte != '' and sess.connecte != '---') %}
<a class="nav-link {% if explodeUrl()[1]=='dashboard' %} active{% endif %}" style="font-size:14px;"
href="{{ path('dashboard',{user:sess.connecte}) }}">Administration</a>
{% endif %}
{% endif %}
</li>
{% endif %}
<li class="nav-item">
@ -61,13 +69,13 @@
<div class="navbar-text" style="color:lightgray;margin-right:15px; margin-top:3px;">
{{ "now"|date('d/m/y') }}
</div>
{% if affiche_username() != '' or sess.connecte != '' %}
{% if affiche_username() != '' or (sess.connecte != '' and sess.connecte != '---') %}
<form method="post" style="margin-top:5px;" action="{{ path('account.profil',{user:affiche_username()}) }}">
<span><img src="\avatar_user.png" width="22" height="22" /></span>
<button id="nom_connecte_bis" style="color:white;font-size: 14px;" class="btn-primary">
{% if affiche_username() != '' %}
{{ affiche_username() }}
{% else %}
{% else %}
{{ sess.connecte }}
{% endif %}
</button>

Loading…
Cancel
Save