Compare commits

..

27 Commits

Author SHA1 Message Date
poka 88072b2f8d fix 2020-10-24 02:12:28 +02:00
nox 1d9249483a Finalisation de la création des antennes dans Tableau de bord Admin 2020-02-23 02:38:32 +01:00
nox 034ceec279 Finalisation de la modification d'une antenne - Ajout des lignes de présentation de l'antenne dans la page Produits 2020-02-04 23:35:27 +01:00
nox 5aec7c62ec Correction bug sur accès au répertoire /src/Antenne/views 2020-01-27 14:12:52 +01:00
nox 600786d914 Avancement sur Modification d'une antenne - Reglage des selects imbriques 2020-01-27 03:56:05 +01:00
nox b9d7376869 Avancement sur modification d'une antenne - Champ select antenne et région 2020-01-26 01:59:59 +01:00
nox 5ebbf9d7d2 Avancement sur gestion des antennes - Formulaire de modification 2020-01-25 01:35:00 +01:00
nox bd626f62e5 Avancement sur la gestion du suivi Antennes. Ajout de la checkbox dans Produits 2020-01-15 01:08:50 +01:00
nox 0ab166726c Ajustement de la deconnexion et du desaffichage de l'utilisateur qui etait connecte 2020-01-06 01:36:42 +01:00
nox 2a01413fab Affichage de l'utilisateur connecté correct en connexion modale ou autre 2020-01-05 04:16:48 +01:00
nox 72fb941a18 Finalisation de l'affichage de l'utilisateur connecté en mode modal ou non modal 2020-01-02 22:27:28 +01:00
nox 8c32377738 Renvoi mot de passe via Profil user opérationnel et avancement sur connexion via fenêtre modale 2019-12-29 03:03:50 +01:00
nox 025d0a2cad Renvoi du mot de passe dans tableau de bord User opérationnel 2019-12-28 01:48:42 +01:00
nox bf65d62297 Gestion du statut actif/inactif des users - Ajout des sessions pour twig 2019-12-23 02:09:54 +01:00
nox 37468993f6 Avancement sur droits d'accès à l'url dashboard/user 2019-12-10 14:29:27 +01:00
nox 502586ae49 Avancement sur renvoi mot de passe dans Dashboard User 2019-12-10 04:36:49 +01:00
nox e19b374ddd Merge backend-admin sur branche master 2019-12-09 23:22:09 +01:00
nox 9096865ecb Merge branch 'backend-user' 2019-12-09 22:46:36 +01:00
nox 623b19631e Merge master sur backend-admin 2019-12-09 22:12:30 +01:00
nox af2257b796 Correction redirection suite login depuis url /login 2019-12-09 16:06:21 +01:00
nox 2b881fd7c5 Correction connexion user pour url /login 2019-12-09 16:02:52 +01:00
nox 2f0b22e26e Ajout fonction actif/inactif dans tableau de bord User 2019-12-09 15:35:12 +01:00
nox ef9e63d898 Avancement sur Tableau de bord Admin et User 2019-12-09 01:02:34 +01:00
nox 2f38ff0776 Mise en place du tableau de bord Admin - Etape 1 2019-12-02 22:49:12 +01:00
nox 55c85b29b8 Réglage en cours de l'affichage du user connecté 2019-11-30 21:18:45 +01:00
nox 85d55df6fe Merge master 2019-11-26 00:07:51 +01:00
nox 473a16c5b0 Nouvel écran profil-utilisateur 2019-11-25 23:46:20 +01:00
71 changed files with 2349 additions and 458 deletions

5
.gitignore vendored
View File

