diff --git a/.gitignore b/.gitignore index 6199e3c..9c26537 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ config/config.php +config/config-backup.php scripts/.loc_hash .idea public/uploads/* @@ -7,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/css/style.css b/public/css/style.css index be4591c..8fe14b9 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -116,12 +116,6 @@ header.header img { border: 0px; } -.profil_user { - height: 400px; - width: 900px; - background-color: lightgray; - text-align: center; -} .records_content th, .records_content2 th { background-color: lightgray; color: rgba(0,0,0,0.85); @@ -131,6 +125,17 @@ header.header img { margin: 5px auto; text-align: center; } + +/******************************************************************/ +/* profil.twig */ +/******************************************************************/ +.profil_user { + background-color: lightgray; + text-align: center; + margin-top:5px; + padding-bottom: 2rem; + padding-right: 3rem; +} /******************************************************************/ /* signup.twig */ /******************************************************************/ diff --git a/public/js/avatar.js b/public/js/avatar.js new file mode 100644 index 0000000..c6e16e8 --- /dev/null +++ b/public/js/avatar.js @@ -0,0 +1,35 @@ +$(document).ready(function () { + var nom_connecte = $("#nom_connecte").text(); + document.querySelector('#avatar').addEventListener('change', function() { + //alert('ok'); + // alert(this.files[0].name); + + }); + $('#avatar').change(function(){ + var fda = new FormData(); + //var input = $('#avatar').files[0]; + //var file = $('#avatar').files[0].name; + //alert(file); + + let files_avatar = $('#avatar')[0].files[0]; + fda.append('avatar',files_avatar); + fda.append('nom_user',nom_connecte); + // requête AJAX pour copier la photo et l'afficher + $.ajax({ + url: '/models/upload_avatar.php', + type: 'post', + data: fda, + contentType: false, + processData: false, + success: function(response){ + if(response != 0){ + // Show image preview + $('#avatar_preview').html(''); + $('#avatar_preview').append(""); + } else { + alert('L\'image n\'a pu être uploadée'); + } + } + }); + }); +}); \ No newline at end of file diff --git a/public/js/script.js b/public/js/script.js index f344981..d05d0ba 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -237,7 +237,7 @@ $(document).ready(function () { $("#hidden_antenne_slug").val(antenne_slug); readRecords(antenne_slug, nom_connecte); var source = 'products'; - } else { + } else if (affichage_slug == 'recherches') { $("#hidden_antenne_slug_r").val(antenne_slug); readRecords2(antenne_slug, nom_connecte); var source = 'recherches'; @@ -305,4 +305,47 @@ $(document).ready(function () { } }); }); + /*function dump(obj) { + var out = ''; + for (var i in obj) { + out += i + ": " + obj[i] + "\n"; + } + alert(out); + // or, if you wanted to avoid alerts... + var pre = document.createElement('pre'); + pre.innerHTML = out; + document.body.appendChild(pre) + }*/ + $('#avatar').change(function(){ + var fda = new FormData(); + var nom_connecte = $("#nom_connecte").text(); + //var file = $('#avatar').files[0].name; + //alert(file); + var test = document.getElementById('avatar'); + //dump(test); + //var files_avatar = $('#avatar')[0].files[0]; + fda.append('avatar',$('#avatar')[0].files[0]); + fda.append('nom_user',nom_connecte); + // requête AJAX pour copier l'avatar et l'afficher + $.ajax({ + url: '/models/upload_avatar.php', + type: 'post', + data: fda, + contentType: false, + processData: false, + success: function(response){ + if(response != 0){ + // Show image preview + alert('ok'); + $('#avatar_preview').html(''); + $('#avatar_preview').append(""); + } else { + alert('L\'image n\'a pu être uploadée'); + } + }, + error: function(response) { + alert('erreur'); + } + }); + }); }); 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/public/models/upload_avatar.php b/public/models/upload_avatar.php new file mode 100644 index 0000000..8bc9532 --- /dev/null +++ b/public/models/upload_avatar.php @@ -0,0 +1,31 @@ +post('/inscription', SignupAction::class); $router->get('/mon-profil', [LoggedInMiddleware::class, AccountAction::class], 'account'); $router->post('/mon-profil', [LoggedInMiddleware::class, AccountEditAction::class]); - $router->get('/profil-utilisateur', ProfilAction::class, 'account.profil'); + $router->get('/profil-utilisateur', [PasswordForgetAction::class, ProfilAction::class], 'account.profil'); $router->post('/profil-utilisateur', ProfilAction::class); } } diff --git a/src/Account/Action/ProfilAction.php b/src/Account/Action/ProfilAction.php index 7ab019e..cbc3f18 100644 --- a/src/Account/Action/ProfilAction.php +++ b/src/Account/Action/ProfilAction.php @@ -1,6 +1,7 @@ renderer = $renderer; $this->auth = $auth; + $this->userTable = $userTable; } public function __invoke(ServerRequestInterface $request) { - /* Transmission du nom de l'utilistateur connecté à la vue Twig */ - session_start(); + /* Transmission du nom et de l'avatar de l'utilisateur connecté à la vue Twig */ + if(!isset($_SESSION)) { + session_start(); + } if (isset($_SESSION['user'])) { $nom_user = $_SESSION['user']; + $requete_user = $this->userTable->findBy('username', $nom_user); + $nom_avatar = $requete_user->avatar; + $email = $requete_user->email; } else { $nom_user = ''; } - return $this->renderer->render('@account/profil', compact('nom_user')); + return $this->renderer->render('@account/profil', compact('nom_user','nom_avatar','email')); } } diff --git a/src/Account/views/profil.twig b/src/Account/views/profil.twig index 71e9ee6..4ed304e 100644 --- a/src/Account/views/profil.twig +++ b/src/Account/views/profil.twig @@ -1,15 +1,71 @@ {% extends 'layout.twig' %} {% block body %} + +
+

Profil utilisateur {{ nom_user }}

+
+
+
Changement d'avatar
+ +
+
+
+ Choisir la nouvelle image :
+
+
+
+ +
+
+
+
+
+
+
+
+
Changement de mot de passe
+
(via l'envoi d'un lien par mail)
+
+
+ {{ csrf_input() }} + {{ field('email', email, 'Votre Email', {type: 'email'}) }} + +
+
+
+
+
+
+
Antennes suivies
+
+
+ Paris +
+
+
+
+
+
+
Prochains Ğ-Marchés
+
+ +
+
+
+
+
+
Statistiques diverses
+
+
Biens achetés
+
+
+
Biens vendus
+
+
+
- {% endblock %} \ No newline at end of file diff --git a/src/Auth/Action/PasswordForgetAction.php b/src/Auth/Action/PasswordForgetAction.php index 881642d..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; @@ -46,7 +56,8 @@ class PasswordForgetAction public function __invoke(ServerRequestInterface $request) { if ($request->getMethod() === 'GET') { - return $this->renderer->render('@auth/password'); + $affichage_div = true; + return $this->renderer->render('@auth/password',compact('affichage_div')); } $params = $request->getParsedBody(); $validator = (new Validator($params)) @@ -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/src/Product/views/admin/products/index.twig b/src/Product/views/admin/products/index.twig index d60e97f..9ca1f39 100644 --- a/src/Product/views/admin/products/index.twig +++ b/src/Product/views/admin/products/index.twig @@ -121,6 +121,9 @@