Nouvel écran profil-utilisateur

This commit is contained in:
nox 2019-11-25 23:46:20 +01:00
parent e557174e96
commit 473a16c5b0
11 changed files with 212 additions and 24 deletions

2
.gitignore vendored
View File

@ -1,4 +1,6 @@
config/config.php
config/config-backup.php
config/conf.php
.idea
/public/uploads
/tmp

View File

@ -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 */
/******************************************************************/

35
public/js/avatar.js Normal file
View File

@ -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("<img src='"+response+"' width='140' height='140' style='display: inline-block;'>");
} else {
alert('L\'image n\'a pu être uploadée');
}
}
});
});
});

View File

@ -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("<img src='"+response+"' width='140' height='140' style='display: inline-block;'>");
} else {
alert('L\'image n\'a pu être uploadée');
}
},
error: function(response) {
alert('erreur');
}
});
});
});

View File

@ -0,0 +1,31 @@
<?php
// Nom du fichier image
$filename = $_FILES['avatar']['name'];
// Emplacement
$path = str_replace('\\', '/', dirname(realpath(__DIR__)));
$location = $path.'/uploads/avatars/';
// Extension du fichier
$file_extension = pathinfo($filename, PATHINFO_EXTENSION);
$file_extension = strtolower($file_extension);
// Extensions valides d'image
$image_ext = array("jpg","png","jpeg");
$nom_user = $_POST['nom_user'];
$response = 0;
if(in_array($file_extension,$image_ext)){
$directory = '/uploads/avatars';
if (file_exists($directory) === false) {
mkdir($directory, 0777, true);
}
$nom_fichier = $nom_user.'-'.uniqid("",true).'.'.$file_extension;
$location2 = '/uploads/avatars/'.$nom_fichier;
// Upload du fichier
if(move_uploaded_file($_FILES['avatar']['tmp_name'],$directory.'/'.$nom_fichier)){
$response = $location2;
}
}
echo $response;

View File

@ -5,6 +5,7 @@ use App\Account\Action\AccountAction;
use App\Account\Action\AccountEditAction;
use App\Account\Action\ProfilAction;
use App\Account\Action\SignupAction;
use App\Auth\Action\PasswordForgetAction;
use Framework\Auth\LoggedInMiddleware;
use Framework\Module;
use Framework\Renderer\RendererInterface;
@ -24,7 +25,7 @@ class AccountModule extends Module
$router->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);
}
}

View File

@ -1,6 +1,7 @@
<?php
namespace App\Account\Action;
use App\Auth\UserTable;
use Framework\Auth;
use Framework\Renderer\RendererInterface;
use Psr\Http\Message\ServerRequestInterface;
@ -16,24 +17,35 @@ class ProfilAction
* @var Auth
*/
private $auth;
/**
* @var UserTable
*/
private $userTable;
public function __construct(
RendererInterface $renderer,
Auth $auth
Auth $auth,
UserTable $userTable
) {
$this->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'));
}
}

View File

@ -1,15 +1,70 @@
{% extends 'layout.twig' %}
{% block body %}
<script type="text/javascript" src="/js/script.js"></script>
<div class="profil_user">
<h4>Profil utilisateur {{ nom_user }}</h4>
<div id="avatar" class="col-sm-10 card" style="text-align:left;margin-left: 1.7rem;">
<div class="card-block" style="margin-left: 1rem;">
<h5 class="card-title">Changement d'avatar</h5>
<!--<div class="col-sm-5" style="float:left;">
<div class="profil_user" style="margin-top:5px;">
<h4>Profil utilisateur {{ nom_user }}</h4>
<div>
<h5>Biens achetés</h5>
</div>
<div>
<h5>Biens vendus</h5>
</div>
</div>-->
<div class="col-sm-8" style="float:left;margin-left:0rem;">
<div class="form-group">
<form method='post' action='' enctype="multipart/form-data">
Choisir la nouvelle image : <input type='file' name='file' id='avatar' class='form-control' ><br>
</form>
<div class="col-sm-8">
<div id="avatar_preview" style="max-width:140px;max-height:140px;">
<img src="/uploads/avatars/{{ nom_avatar }}" />
</div>
</div>
</div>
</div>
</div>
</div>
<div id="mot_de_passe" class="col-sm-10 card" style="text-align: left;margin-top:0.8rem; margin-left: 1.7rem;">
<div class="card-block" style="margin-left: 1rem;">
<h5 class="card-title">Changement de mot de passe</h5>
<div class="container" style="background-color: lightgray;opacity: 0.9;
margin-left: 0rem;margin-bottom:1rem; padding:1rem;">
<form action="" method="post">
{{ csrf_input() }}
{{ field('email', email, 'Email', {type: 'email'}) }}
<button class="btn btn-primary">Envoyer lien de reset du mot de passe</button>
</form>
</div>
</div>
</div>
<div id="antennes_suivies" class="col-sm-10 card" style="text-align: left;margin-top:0.8rem;margin-left: 1.7rem;">
<div class="card-block" style="margin-left: 1rem;">
<h5 class="card-title">Antennes suivies</h5>
<div>
<div class="row" style="margin-left: 2rem;">
Paris
</div>
</div>
</div>
</div>
<div id="prochains_gmarches" class="col-sm-10 card" style="text-align: left;margin-top:0.8rem;margin-left: 1.7rem;">
<div class="card-block" style="margin-left: 1rem;">
<h5 class="card-title">Prochains Ğ-Marchés</h5>
<div>
</div>
</div>
</div>
<div class="col-sm-10 card" style="text-align: left;margin-left: 1.7rem;margin-top:0.8rem;">
<div class="card-block" style="margin-left: 1rem;">
<h5 class="card-title">Statistiques diverses</h5>
<div>
<h6 style="margin-left: 1rem;">Biens achetés</h6>
</div>
<div>
<h6 style="margin-left: 1rem;">Biens vendus</h6>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -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')

View File

@ -202,6 +202,9 @@
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
<form method='post' action='' enctype="multipart/form-data">
Choisir la nouvelle image : <input type='file' name='file' id='avatar' class='form-control' ><br>
</form>
<div class="form-group">
<label for="update_vendeur">Vendeur</label>
<input type="input" disabled="disabled" id="update_vendeur" placeholder="Vendeur" class="form-control"/>

View File

@ -58,7 +58,7 @@
<form method="post" style="margin-top:5px;" action="{{ path('account.profil') }}">
<span><img src="\avatar_user.png" width="22" height="22" /></span>
<!--<span id="nom_connecte"> nom_user </span>-->
<button style="color:white;font-size: 14px;" class="btn-primary">{{ nom_user }}</button>
<button id="nom_connecte" style="color:white;font-size: 14px;" class="btn-primary">{{ nom_user }}</button>
</form>
<form method="post" action="{{ path('auth.logout') }}">
<!-- csrf_input() }}-->