@ -1,10 +1,11 @@
config/config.php
config/config-backup.php
scripts/.loc_hash
.idea
public/uploads/*
!public/uploads/default.png
/tmp
tmp
vendor
composer.json
composer.lock
/src/Framework/SwiftMailerFactory.php
src/Framework/SwiftMailerFactory.php

View File

@ -2,6 +2,7 @@
include 'config.php';
use App\Framework\Twig\UrlExtension;
use App\Framework\Twig\VariableExtension;
use Framework\Middleware\CsrfMiddleware;
use Framework\Renderer\RendererInterface;
use Framework\Renderer\TwigRendererFactory;
@ -29,7 +30,8 @@ return [
\DI\get(FlashExtension::class),
\DI\get(FormExtension::class),
\DI\get(CsrfExtension::class),
\DI\get(UrlExtension::class)
\DI\get(UrlExtension::class),
\DI\get(VariableExtension::class)
],
SessionInterface::class => \DI\object(PHPSession::class),
CsrfMiddleware::class => \DI\object()->constructor(\DI\get(SessionInterface::class)),
@ -48,6 +50,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)
];

View File

Before

Width:  |  Height:  |  Size: 704 B

After

Width:  |  Height:  |  Size: 704 B

7
public/css/jquery-ui.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -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 */
/******************************************************************/
@ -162,18 +167,24 @@ header.header img {
display: block;
margin: auto;
}
/******************************************************************/
/* dashboard.twig et dashboard-user.twig */
/******************************************************************/
.tab-de-bord {
background-color: brown;
padding: 1rem;
min-width: 380px;
}
/******************************************************************/
/* layout.twig */
/******************************************************************/
.mdp_oublie:hover {
background-color: deepskyblue;
}
/******************************************************************/
/* LOADING PUBKEY */
/******************************************************************/
#cle_pub {
display: none;
}
@ -195,7 +206,17 @@ body.loading .loadingPubkey {
/* POUR MOBILES */
/******************************************************************/
@media only screen and (max-width:560px) {
/******************************************************************/
/* dashboard.twig */
/******************************************************************/
.tab-de-bord {
background-color: brown;
padding: 1rem;
min-width: 290px;
}
/******************************************************************/
/* layout.twig */
/******************************************************************/
.fond {
background-color: black;
background-image: url("../images/bildreich_1275.jpg");

View File

@ -21,6 +21,7 @@ use Middlewares\Whoops;
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
$chemin = $_SERVER['DOCUMENT_ROOT'];
$chemin_new = substr($chemin,0,-6);
@ -34,18 +35,14 @@ $app = (new \Framework\App( $chemin_new .'config/apply.php'))
$container = $app->getContainer();
// Pose un problème
//$container->get(\Framework\Router::class)->get('/', \App\Gmarche\Actions\RegionIndexAction::class, 'home');
$app->pipe(Whoops::class);
$app->pipe(TrailingSlashMiddleware::class);
$app->pipe(\App\Auth\ForbiddenMiddleware::class);
// admin pose problème
//$app->pipe(
// $container->get('admin.prefix'),
// $container->get(RoleMiddlewareFactory::class)->makeForRole('admin')
// );
$app->pipe(
$container->get('admin.prefix'),
$container->get(RoleMiddlewareFactory::class)->makeForRole('0','1')
);
$app->pipe(MethodMiddleware::class)
->pipe(RendererRequestMiddleware::class)

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

@ -8,14 +8,19 @@ function connexion(nom_connecte, mdp, chemin) {
var result = JSON.parse(data);
// Afficher l'avatar et le nom du connecté sur la barre d'état ou message d'erreur
if (result.valide) {
$("#bouton-connexion").html('');
$("#bouton-connexion").append('<span><img src="/images/avatar_user.png" width="22" height="22" />');
$("#bouton-connexion").append('</span>');
$("#nom_connecte").css('display',"block");
$("#bouton-connexion").css('display',"none");
$("#avatar-user").css('display',"inline-block");
$("#avatar-user").html('');
$("#avatar-user").append('<span><img src="/avatar_user.png" width="22" height="22" />');
$("#avatar-user").append('</span>');
$("#user-connecte").css('display',"inline-block");
$("#contenu_bouton").html('');
$("#contenu_bouton").append(result.username);
$("#nom_connecte_bis").append(result.username);
$('#formulaire').attr('action', '/profil/user/'+result.username);
$("#deconnexion").css('display',"block");
$("#inscription").css('display',"none");
$("#nom_connecte").append(result.username);
// On recharge la page pour tenir compte de la connexion de l'utilisateur
window.location.reload(true);
} else {
$('.alert-danger').html('');

View File

@ -197,6 +197,21 @@ function UpdateProduitsDetails(nom_connecte) {
}
);
}
function UpdateSuiviAntenne(id_connecte, id_antenne, etat_suivi) {
$.post("/models/updateSuiviAntenne.php", {
id_connecte: id_connecte,
id_antenne: id_antenne,
etat_suivi: etat_suivi
},
function (data, status) {
// On recharge la page pour tenir compte de la connexion de l'utilisateur
//window.location.reload(true);
}
);
}
function UpdateRecherchesDetails(nom_connecte) {
var produit = $("#update_produit").val();
@ -227,17 +242,21 @@ function UpdateRecherchesDetails(nom_connecte) {
}
$(document).ready(function () {
//$('input:checkbox[name=mybox]').attr('checked',false);
// On récupère le nom de l'antenne dans l'url pour afficher les biens/services de celle-ci
var url = document.location.href;
var antenne_slug = url.split('/')[5];
var affichage_slug = url.split('/')[6];
var nom_connecte = $("#nom_connecte").text();
var nom_connecte = $("#contenu_bouton").text().trim();
if (nom_connecte == '') {
nom_connecte = $("#nom_connecte_bis").text();
nom_connecte = nom_connecte.trim();
}
if (affichage_slug == 'produits') {
$("#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 +324,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');
}
});
});
});

11
public/js/utils.js Normal file
View File

@ -0,0 +1,11 @@
// cleanArray supprime les éléments dupliqués
function cleanArray(array) {
var i, j, len = array.length, out = [], obj = {};
for (i = 0; i < len; i++) {
obj[array[i]] = 0;
}
for (j in obj) {
out.push(j);
}
return out;
}

View File

@ -1,22 +1,26 @@
<?php
if (!isset($_SESSION)) {
session_start();
}
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
$requete = "SELECT username, password, role
FROM users
WHERE username = :username";
$query = $bdd->prepare($requete);
$query->execute($params);
$row = $query->fetch(PDO::FETCH_ASSOC);
if (password_verify($_POST['mdp'],$row['password'])) {
session_start();
$_SESSION['user']=$row['username'];
$_SESSION['connecte'] = $row['username'];
$_SESSION['role'] = $row['role'];
$_SESSION['logout'] = false;
echo '{"valide":true,"username":"'.$row['username'].'"}';
} else {
echo '{"valide":false}';

View File

@ -1,21 +1,21 @@
<?php
session_start();
//session_start();
ini_set('display_errors', 0);
include '../../config/config.php';
$antenne_slug = $_GET['antenne_slug'];
$nom_connecte = $_SESSION['user'];
$nom_connecte = $_GET['nom_connecte'];
$bdd = new \PDO("mysql:host=$db_server;dbname=$db_name", $db_username, $db_password);
// Affichage des intitulés de colonnes
$data = '<table class="table table-bordered table-striped">
<tr style="color: black;">
<th>No.</th>
<th>Bien / service</th>
<th>Photo</th>
<th>Vendeur</th>
<th>Clé publique</th>
<th>Quantité</th>
<th>Prix en junes</th>';
<tr style="color: black;">
<th>No.</th>
<th>Bien / service</th>
<th>Photo</th>
<th>Vendeur</th>
<th>Clé publique</th>
<th>Quantité</th>
<th>Prix en junes</th>';
$params["antenne_slug"] = $antenne_slug;
$requete = "SELECT products.*, users.username, users.pubkey
@ -25,30 +25,31 @@
LEFT JOIN users
ON users.id = products.user_id
WHERE antennes.slug = :antenne_slug";
$stmt = $bdd->prepare($requete);
$stmt2 = $bdd->prepare($requete);
$stmt->execute($params);
$stmt2->execute($params);
$count = $stmt->rowCount();
$affich_actions = false;
while ($row2 = $stmt2->fetch(PDO::FETCH_ASSOC)) {
if ($row2['username'] == $nom_connecte) {
$affich_actions = true;
}
$stmt = $bdd->prepare($requete);
$stmt2 = $bdd->prepare($requete);
$stmt->execute($params);
$stmt2->execute($params);
$count = $stmt->rowCount();
$affich_actions = false;
while ($row2 = $stmt2->fetch(PDO::FETCH_ASSOC)) {
if ($row2['username'] == $nom_connecte) {
$affich_actions = true;
}
if ($affich_actions) {
$data .= '<th colspan="2" style="text-align: center;">Actions</th>';
$data .= '</tr>';
} else {
$data .= '</tr>';
}
if ($count > 0)
{
$number = 1;
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
}
if ($affich_actions) {
$data .= '<th colspan="2" style="text-align: center;">Actions</th>';
$data .= '</tr>';
} else {
$data .= '</tr>';
}
if ($count > 0)
{
$number = 1;
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$data .= "<tr style='background:lightblue;color:black;'>
$data .= "<tr style='background:lightblue;color:black;'>
<td>$number</td>";
$prix = $row['prix'];
$vendeur = $row['username'];
$quantite = $row['quantite'];
@ -103,13 +104,13 @@
$data .= '<td></td><td></td>';
}
}
$data .= '</tr>';
$number++;
}
} else {
// Il n'y a pas encore de biens/services saisis
$data .= "<tr style='background-color:lightblue;text-align:left;color:black;'><td colspan='10'>Aucun enregistrement saisi</td></tr>";
$data .= '</tr>';
$number++;
}
$data .= '</table>';
echo $data;
} else {
// Il n'y a pas encore de biens/services saisis
$data .= "<tr style='background-color:lightblue;text-align:left;color:black;'><td colspan='10'>Aucun enregistrement saisi</td></tr>";
}
$data .= '</table>';
echo $data;
?>

