diff --git a/.gitignore b/.gitignore index 4d905f0..9c26537 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ public/uploads/* vendor composer.json composer.lock -/src/Framework/SwiftMailerFactory.php +src/Framework/SwiftMailerFactory.php diff --git a/config/apply.php b/config/apply.php index 80827d1..fe4745c 100644 --- a/config/apply.php +++ b/config/apply.php @@ -48,6 +48,6 @@ return [ }, // MAILER 'mail.to' => 'admin@gmarche-testmail.com', - 'mail.from' => '$mail_from', + 'mail.from' => "$mail_from", Swift_Mailer::class => \DI\factory(\Framework\SwiftMailerFactory::class) ]; diff --git a/public/models/connexion.php b/public/models/connexion.php index 951db35..95deb85 100644 --- a/public/models/connexion.php +++ b/public/models/connexion.php @@ -5,7 +5,7 @@ include '../../config/config.php'; try { $bdd = new \PDO("mysql:host=$db_server;dbname=$db_name", $db_username, $db_password); - if (isset($_POST['nom_connecte']) && isset($_POST['mdp']) != "") { + if (isset($_POST['nom_connecte']) && isset($_POST['mdp'])) { $params["username"] = $_POST['nom_connecte']; $requete = "SELECT username, password diff --git a/src/Account/views/profil.twig b/src/Account/views/profil.twig index bc1dbc1..4ed304e 100644 --- a/src/Account/views/profil.twig +++ b/src/Account/views/profil.twig @@ -25,14 +25,15 @@
-
+
Changement de mot de passe
+
(via l'envoi d'un lien par mail)
-
+ {{ csrf_input() }} - {{ field('email', email, 'Email', {type: 'email'}) }} - + {{ field('email', email, 'Votre Email', {type: 'email'}) }} +
diff --git a/src/Auth/Action/PasswordForgetAction.php b/src/Auth/Action/PasswordForgetAction.php index 0d95584..b354c59 100644 --- a/src/Auth/Action/PasswordForgetAction.php +++ b/src/Auth/Action/PasswordForgetAction.php @@ -3,12 +3,15 @@ namespace App\Auth\Action; use App\Auth\Mailer\PasswordResetMailer; use App\Auth\UserTable; +use Framework\Actions\RouterAwareAction; use Framework\Database\NoRecordException; use Framework\Renderer\RendererInterface; use Framework\Response\RedirectResponse; +use Framework\Router; use Framework\Session\FlashService; use Framework\Validator; use Psr\Http\Message\ServerRequestInterface; +use Zend\Expressive\Router\RouterInterface; class PasswordForgetAction { @@ -17,6 +20,10 @@ class PasswordForgetAction * @var RendererInterface */ private $renderer; + /** + * @var RouterInterface + */ + private $router; /** * @var UserTable */ @@ -30,14 +37,17 @@ class PasswordForgetAction */ private $flashService; + use RouterAwareAction; + public function __construct( RendererInterface $renderer, + Router $router, UserTable $userTable, PasswordResetMailer $mailer, FlashService $flashService ) { - $this->renderer = $renderer; + $this->router = $router; $this->userTable = $userTable; $this->mailer = $mailer; $this->flashService = $flashService; @@ -45,9 +55,10 @@ class PasswordForgetAction public function __invoke(ServerRequestInterface $request) { - /*if ($request->getMethod() === 'GET') { - return $this->renderer->render('@auth/password'); - }*/ + if ($request->getMethod() === 'GET') { + $affichage_div = true; + return $this->renderer->render('@auth/password',compact('affichage_div')); + } $params = $request->getParsedBody(); $validator = (new Validator($params)) ->notEmpty('email') @@ -61,13 +72,21 @@ class PasswordForgetAction 'token' => $token ]); $this->flashService->success('Un email vous a été envoyé'); - return new RedirectResponse($request->getUri()->getPath()); + //return new RedirectResponse($request->getUri()->getPath()); + //$path = $this->router->generateUri('account.profil'); + //$this->session->delete('auth.redirect'); + + //return new RedirectResponse($path); + $affichage_div = false; + return $this->renderer->render('@auth/password',compact('affichage_div')); } catch (NoRecordException $e) { - $errors = ['email' => 'Aucun utilisateur ne correspond à cet email']; + //$errors = ['email' => 'Aucun utilisateur ne correspond à cet email']; + $this->flashService->error('Aucun utilisateur ne correspond à cet email'); } } else { $errors = $validator->getErrors(); } - return $this->renderer->render('@auth/password', compact('errors')); + $affichage_div = true; + return $this->renderer->render('@auth/password', compact('errors','affichage_div')); } } diff --git a/src/Auth/views/password.twig b/src/Auth/views/password.twig index 66eebf5..808cfe4 100644 --- a/src/Auth/views/password.twig +++ b/src/Auth/views/password.twig @@ -1,24 +1,25 @@ {% extends 'layout.twig' %} - {% block body %} + {% if flash('error') %} +
+ {{ flash('error') }} +
+ {% endif %} + - {% if flash('error') %} -
- {{ flash('error') }} -
- {% endif %} - -
-
- {{ csrf_input() }} - {{ field('email', null, 'Email', {type: 'email'}) }} - -
-
+ {% if affichage_div %} +
+
+ + {{ field('email', null, 'Votre Email', {type: 'email'}) }} + +
+
+ {% endif %} {% endblock %} diff --git a/src/Framework/SwiftMailerFactory.php b/src/Framework/SwiftMailerFactory.php index 9e2eb81..6c1dd55 100644 --- a/src/Framework/SwiftMailerFactory.php +++ b/src/Framework/SwiftMailerFactory.php @@ -9,7 +9,8 @@ class SwiftMailerFactory public function __invoke(ContainerInterface $container): \Swift_Mailer { if ($container->get('env') === 'production') { - $transport = new \Swift_SendmailTransport(); + //$transport = new \Swift_SendmailTransport(); + $transport = new \Swift_SmtpTransport('localhost', 1025); } else { $transport = new \Swift_SmtpTransport('localhost', 1025); } diff --git a/views/layout.twig b/views/layout.twig index ff1805a..3cde16f 100644 --- a/views/layout.twig +++ b/views/layout.twig @@ -55,7 +55,6 @@ {{ "now"|date('d/m/y') }}
{% if nom_user != '' %} -
@@ -69,8 +68,8 @@ - +