diff --git a/.gitignore b/.gitignore index 9c26537..4be7e6c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,8 @@ 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 \ No newline at end of file diff --git a/config/config-backup.php b/config/config-backup.php new file mode 100644 index 0000000..d4a789c --- /dev/null +++ b/config/config-backup.php @@ -0,0 +1,55 @@ + \DI\env('ENV', 'production'), + /*'env' => \DI\env('ENV', 'development'),*/ + 'database.host' => $host, + //'database.username' => 'guser', + 'database.username' => $username, + //'database.password' => 'kptgT81U7nzYWHBdQ9', + 'database.password' => $password, + 'database.name' => $database_name, + 'views.path' => dirname(__DIR__) . '/views', + 'twig.extensions' => [ + \DI\get(RouterTwigExtension::class), + \DI\get(PagerFantaExtension::class), + \DI\get(TextExtension::class), + \DI\get(TimeExtension::class), + \DI\get(FlashExtension::class), + \DI\get(FormExtension::class), + \DI\get(CsrfExtension::class), + \DI\get(UrlExtension::class) + ], + SessionInterface::class => \DI\object(PHPSession::class), + CsrfMiddleware::class => \DI\object()->constructor(\DI\get(SessionInterface::class)), + Router::class => \DI\factory(RouterFactory::class), + RendererInterface::class => \DI\factory(TwigRendererFactory::class), + \PDO::class => function (\Psr\Container\ContainerInterface $c) { + return new PDO( + 'mysql:host='. $c->get('database.host') . ';dbname=' . $c->get('database.name'), + $c->get('database.username'), + $c->get('database.password'), + [ + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION + ] + ); + }, + // MAILER + 'mail.to' => 'mailto@admin.fr', + 'mail.from' => 'no-reply@admin.fr', + Swift_Mailer::class => \DI\factory(\Framework\SwiftMailerFactory::class) +]; \ No newline at end of file diff --git a/public/css/style.css b/public/css/style.css index 8fe14b9..072889c 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -167,18 +167,24 @@ header.header img { display: block; margin: auto; } + +/******************************************************************/ +/* dashboard.twig */ +/******************************************************************/ +.tab-de-bord { + background-color: brown; + padding: 1rem; + min-width: 350px; +} /******************************************************************/ /* layout.twig */ /******************************************************************/ - .mdp_oublie:hover { background-color: deepskyblue; } - /******************************************************************/ /* LOADING PUBKEY */ /******************************************************************/ - #cle_pub { display: none; } @@ -200,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: 280px; + } + /******************************************************************/ + /* layout.twig */ + /******************************************************************/ .fond { background-color: black; background-image: url("../images/bildreich_1275.jpg"); diff --git a/public/index.php b/public/index.php index 8c8159b..8756a1f 100644 --- a/public/index.php +++ b/public/index.php @@ -34,18 +34,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) diff --git a/public/models/connexion.php b/public/models/connexion.php index 95deb85..91816eb 100644 --- a/public/models/connexion.php +++ b/public/models/connexion.php @@ -8,7 +8,7 @@ try { 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); @@ -17,6 +17,7 @@ try { if (password_verify($_POST['mdp'],$row['password'])) { session_start(); $_SESSION['user']=$row['username']; + $_SESSION['role']=$row['role']; echo '{"valide":true,"username":"'.$row['username'].'"}'; } else { echo '{"valide":false}'; diff --git a/public/models/readRecords.php b/public/models/readRecords.php index 474c6d1..f679ae9 100644 --- a/public/models/readRecords.php +++ b/public/models/readRecords.php @@ -8,14 +8,14 @@ // Affichage des intitulés de colonnes $data = ' - - - - - - - - '; + + + + + + + + '; $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 .= ''; - $data .= ''; - } else { - $data .= ''; - } - if ($count > 0) - { - $number = 1; - while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { +} +if ($affich_actions) { + $data .= ''; + $data .= ''; +} else { + $data .= ''; +} +if ($count > 0) +{ + $number = 1; + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { - $data .= " + $data .= ""; + $prix = $row['prix']; $vendeur = $row['username']; $quantite = $row['quantite']; @@ -103,13 +104,13 @@ $data .= ''; } } - $data .= ''; - $number++; - } - } else { - // Il n'y a pas encore de biens/services saisis - $data .= ""; + $data .= ''; + $number++; } - $data .= '
No.Bien / servicePhotoVendeurClé publiqueQuantitéPrix en junes
No.Bien / servicePhotoVendeurClé publiqueQuantitéPrix en junesActions
Actions
$number
Aucun enregistrement saisi
'; - echo $data; +} else { + // Il n'y a pas encore de biens/services saisis + $data .= "Aucun enregistrement saisi"; +} +$data .= ''; +echo $data; ?> diff --git a/src/Account/Action/ActiveAction.php b/src/Account/Action/ActiveAction.php new file mode 100644 index 0000000..6aa61fb --- /dev/null +++ b/src/Account/Action/ActiveAction.php @@ -0,0 +1,70 @@ +renderer = $renderer; + $this->auth = $auth; + $this->flashService = $flashService; + $this->userTable = $userTable; + } + + public function __invoke(ServerRequestInterface $request) + { + $user = $this->auth->getUser(); + var_dump($user); + die(); + $params = $request->getParsedBody(); + $validator = (new Validator($params)) + ->required('username', 'actif'); + if ($validator->isValid()) { + $userParams = [ + 'username' => $params['username'], + 'actif' => $params['actif'] + ]; + + $this->userTable->update($user->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($request->getUri()->getPath()); + } + $errors = $validator->getErrors(); + return $this->renderer->render('@account/account', compact('user', 'errors')); + } +} diff --git a/src/Admin/AdminModule.php b/src/Admin/AdminModule.php index 8f28a30..8ce7888 100644 --- a/src/Admin/AdminModule.php +++ b/src/Admin/AdminModule.php @@ -2,8 +2,7 @@ namespace App\Admin; -use App\Product\Actions\ProductIndexAction; -use App\Product\Actions\ProductCrudAction; +use App\Account\Action\ActiveAction; use Framework\Module; use Framework\Renderer\RendererInterface; use Framework\Renderer\TwigRenderer; @@ -11,7 +10,6 @@ use Framework\Router; class AdminModule extends Module { - const DEFINITIONS = __DIR__ . '/config.php'; public function __construct( @@ -19,13 +17,14 @@ 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) { + ) + { + $router->get('/dashboard', DashboardAction::class, 'dashboard'); + $router->get('/dashboard/{user:[a-zA-Z\-0-9]+}', DashboardUserAction::class, 'dashboard.user'); + $router->get('/activation', ActiveAction::class, 'account.active'); + $router->post('/activation', ActiveAction::class); + if ($renderer instanceof TwigRenderer) { $renderer->getTwig()->addExtension($adminTwigExtension); - }*/ + } } } diff --git a/src/Admin/DashboardAction.php b/src/Admin/DashboardAction.php new file mode 100644 index 0000000..006d610 --- /dev/null +++ b/src/Admin/DashboardAction.php @@ -0,0 +1,66 @@ +renderer = $renderer; + $this->antenneTable = $antenneTable; + $this->userTable = $userTable; + } + + /** + * @param ServerRequestInterface $request + * @return string + */ + public function __invoke(ServerRequestInterface $request) + { + if ($request->getMethod() === 'GET') { + + $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(); + if (!isset($_SESSION)) { + session_start(); + } + if (isset($_SESSION['user'])) { + $nom_user = $_SESSION['user']; + $role = $_SESSION['role']; + } else { + $nom_user = ''; + $role = '3'; + } + return $this->renderer->render('@admin/dashboard', + compact('nom_user','role', 'liste_adminGeneral', 'liste_users_suivi', + 'liste_adminAntenne', 'listeAntennes')); + } + } +} diff --git a/src/Admin/DashboardUserAction.php b/src/Admin/DashboardUserAction.php new file mode 100644 index 0000000..69e34fb --- /dev/null +++ b/src/Admin/DashboardUserAction.php @@ -0,0 +1,76 @@ +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'); + + $username = $request->getAttribute('user'); + + $profil_user = $this->userTable->findBy('username', $username); + // var_dump($profil_user); + // die(); + $listeAntennes = $this->antenneTable->findAllAntennes(); + if (!isset($_SESSION)) { + session_start(); + } + if (isset($_SESSION['user'])) { + $nom_user = $_SESSION['user']; + $role = $_SESSION['role']; + } else { + $nom_user = ''; + $role = '3'; + } + + return $this->renderer->render('@admin/dashboard_user', + compact('nom_user','role','username','profil_user','liste_users_suivi','listeAntennes')); + } + } +} diff --git a/src/Admin/Entity/User.php b/src/Admin/Entity/User.php new file mode 100644 index 0000000..a92a0cd --- /dev/null +++ b/src/Admin/Entity/User.php @@ -0,0 +1,35 @@ +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"); + } + +} diff --git a/src/Admin/views/dashboard.twig b/src/Admin/views/dashboard.twig new file mode 100644 index 0000000..04d9a93 --- /dev/null +++ b/src/Admin/views/dashboard.twig @@ -0,0 +1,105 @@ +{% extends 'layout.twig' %} + +{% block title "Ğ1-Marché - Tableau de bord" %} + +{% block body %} +
+
+