View File

@ -1,9 +1,9 @@
<?php
session_start();
//session_start();
ini_set('display_errors', 0);
include '../../config/config.php';
$antenne_slug = $_GET['antenne_slug'];
$nom_connecte = $_SESSION['user'];
$nom_connecte = $_GET['nom_connecte'];
$bdd = new \PDO("mysql:host=$db_server;dbname=$db_name", $db_username, $db_password);
// Affichage des intitulés de colonnes

View File

@ -0,0 +1,90 @@
<?php
error_reporting(E_ALL & ~E_NOTICE);
include '../../config/config.php';
$bdd = new \PDO("mysql:host=$db_server;dbname=$db_name", $db_username, $db_password);
if(isset($_POST)) {
$params["user_id"] = $_POST['id_connecte'];
$antenne_id = $_POST['id_antenne'];
$etat_suivi = $_POST['etat_suivi'];
$maj = true;
// On lit le champ SuiviAntenne
$requete1 = "SELECT suiviantenne FROM users WHERE id = :user_id";
$query1 = $bdd->prepare($requete1);
$ancien_suivi = $query1->execute($params);
$suivi = $ancien_suivi;
//echo "ancien=".$ancien_suivi;
/*if (strpos($ancien_suivi,'|')>0) {
echo "strpos > 0";
$tableau = explode('|', $ancien_suivi);
$antennes_suivies = '';
// On ajoute l'antenne suivie
if ($etat_suivi == 'true') {
if (count($tableau) > 0) {
foreach ($valeur as $tableau) {
$antennes_suivies .= $valeur.'|';
}
$antennes_suivies .= $antenne_id;
}
} else {
// On retire l'antenne qui n'est plus suivie
foreach($valeur2 as $tableau) {
if ($valeur2 == $antenne_id) {
$ajout = '';
} else {
$ajout = $valeur2.'|';
}
$antennes_suivies .= $ajout;
}
// On supprime le pipe inutile à la fin de la chaîne
$antennes_suivies = substr($antennes_suivies,0,-1);
}*/
// On ajoute alors qu'il n'y a qu'une antenne dans le suivi ou aucune
if ($etat_suivi == 'true') {
if ($suivi == $antenne_id) {
echo "suivi 1 =".$suivi;
echo "<br />antenne_id =".$antenne_id;
$antennes_suivies = $antenne_id;
} elseif ($suivi != $antenne_id) {
echo "suivi 2 =".$suivi;
echo "<br />antenne_id =".$antenne_id;
$antennes_suivies = $suivi . '|' . $antenne_id;
}
}
if ($etat_suivi == 'true') {
if ($suivi == '') {
echo "suivi 0 =" . $suivi;
echo "<br />antenne_id =" . $antenne_id;
$antennes_suivies = $antenne_id;
}
}
if ($etat_suivi == 'false') {
if ($suivi != $antenne_id) {
echo "ERREUR 4 =" . $suivi;
echo "<br />antenne_id =" . $antenne_id;
//$antennes_suivies = $suivi . '|' . $antenne_id;
$maj = false;
} elseif ($suivi == $antenne_id) {
echo "suivi 3 =".$suivi;
echo "<br />antenne_id =".$antenne_id;
$antennes_suivies = '';
} elseif ($suivi == '') {
echo "suivi 5 =" . $suivi;
echo "<br />antenne_id =" . $antenne_id;
$antennes_suivies = '';
}
}
// Mise à jour du champ SuiviAntenne
if ($maj) {
$requete2 = "UPDATE users SET suiviantenne = '$antennes_suivies' WHERE id = :user_id";
$query2 = $bdd->prepare($requete2);
$query2->execute($params);
$query2->closeCursor();
}
$query1->closeCursor();
}

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

