From 473a16c5b097a7fa558e3709b33143e10fd4ccc3 Mon Sep 17 00:00:00 2001 From: nox Date: Mon, 25 Nov 2019 23:46:20 +0100 Subject: [PATCH] =?UTF-8?q?Nouvel=20=C3=A9cran=20profil-utilisateur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + public/css/style.css | 18 +++-- public/js/avatar.js | 35 ++++++++++ public/js/script.js | 45 ++++++++++++- public/models/upload_avatar.php | 31 +++++++++ src/Account/AccountModule.php | 3 +- src/Account/Action/ProfilAction.php | 20 ++++-- src/Account/views/profil.twig | 73 ++++++++++++++++++--- src/Auth/Action/PasswordForgetAction.php | 4 +- src/Product/views/admin/products/index.twig | 3 + views/layout.twig | 2 +- 11 files changed, 212 insertions(+), 24 deletions(-) create mode 100644 public/js/avatar.js create mode 100644 public/models/upload_avatar.php diff --git a/.gitignore b/.gitignore index 4df4448..cce723b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ config/config.php +config/config-backup.php +config/conf.php .idea /public/uploads /tmp diff --git a/public/css/style.css b/public/css/style.css index c6653e5..7a22520 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -99,12 +99,7 @@ header.header img { .container { font-family: Arial, sans-serif; } -.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); @@ -114,6 +109,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/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..bc1dbc1 100644 --- a/src/Account/views/profil.twig +++ b/src/Account/views/profil.twig @@ -1,15 +1,70 @@ {% extends 'layout.twig' %} {% block body %} + +
+

Profil utilisateur {{ nom_user }}

+
+
+
Changement d'avatar
+ +
+
+
+ Choisir la nouvelle image :
+
+
+
+ +
+
+
+
+
+
+
+
+
Changement de mot de passe
+
+
+ {{ csrf_input() }} + {{ field('email', email, '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..0d95584 100644 --- a/src/Auth/Action/PasswordForgetAction.php +++ b/src/Auth/Action/PasswordForgetAction.php @@ -45,9 +45,9 @@ class PasswordForgetAction public function __invoke(ServerRequestInterface $request) { - if ($request->getMethod() === 'GET') { + /*if ($request->getMethod() === 'GET') { return $this->renderer->render('@auth/password'); - } + }*/ $params = $request->getParsedBody(); $validator = (new Validator($params)) ->notEmpty('email') diff --git a/src/Product/views/admin/products/index.twig b/src/Product/views/admin/products/index.twig index f418154..3d52d42 100644 --- a/src/Product/views/admin/products/index.twig +++ b/src/Product/views/admin/products/index.twig @@ -202,6 +202,9 @@