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 %} + +