@ -6,6 +6,7 @@ use App\Account\Action\AccountEditAction;
use App\Account\Action\ProfilAction;
use App\Account\Action\SignupAction;
use Framework\Auth\LoggedInMiddleware;
use Framework\Auth\LoginModalMiddleware;
use Framework\Module;
use Framework\Renderer\RendererInterface;
use Framework\Router;
@ -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->post('/profil-utilisateur', ProfilAction::class);
$router->get('/profil/user/{user:[a-zA-Z\-0-9]+}', [LoginModalMiddleware::class, ProfilAction::class], 'account.profil');
$router->post('/profil/user/{user:[a-zA-Z\-0-9]+}', [LoginModalMiddleware::class, ProfilAction::class]);
}
}

View File

@ -0,0 +1,67 @@
<?php
namespace App\Account\Action;
use App\Auth\UserTable;
use Framework\Auth;
use Framework\Renderer\RendererInterface;
use Framework\Response\RedirectResponse;
use Framework\Session\FlashService;
use Framework\Validator;
use Psr\Http\Message\ServerRequestInterface;
class AccountUserEditAction
{
/**
* @var RendererInterface
*/
private $renderer;
/**
* @var Auth
*/
private $auth;
/**
* @var FlashService
*/
private $flashService;
/**
* @var UserTable
*/
private $userTable;
public function __construct(
RendererInterface $renderer,
Auth $auth,
FlashService $flashService,
UserTable $userTable
) {
$this->renderer = $renderer;
$this->auth = $auth;
$this->flashService = $flashService;
$this->userTable = $userTable;
}
public function __invoke(ServerRequestInterface $request)
{
//$user = $this->auth->getUser();
$params = $request->getParsedBody();
$url_part = explode('/',$_SERVER['HTTP_REFERER']);
$chemin = $url_part[3].'/'.$url_part[4];
$validator = (new Validator($params))
->required('firstname', 'lastname');
if ($validator->isValid()) {
$userParams = [
'firstname' => $params['firstname'],
'lastname' => $params['lastname']
];
$this->userTable->update($params['id_user'], $userParams);
$this->flashService->success("Le compte ".$params['username']." a bien été mis à jour");
return new RedirectResponse($chemin);
//return new RedirectResponse($request->getUri()->getPath());
}
$errors = $validator->getErrors();
return $this->renderer->render('@account/account', compact('user', 'errors'));
}
}