Tableau de bord -

+

+ {% if role == '0' %} Super Admin{% endif %} + {% if role == '1' %} Admin général{% endif %} + {% if role == '2' %} Admin Antenne{% endif %} +

+ +
+

+ {% if role == '0' %} +

Liste des admins généraux

+ + {% endif %} +

+ {% if (role == '0' or role == '1') %} +

Liste des admins Antenne

+ + {% endif %} +

+ {% if (role == '0' or role == '1' or role == '2') %} +

Liste des régions/antennes

+ + {% endif %} +

+ {% if (role == '0' or role == '1' or role == '2') %} +

Liste des utilisateurs

+ + + {% endif %} +

+ {% if (role == '0' or role == '1') %} +

Gestion d'une antenne

+ {% endif %} +

+ {% if (role == '0' or role == '1' or role == '2') %} +

Gestion d'un G-Marché

+ {% endif %} +
+ {{ widgets | raw }} +
+
+{% endblock %} \ No newline at end of file diff --git a/src/Admin/views/dashboard_user.twig b/src/Admin/views/dashboard_user.twig new file mode 100644 index 0000000..e8a5434 --- /dev/null +++ b/src/Admin/views/dashboard_user.twig @@ -0,0 +1,65 @@ +{% extends 'layout.twig' %} + +{% block title "Ğ1-Marché - Tableau de bord User" %} + +{% block body %} +
+
+

Tableau de bord User - {{ username }}

+
+ +

+

Profil

+ + + +

+

Liste des antennes suivies

+ + +

+
+{% endblock %} \ No newline at end of file diff --git a/src/Admin/views/layout.twig b/src/Admin/views/layout.twig index 93024c9..440c29b 100644 --- a/src/Admin/views/layout.twig +++ b/src/Admin/views/layout.twig @@ -1,7 +1,7 @@ - {% block title "Mon site " %} + {% block title "Ğ1-Marché - Administration" %}