Changement de mot de passe
(via l'envoi d'un lien par mail)
-
diff --git a/src/Admin/AdminModule.php b/src/Admin/AdminModule.php
index 4a6ba7d..4e155cb 100644
--- a/src/Admin/AdminModule.php
+++ b/src/Admin/AdminModule.php
@@ -25,11 +25,11 @@ class AdminModule extends Module
{
$router->get('/dashboard', [LoggedInMiddleware::class, DashboardAction::class], 'dashboard');
$router->get('/dashboard/{user:[a-zA-Z\-0-9]+}', [LoggedInMiddleware::class, DashboardUserAction::class], 'dashboard.user');
- $router->get('/activation', ActiveAction::class, 'account.active');
+ $router->get('/activation', [LoggedInMiddleware::class, ActiveAction::class], 'account.active');
$router->post('/activation', ActiveAction::class);
$router->get('/profil-user', [LoggedInMiddleware::class, AccountUserEditAction::class], 'account.user');
$router->post('/profil-user', [LoggedInMiddleware::class, AccountUserEditAction::class]);
- $router->any('/password_reinit', PasswordForgetAction::class, 'auth.password');
+ //$router->any('/password_reinit', PasswordForgetAction::class, 'auth.password');
if ($renderer instanceof TwigRenderer) {
$renderer->getTwig()->addExtension($adminTwigExtension);
// $renderer->getTwig()->addExtension($variableExtension);
diff --git a/src/Admin/DashboardUserAction.php b/src/Admin/DashboardUserAction.php
index 935702e..fadfd1d 100644
--- a/src/Admin/DashboardUserAction.php
+++ b/src/Admin/DashboardUserAction.php
@@ -54,11 +54,8 @@ class DashboardUserAction
$url_part = explode('/',$_SERVER['REQUEST_URI']);
$user_affiche = $url_part[2];
-
$user = $this->userTable->findBy('username', $user_affiche);
$id_affiche = $user->id;
- // echo "id_affiche=".$id_affiche;
- // die();
$actif_affiche = $user->actif;
$listeAntennes = $this->antenneTable->findAllAntennes();
diff --git a/src/Auth/Action/PasswordForgetAction.php b/src/Auth/Action/PasswordForgetAction.php
index 615fe09..f716fd5 100644
--- a/src/Auth/Action/PasswordForgetAction.php
+++ b/src/Auth/Action/PasswordForgetAction.php
@@ -3,6 +3,7 @@ namespace App\Auth\Action;
use App\Auth\Mailer\PasswordResetMailer;
use App\Auth\UserTable;
+use App\Framework\Response\RedirectBackResponse;
use Framework\Actions\RouterAwareAction;
use Framework\Database\NoRecordException;
use Framework\Renderer\RendererInterface;
@@ -60,33 +61,27 @@ class PasswordForgetAction
return $this->renderer->render('@auth/password',compact('affichage_div'));
}
$params = $request->getParsedBody();
- $url_part = explode('/',$_SERVER['HTTP_REFERER']);
- $chemin = $url_part[3].'/'.$url_part[4];
+ //$url_part = explode('/',$request->getServerParams()['HTTP_REFERER'] ?? '/');
+ //$chemin = $url_part[3].'/'.$url_part[4];
$validator = (new Validator($params))
->notEmpty('email')
->email('email');
if ($validator->isValid()) {
- // try {
- if ($user = $this->userTable->findBy('email', $params['email'])) {
+ if ($user = $this->userTable->findBy('email', $params['email'])) {
- $token = $this->userTable->resetPassword($user->id);
- $this->mailer->send($user->email, [
- 'id' => $user->id,
- 'token' => $token
- ]);
- $this->flashService->success("Un email a été envoyé à l'utilisateur");
+ $token = $this->userTable->resetPassword($user->id);
+ $this->mailer->send($user->email, [
+ 'id' => $user->id,
+ 'token' => $token
+ ]);
+ $this->flashService->success("Un email a été envoyé à l'utilisateur");
- $affichage_div = false;
- return new RedirectResponse($chemin);
- //return $this->renderer->render('@auth/password', compact('affichage_div'));
- } else {
- $this->flashService->error('Aucun utilisateur ne correspond à cet email');
- }
- /* } catch (NoRecordException $e) {
- //$errors = ['email' => 'Aucun utilisateur ne correspond à cet email'];
+ $affichage_div = false;
+ return new RedirectBackResponse($request);
+ } else {
$this->flashService->error('Aucun utilisateur ne correspond à cet email');
- }*/
+ }
} else {
$errors = $validator->getErrors();
}
diff --git a/src/Framework/Auth/LoggedInMiddleware.php b/src/Framework/Auth/LoggedInMiddleware.php
index b0ab70b..5274151 100644
--- a/src/Framework/Auth/LoggedInMiddleware.php
+++ b/src/Framework/Auth/LoggedInMiddleware.php
@@ -38,7 +38,7 @@ class LoggedInMiddleware implements MiddlewareInterface
{
$user = $this->auth->getUser();
- if (is_null($user) and (!$_SESSION['user'])) {
+ if (is_null($user)) {
//throw new ForbiddenException();
//return $this->redirect('auth.login');
//$this->session->set('auth.login', $request->getUri()->getPath());
diff --git a/src/Framework/Response/RedirectBackResponse.php b/src/Framework/Response/RedirectBackResponse.php
new file mode 100644
index 0000000..837af99
--- /dev/null
+++ b/src/Framework/Response/RedirectBackResponse.php
@@ -0,0 +1,16 @@
+getServerParams()['HTTP_REFERER'] ?? '/');
+ }
+}
diff --git a/src/Framework/Twig/VariableExtension.php b/src/Framework/Twig/VariableExtension.php
index 23c7090..a291552 100644
--- a/src/Framework/Twig/VariableExtension.php
+++ b/src/Framework/Twig/VariableExtension.php
@@ -26,21 +26,23 @@ class VariableExtension extends \Twig_Extension
{
return [
new \Twig_SimpleFunction('affiche_username', [$this, 'affich_usrname']),
- new \Twig_SimpleFunction('affiche_role', [$this, 'affich_role'])
+ new \Twig_SimpleFunction('affiche_role', [$this, 'affich_role']),
+ new \Twig_SimpleFunction('affiche_mail', [$this, 'affich_mail'])
];
}
public function affich_role(): ?string
{
- //echo "session=".$_SESSION['user'];
- //die();
$retour_aff = $this->session->get('role') ?: '';
return $retour_aff;
}
public function affich_usrname(): ?string
{
- //echo "session=".$_SESSION['user'];
- //die();
$retour_aff = $this->session->get('username') ?: '';
return $retour_aff;
}
+ public function affich_mail(): ?string
+ {
+ $retour_aff = $this->session->get('email') ?: '';
+ return $retour_aff;
+ }
}
diff --git a/src/Gmarche/Actions/AntenneShowAction.php b/src/Gmarche/Actions/AntenneShowAction.php
index cb1cc41..4b5a33b 100644
--- a/src/Gmarche/Actions/AntenneShowAction.php
+++ b/src/Gmarche/Actions/AntenneShowAction.php
@@ -45,29 +45,31 @@ class AntenneShowAction
public function __invoke(Request $request)
{
- $params = $request->getQueryParams();
- $gmarchePrefix = $this->container->get('gmarche.prefix');
- // On récupère l'id de la région cliquée
- $region_id = $this->regionTable->findBy('slug', $request->getAttribute('slug'))->id;
- $slug = $request->getAttribute('slug');
- $page = $params['p'] ?? 1; // Si la page n'est pas définie, on l'initialise à 1
- $antennes = $this->antenneTable->findAllbyRegion($region_id)->paginate(25, $page);
+ if ($request->getMethod() === 'GET') {
+ $params = $request->getQueryParams();
+ $gmarchePrefix = $this->container->get('gmarche.prefix');
+ // On récupère l'id de la région cliquée
+ $region_id = $this->regionTable->findBy('slug', $request->getAttribute('slug'))->id ?: 1;
+ $slug = $request->getAttribute('slug');
+ $page = $params['p'] ?? 1; // Si la page n'est pas définie, on l'initialise à 1
+ $antennes = $this->antenneTable->findAllbyRegion($region_id)->paginate(25, $page);
- $region=$this->regionTable->findBy('slug', $request->getAttribute('slug'));
- /*if ($region->slug !== $slug) {
- return $this->redirect('gmarche.show', [
- 'slug' => $region->slug,
- 'id' => $region->id
- ]);
- }*/
- if (!isset($_SESSION)) {
- //session_start();
+ $region = $this->regionTable->findBy('slug', $request->getAttribute('slug'));
+ /*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'));
}
- 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'));
}
}
diff --git a/src/Gmarche/GmarcheModule.php b/src/Gmarche/GmarcheModule.php
index da00868..fd4df78 100644
--- a/src/Gmarche/GmarcheModule.php
+++ b/src/Gmarche/GmarcheModule.php
@@ -3,7 +3,6 @@ namespace App\Gmarche;
use App\Gmarche\Actions\AntenneShowAction;
use App\Gmarche\Actions\RegionIndexAction;
-use Framework\Auth;
use Framework\Module;
use Framework\Renderer\RendererInterface;
use Framework\Router;
@@ -16,9 +15,8 @@ class GmarcheModule extends Module
const MIGRATIONS = __DIR__ . '/db/migrations';
const SEEDS = __DIR__ . '/db/seeds';
- public function __construct(ContainerInterface $container, Auth $auth)
+ public function __construct(ContainerInterface $container)
{
- $this->auth = $auth;
$gmarchePrefix = $container->get('gmarche.prefix');
$container->get(RendererInterface::class)->addPath('gmarche', __DIR__ . '/views');
$router = $container->get(Router::class);
diff --git a/views/layout.twig b/views/layout.twig
index 98e358e..f8fa84f 100644
--- a/views/layout.twig
+++ b/views/layout.twig
@@ -61,23 +61,36 @@
{{ "now"|date('d/m/y') }}
+
{% if affiche_username() != '' %}
-
{% else %}
+
-
+