View File

@ -0,0 +1,78 @@
<?php
namespace App\Account\Action;
use App\Auth\UserTable;
use Framework\Auth;
use Framework\Renderer\RendererInterface;
use Framework\Response\RedirectResponse;
use Framework\Router;
use Framework\Session\FlashService;
use Framework\Validator;
use Psr\Http\Message\ServerRequestInterface;
class ActiveAction
{
/**
* @var RendererInterface
*/
private $renderer;
/**
* @var Auth
*/
private $auth;
/**
* @var FlashService
*/
private $flashService;
/**
* @var UserTable
*/
private $userTable;
public function __construct(
RendererInterface $renderer,
Auth $auth,
FlashService $flashService,
Router $router,
UserTable $userTable
) {
$this->renderer = $renderer;
$this->auth = $auth;
$this->flashService = $flashService;
$this->router = $router;
$this->userTable = $userTable;
}
public function __invoke(ServerRequestInterface $request)
{
$params = $request->getParsedBody();
$url_part = explode('/',$_SERVER['HTTP_REFERER']);
$chemin = $url_part[3].'/'.$url_part[4];
$validator = (new Validator($params))
->required('username', 'actif');
if ($validator->isValid()) {
if ($params['actif']) {
$params['actif'] = '0';
} else {
$params['actif'] = '1';
}
$userParams = [
'username' => $params['username'],
'actif' => $params['actif']
];
$this->userTable->update($params['id'], $userParams);
if (!$params['actif']) {
$this->flashService->success("L'utilisateur ".$params['username']." a bien été désactivé");
} else {
$this->flashService->success("L'utilisateur ".$params['username']." a bien été réactivé");
}
return new RedirectResponse($chemin);
}
$errors = $validator->getErrors();
return $this->renderer->render('@account/account', compact('user', 'errors'));
}
}

View File

@ -1,6 +1,8 @@
<?php
namespace App\Account\Action;
use App\Auth\UserTable;
use App\Gmarche\Table\AntenneTable;
use Framework\Auth;
use Framework\Renderer\RendererInterface;
use Psr\Http\Message\ServerRequestInterface;
@ -16,24 +18,31 @@ class ProfilAction
* @var Auth
*/
private $auth;
/**
* @var UserTable
*/
private $userTable;
public function __construct(
RendererInterface $renderer,
Auth $auth
AntenneTable $antenneTable,
Auth $auth,
UserTable $userTable
) {
$this->renderer = $renderer;
$this->antenneTable = $antenneTable;
$this->auth = $auth;
$this->userTable = $userTable;
}
public function __invoke(ServerRequestInterface $request)
{
/* Transmission du nom de l'utilistateur connecté à la vue Twig */
session_start();
if (isset($_SESSION['user'])) {
$nom_user = $_SESSION['user'];
} else {
$nom_user = '';
}
return $this->renderer->render('@account/profil', compact('nom_user'));
$listeAntennes = $this->antenneTable->findAllAntennes('');
$user_affiche = $request->getAttribute('user')->username;
$nom_avatar = $request->getAttribute('user')->avatar;
$email = $request->getAttribute('user')->email;
$suiviantenne = $request->getAttribute('user')->suiviantenne;
return $this->renderer->render('@account/profil',
compact('user_affiche', 'nom_avatar', 'email', 'listeAntennes', 'suiviantenne'));
}
}

View File

@ -60,7 +60,6 @@ class SignupAction
$validator = (new Validator($params))
->required('username', 'pubkey', 'email', 'password', 'password_confirm', 'created_at')
->length('username', 3)
->length('pubkey', 43)
->length('firstname', 0)
->length('lastname', 0)
->email('email')
@ -77,7 +76,8 @@ class SignupAction
'email' => $params['email'],
'password' => password_hash($params['password'], PASSWORD_DEFAULT),
'created_at' => $params['created_at'],
'role' => 'user'
'role' => '3',
'suiviantenne' => ''
];
$this->userTable->insert($userParams);
$user = Hydrator::hydrate($userParams, User::class);

View File

@ -17,7 +17,7 @@ class User extends \App\Auth\User
/**
* @var string
*/
private $role;
public $role;
public function getRoles(): array
{

View File

@ -1,15 +1,83 @@
{% extends 'layout.twig' %}
{% block body %}
<script type="text/javascript" src="/js/script.js"></script>
<div class="profil_user">
<h4>Profil utilisateur - {{ user_affiche }}</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;margin-top:0.6rem;">
<h5 class="card-title">Changement de mot de passe</h5>
<h5 class="card-title">(via l'envoi d'un lien par mail)</h5>
<div class="container" style="color:black;background-color: lightgray;opacity: 0.9;margin:0.5rem 0.2rem;padding:0.4rem;">
<form action="{{ path('auth.password') }}" method="post">
<button class="btn btn-primary">Renvoyer un mot de passe</button>
<div style="width:0;height:0;">
{{ field('username', user_affiche, "", {type: 'hidden'}) }}
{{ field('email', email, "", {type: 'hidden'}) }}
</div>
</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;">
<ul class="list-group list-group-flush">
{% set antenne_suivie = suiviantenne|split('|') %}
{% for antenn in antenne_suivie %}
<li class="liste_antennes list-group-item" style="padding: .2rem 1.25rem;">
{% for item in listeAntennes %}
{% if (item.id == antenn) %}
{{ item.antenneName }}
{% endif %}
{% endfor %}
</li>
{% endfor %}
</ul>
</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

@ -2,8 +2,12 @@
namespace App\Admin;
use App\Product\Actions\ProductIndexAction;
use App\Product\Actions\ProductCrudAction;
use App\Account\Action\AccountUserAction;
use App\Account\Action\AccountUserEditAction;
use App\Account\Action\ActiveAction;
use App\Antenne\Actions\AntenneEditAction;
use App\Antenne\Actions\AntenneCrudAction;
use Framework\Auth\LoggedInMiddleware;
use Framework\Module;
use Framework\Renderer\RendererInterface;
use Framework\Renderer\TwigRenderer;
@ -11,7 +15,6 @@ use Framework\Router;
class AdminModule extends Module
{
const DEFINITIONS = __DIR__ . '/config.php';
public function __construct(
@ -19,13 +22,23 @@ class AdminModule extends Module
Router $router,
AdminTwigExtension $adminTwigExtension,
string $prefix
) {
$renderer->addPath('admin', __DIR__ . '/views');
//$router->get('/machin', ProductCrudAction::class, 'machin.bidule'); // ProductIndexAction
/*if ($renderer instanceof TwigRenderer) {
)
{
$chemin = str_replace('Admin','Antenne',__DIR__);
$renderer->addPath('antenne', $chemin . '/views');
$router->get('/dashboard/{user:[a-zA-Z\-0-9]+}', [LoggedInMiddleware::class, DashboardAction::class], 'dashboard');
$router->get('/dashboard/details/{user:[a-zA-Z\-0-9]+}', [LoggedInMiddleware::class, DashboardUserAction::class], 'dashboard.user');
$router->get('/activation', [LoggedInMiddleware::class, ActiveAction::class], 'account.active');
$router->post('/activation', ActiveAction::class);
$router->get('/profil-user', [LoggedInMiddleware::class, AccountUserEditAction::class], 'account.user');
$router->post('/profil-user', [LoggedInMiddleware::class, AccountUserEditAction::class]);
//$router->get('/antenne/new', [LoggedInMiddleware::class, AntenneCrudAction::class], 'antenne.create');
$router->crud('/antenne', [LoggedInMiddleware::class, AntenneCrudAction::class],'antenne');
$router->get('/antenne/edit', [LoggedInMiddleware::class, AntenneEditAction::class], 'antenne.edit');
$router->post('/antenne/edit', [LoggedInMiddleware::class, AntenneEditAction::class]);
if ($renderer instanceof TwigRenderer) {
$renderer->getTwig()->addExtension($adminTwigExtension);
}*/
// $renderer->getTwig()->addExtension($variableExtension);
}
}
}

View File

@ -0,0 +1,75 @@
<?php
namespace App\Admin;
if (!isset($_SESSION)) {
session_start();
}
use App\Admin\Table\UserTable;
use App\Gmarche\Table\AntenneTable;
use Framework\Renderer\RendererInterface;
use Framework\Session\SessionInterface;
use Psr\Http\Message\ServerRequestInterface;
class DashboardAction
{
/**
* @var RendererInterface
*/
private $renderer;
/**
* @var AntenneTable
*/
private $antenneTable;
/**
* @var SessionInterface
*/
private $session;
/**
* @var UserTable
*/
private $userTable;
public function __construct(
RendererInterface $renderer,
AntenneTable $antenneTable,
SessionInterface $session,
UserTable $userTable)
{
$this->renderer = $renderer;
$this->antenneTable = $antenneTable;
$this->session = $session;
$this->userTable = $userTable;
}
/**
* @param ServerRequestInterface $request
* @return string
*/
public function __invoke(ServerRequestInterface $request)
{
if ($request->getMethod() === 'GET') {
$role = $this->session->get('role', []);
$username = $this->session->get('username', []);
$this->renderer->addPath('admin', __DIR__ . '/views');
$page = $params['p'] ?? 1; // Si la page n'est pas définie, on l'initialise à 1
$liste_adminGeneral = $this->userTable->findAdminUsers('1');
$liste_adminAntenne = $this->userTable->findAdminUsers('2');
$liste_users_suivi = $this->userTable->findUsers('3');
$listeAntennes = $this->antenneTable->findAllAntennes('',false,'');
if ($this->session->get('username')) {
$this->session->delete('role');
$this->session->delete('username');
$this->session->set('role',$role);
$this->session->set('username',$username);
} else {
$this->session->set('username',$username);
$this->session->set('role',$role);
}
$sess = $_SESSION;
return $this->renderer->render('@admin/dashboard',
compact('sess','username','liste_adminGeneral', 'liste_users_suivi',
'liste_adminAntenne', 'listeAntennes'));
}
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace App\Admin;
if (!isset($_SESSION)) {
session_start();
}
use App\Auth\UserTable;
use App\Admin\Table\UserTable as UserTableAdmin;
use App\Gmarche\Table\AntenneTable;
use Framework\Auth;
use Framework\Renderer\RendererInterface;
use Psr\Http\Message\ServerRequestInterface;
class DashboardUserAction
{
/**
* @var RendererInterface
*/
private $renderer;
/**
* @var Auth
*/
private $auth;
/**
* @var AntenneTable
*/
private $antenneTable;
/**
* @var UserTable
*/
private $userTable;
public function __construct(
RendererInterface $renderer,
Auth $auth,
AntenneTable $antenneTable,
UserTable $userTable,
UserTableAdmin $userTableAdmin)
{
$this->renderer = $renderer;
$this->auth = $auth;
$this->antenneTable = $antenneTable;
$this->userTable = $userTable;
$this->userTableAdmin = $userTableAdmin;
}
/**
* @param ServerRequestInterface $request
* @return string
*/
public function __invoke(ServerRequestInterface $request)
{
if ($request->getMethod() === 'GET') {
$this->renderer->addPath('admin', __DIR__ . '/views');
$liste_users_suivi = $this->userTableAdmin->findUsers('3');
$url_part = explode('/',$_SERVER['REQUEST_URI']);
$user_affiche = $url_part[3];
$user = $this->userTable->findBy('username', $user_affiche);
$id_affiche = $user->id;
$actif_affiche = $user->actif;
$listeAntennes = $this->antenneTable->findAllAntennes('');
$sess = $_SESSION;
return $this->renderer->render('@admin/dashboard_user',
compact('sess','user_affiche','id_affiche', 'actif_affiche', 'user','liste_users_suivi','listeAntennes'));
}
}
}

35
src/Admin/Entity/User.php Normal file
View File

@ -0,0 +1,35 @@
<?php
namespace App\Admin\Entity;
class User
{
public $id;
public $username;
public $email;
public $password;
public $firstname;
public $lastname;
public $created_at;
public $role;
public $password_reset;
public $password_reset_at;
public $pubkey;
public $avatar;
public $suiviantenne;
public $actif;
}

View File

@ -0,0 +1,74 @@
<?php
namespace App\Admin\Table;
use App\Admin\Entity\User;
use App\Gmarche\Table\AntenneTable;
use Framework\Database\Query;
use Framework\Database\Table;
class UserTable extends Table
{
protected $entity = User::class;
protected $table = 'users';
public function findList(): array
{
$results = $this->pdo
->query("SELECT id, name FROM {$this->table}")
->fetchAll(\PDO::FETCH_NUM);
$list = [];
foreach ($results as $result) {
$list[$result[0]] = $result[1];
}
return $list;
}
public function findAntennebyId(int $id_antenne): Query
{
$antenne = new AntenneTable($this->pdo);
return $this->makeQuery()
->select('a.name as nameAntenne')
->where("a.id = $id_antenne");
}
public function findUsers($role): Query
{
return $this->makeQuery()
->select('u.*')
->where("u.role = '" . $role . "'")
->order('u.username ASC');
}
/*public function findUsersSuivi($role): Query
{
$antenne = new AntenneTable($this->pdo);
return $this->makeQuery()
->join($antenne->getTable() . ' as a', 'substring(u.suiviantenne,1,1) = a.id')
->select('u.*,a.name as nameAntenne')
->where("u.role = '".$role."'")
->order('u.username, nameAntenne ASC');
}*/
public function findAdminUsers($role): Query
{
return $this->makeQuery()
->select('u.*')
->where("u.role = $role")
->order('u.username ASC');
}
public function findRole($username): Query
{
return $this->makeQuery()
->select('u.role')
->where("u.username = '" . $username . "'");
}
public function findRole2($username)
{
return $this->pdo
->query("SELECT role FROM {$this->table} WHERE username='".$username."'")
->fetch();
}
}

View File

@ -1,12 +1,10 @@
<?php
use App\Admin\AdminModule;
use App\Admin\DashboardAction;
return [
'admin.prefix' => '/admin',
'admin.widgets' => [],
\App\Admin\AdminTwigExtension::class => \DI\object()->constructor(\DI\get('admin.widgets')),
AdminModule::class => \DI\object()->constructorParameter('prefix', \DI\get('admin.prefix'))
//DashboardAction::class => \DI\object()->constructorParameter('widgets', \DI\get('admin.widgets'))
];

View File

@ -0,0 +1,112 @@
{% extends 'layout.twig' %}
{% block title "Ğ1-Marché - Tableau de bord" %}
{% block body %}
<div class="container" style="color:floralwhite;background-color: #333333;padding: 1rem;">
<div class="container tab-de-bord">
<h3 style="display:inline-block;">Tableau de bord - </h3>
<h4 style="display:inline-block;">
{% if (sess.role == 0) %} Super Admin{% endif %}
{% if (sess.role == 1) %} Admin général{% endif %}
{% if (sess.role == 2) %} Admin Antenne{% endif %}
</h4>
</h3>
</div>
<p></p>
{% if (sess.role == 0) %}
<h4>Liste des admins généraux</h4>
<ul class="list-group list-group-flush">