From 8e3e130f93b8fb9cbb0fc576d82be08f608e812b Mon Sep 17 00:00:00 2001 From: Baptiste D Date: Sat, 18 Nov 2023 12:08:52 +0100 Subject: [PATCH 01/10] =?UTF-8?q?d=C3=A9but=20alto=20routeur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- php/.htaccess | 9 +- php/index.php | 15 ++ php/public/index.php | 16 -- php/src/config/Validation.php | 12 + php/src/controleur/FrontControleur.php | 59 ++++- php/src/router/AltoRouter.php | 304 +++++++++++++++++++++++++ php/templates/connection.html | 2 +- php/templates/detailEvenement.html | 2 +- php/templates/erreur.html | 2 +- php/templates/evenement.html | 8 +- php/templates/inscription.html | 2 +- php/templates/inscription_success.html | 2 +- 12 files changed, 401 insertions(+), 32 deletions(-) create mode 100755 php/index.php delete mode 100755 php/public/index.php create mode 100644 php/src/router/AltoRouter.php diff --git a/php/.htaccess b/php/.htaccess index 095bf2a..7ded04e 100644 --- a/php/.htaccess +++ b/php/.htaccess @@ -1,6 +1,3 @@ - - RewriteEngine On - RewriteBase /php/public/ - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ index.php [QSA,L] - +RewriteEngine on +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule . index.php [L] \ No newline at end of file diff --git a/php/index.php b/php/index.php new file mode 100755 index 0000000..8252479 --- /dev/null +++ b/php/index.php @@ -0,0 +1,15 @@ + false, + 'debug' => true +]); +$twig->addExtension(new \Twig\Extension\DebugExtension()); +$cont = new \App\controleur\FrontControleur(); \ No newline at end of file diff --git a/php/public/index.php b/php/public/index.php deleted file mode 100755 index 2bce566..0000000 --- a/php/public/index.php +++ /dev/null @@ -1,16 +0,0 @@ - false, - 'debug' => true -]); -$twig->addExtension(new \Twig\Extension\DebugExtension()); -$cont = new \App\controleur\FrontControleur(); \ No newline at end of file diff --git a/php/src/config/Validation.php b/php/src/config/Validation.php index 62d1465..4960b2a 100755 --- a/php/src/config/Validation.php +++ b/php/src/config/Validation.php @@ -1,6 +1,7 @@ setBasePath('/php'); + + $router->map('GET','/','UtilisateurControleur'); + + $router->map('GET|POST','/user/[i:id]/[a:action]?','MembreControleur'); + + $router->map('GET|POST','/admin/[i:id]/[a:action]?','AdminControleur'); + + $id = 0; + + + $match = $router->match(); + $action = array(); + + $id=array(); + + if(!$match) + { + global $twig; + $dVueErreur[] = "Error 404 Page not found"; + echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]); + } + + if($match) + { + $controller = $match['target'] ?? NULL; + $action = $match['params']['actions'] ?? NULL; + $id = $match['params']['id'] ?? NULL; + + } + + try{ + $controller = new $controller; + } + catch (Error $error) + { + $dVueErreur = ['Erreur : Action inconnue']; + $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); + } + + } + + + + +} + +/*class FrontControleur { public function __construct() { @@ -52,4 +109,4 @@ class FrontControleur new UtilisateurControleur(); } } -} +}*/ diff --git a/php/src/router/AltoRouter.php b/php/src/router/AltoRouter.php new file mode 100644 index 0000000..3f7c952 --- /dev/null +++ b/php/src/router/AltoRouter.php @@ -0,0 +1,304 @@ + + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +class AltoRouter +{ + + /** + * @var array Array of all routes (incl. named routes). + */ + protected $routes = []; + + /** + * @var array Array of all named routes. + */ + protected $namedRoutes = []; + + /** + * @var string Can be used to ignore leading part of the Request URL (if main file lives in subdirectory of host) + */ + protected $basePath = ''; + + /** + * @var array Array of default match types (regex helpers) + */ + protected $matchTypes = [ + 'i' => '[0-9]++', + 'a' => '[0-9A-Za-z]++', + 'h' => '[0-9A-Fa-f]++', + '*' => '.+?', + '**' => '.++', + '' => '[^/\.]++' + ]; + + /** + * Create router in one call from config. + * + * @param array $routes + * @param string $basePath + * @param array $matchTypes + * @throws Exception + */ + public function __construct(array $routes = [], $basePath = '', array $matchTypes = []) + { + $this->addRoutes($routes); + $this->setBasePath($basePath); + $this->addMatchTypes($matchTypes); + } + + /** + * Retrieves all routes. + * Useful if you want to process or display routes. + * @return array All routes. + */ + public function getRoutes() + { + return $this->routes; + } + + /** + * Add multiple routes at once from array in the following format: + * + * $routes = [ + * [$method, $route, $target, $name] + * ]; + * + * @param array $routes + * @return void + * @author Koen Punt + * @throws Exception + */ + public function addRoutes($routes) + { + if (!is_array($routes) && !$routes instanceof Traversable) { + throw new RuntimeException('Routes should be an array or an instance of Traversable'); + } + foreach ($routes as $route) { + call_user_func_array([$this, 'map'], $route); + } + } + + /** + * Set the base path. + * Useful if you are running your application from a subdirectory. + * @param string $basePath + */ + public function setBasePath($basePath) + { + $this->basePath = $basePath; + } + + /** + * Add named match types. It uses array_merge so keys can be overwritten. + * + * @param array $matchTypes The key is the name and the value is the regex. + */ + public function addMatchTypes(array $matchTypes) + { + $this->matchTypes = array_merge($this->matchTypes, $matchTypes); + } + + /** + * Map a route to a target + * + * @param string $method One of 5 HTTP Methods, or a pipe-separated list of multiple HTTP Methods (GET|POST|PATCH|PUT|DELETE) + * @param string $route The route regex, custom regex must start with an @. You can use multiple pre-set regex filters, like [i:id] + * @param mixed $target The target where this route should point to. Can be anything. + * @param string $name Optional name of this route. Supply if you want to reverse route this url in your application. + * @throws Exception + */ + public function map($method, $route, $target, $name = null) + { + + $this->routes[] = [$method, $route, $target, $name]; + + if ($name) { + if (isset($this->namedRoutes[$name])) { + throw new RuntimeException("Can not redeclare route '{$name}'"); + } + $this->namedRoutes[$name] = $route; + } + + return; + } + + /** + * Reversed routing + * + * Generate the URL for a named route. Replace regexes with supplied parameters + * + * @param string $routeName The name of the route. + * @param array @params Associative array of parameters to replace placeholders with. + * @return string The URL of the route with named parameters in place. + * @throws Exception + */ + public function generate($routeName, array $params = []) + { + + // Check if named route exists + if (!isset($this->namedRoutes[$routeName])) { + throw new RuntimeException("Route '{$routeName}' does not exist."); + } + + // Replace named parameters + $route = $this->namedRoutes[$routeName]; + + // prepend base path to route url again + $url = $this->basePath . $route; + + if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { + foreach ($matches as $index => $match) { + list($block, $pre, $type, $param, $optional) = $match; + + if ($pre) { + $block = substr($block, 1); + } + + if (isset($params[$param])) { + // Part is found, replace for param value + $url = str_replace($block, $params[$param], $url); + } elseif ($optional && $index !== 0) { + // Only strip preceding slash if it's not at the base + $url = str_replace($pre . $block, '', $url); + } else { + // Strip match block + $url = str_replace($block, '', $url); + } + } + } + + return $url; + } + + /** + * Match a given Request Url against stored routes + * @param string $requestUrl + * @param string $requestMethod + * @return array|boolean Array with route information on success, false on failure (no match). + */ + public function match($requestUrl = null, $requestMethod = null) + { + + $params = []; + + // set Request Url if it isn't passed as parameter + if ($requestUrl === null) { + $requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'; + } + + // strip base path from request url + $requestUrl = substr($requestUrl, strlen($this->basePath)); + + // Strip query string (?a=b) from Request Url + if (($strpos = strpos($requestUrl, '?')) !== false) { + $requestUrl = substr($requestUrl, 0, $strpos); + } + + $lastRequestUrlChar = $requestUrl ? $requestUrl[strlen($requestUrl)-1] : ''; + + // set Request Method if it isn't passed as a parameter + if ($requestMethod === null) { + $requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; + } + + foreach ($this->routes as $handler) { + list($methods, $route, $target, $name) = $handler; + + $method_match = (stripos($methods, $requestMethod) !== false); + + // Method did not match, continue to next route. + if (!$method_match) { + continue; + } + + if ($route === '*') { + // * wildcard (matches all) + $match = true; + } elseif (isset($route[0]) && $route[0] === '@') { + // @ regex delimiter + $pattern = '`' . substr($route, 1) . '`u'; + $match = preg_match($pattern, $requestUrl, $params) === 1; + } elseif (($position = strpos($route, '[')) === false) { + // No params in url, do string comparison + $match = strcmp($requestUrl, $route) === 0; + } else { + // Compare longest non-param string with url before moving on to regex + // Check if last character before param is a slash, because it could be optional if param is optional too (see https://github.com/dannyvankooten/AltoRouter/issues/241) + if (strncmp($requestUrl, $route, $position) !== 0 && ($lastRequestUrlChar === '/' || $route[$position-1] !== '/')) { + continue; + } + + $regex = $this->compileRoute($route); + $match = preg_match($regex, $requestUrl, $params) === 1; + } + + if ($match) { + if ($params) { + foreach ($params as $key => $value) { + if (is_numeric($key)) { + unset($params[$key]); + } + } + } + + return [ + 'target' => $target, + 'params' => $params, + 'name' => $name + ]; + } + } + + return false; + } + + /** + * Compile the regex for a given route (EXPENSIVE) + * @param $route + * @return string + */ + protected function compileRoute($route) + { + if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { + $matchTypes = $this->matchTypes; + foreach ($matches as $match) { + list($block, $pre, $type, $param, $optional) = $match; + + if (isset($matchTypes[$type])) { + $type = $matchTypes[$type]; + } + if ($pre === '.') { + $pre = '\.'; + } + + $optional = $optional !== '' ? '?' : null; + + //Older versions of PCRE require the 'P' in (?P) + $pattern = '(?:' + . ($pre !== '' ? $pre : null) + . '(' + . ($param !== '' ? "?P<$param>" : null) + . $type + . ')' + . $optional + . ')' + . $optional; + + $route = str_replace($block, $pattern, $route); + } + } + return "`^$route$`u"; + } +} diff --git a/php/templates/connection.html b/php/templates/connection.html index c199201..872f803 100755 --- a/php/templates/connection.html +++ b/php/templates/connection.html @@ -37,7 +37,7 @@
-
+
diff --git a/php/templates/detailEvenement.html b/php/templates/detailEvenement.html index fd9e78d..ac3a0fe 100644 --- a/php/templates/detailEvenement.html +++ b/php/templates/detailEvenement.html @@ -24,7 +24,7 @@

Description: {{ evenement.description }}

Event Image

Places disponibles: {{ evenement.nbPlaceMax }}

- Retour + Retour
{% else %}

L'événement n'existe pas ou n'est pas disponible.

diff --git a/php/templates/erreur.html b/php/templates/erreur.html index ea207e5..5b78019 100755 --- a/php/templates/erreur.html +++ b/php/templates/erreur.html @@ -21,7 +21,7 @@

{{value}}

{% endfor %} {% endif %} -
+
diff --git a/php/templates/evenement.html b/php/templates/evenement.html index 8d45c2e..3e68ce5 100644 --- a/php/templates/evenement.html +++ b/php/templates/evenement.html @@ -15,14 +15,14 @@
-
+

Liste des Événements

- Publier événement + Publier événement
    @@ -36,9 +36,9 @@

    Description: {{ evenement.description }}

    {{ evenement.titre }}

    Places disponibles: {{ evenement.nbPlaceMax }}

    - Détails + Détails
-
+ diff --git a/php/templates/inscription.html b/php/templates/inscription.html index a22ee4b..456c0f2 100755 --- a/php/templates/inscription.html +++ b/php/templates/inscription.html @@ -62,7 +62,7 @@
-
+
diff --git a/php/templates/inscription_success.html b/php/templates/inscription_success.html index 3e1f2b3..2843e6c 100644 --- a/php/templates/inscription_success.html +++ b/php/templates/inscription_success.html @@ -15,7 +15,7 @@
From b7a820f49d4de866f5c9bbd2bcce9025cb7270f0 Mon Sep 17 00:00:00 2001 From: Baltazouu Date: Sat, 18 Nov 2023 17:55:42 +0100 Subject: [PATCH 02/10] avancees altorouteur --- php/src/TwigExtensions.php | 24 ------ php/src/modele/OffreModele.php | 145 --------------------------------- 2 files changed, 169 deletions(-) delete mode 100644 php/src/TwigExtensions.php delete mode 100644 php/src/modele/OffreModele.php diff --git a/php/src/TwigExtensions.php b/php/src/TwigExtensions.php deleted file mode 100644 index 64fe288..0000000 --- a/php/src/TwigExtensions.php +++ /dev/null @@ -1,24 +0,0 @@ -offreGw = new OffreGateway(new Connection(DB_HOST,DB_USER,DB_PASS)); - } - - public function publishOffer(string $img, string $logo) - { - $desc = $_POST["description"]; - $descposte = $_POST["descriptPoste"]; - $nom = $_POST["name"]; - $ville = $_POST["ville"]; - $entreprise = $_POST["entreprise"]; - $profilRecherche = $_POST["profilRecherche"]; - $mail = $_POST["mail"]; - $num = $_POST["num"]; - $site = $_POST["site"]; - $exp = $_POST["choixExp"]; - $typeContrat = $_POST["typeContrat"]; - $niveauEtudes = $_POST["education"]; - $date = new \DateTime(); - - if(isset($_POST["fullRemote"])) - { - $remote = true; - } - else $remote = false; - - // à la place de NULL passer id utilisateur créateur offre - $offre = new Offre($this->offreGw->getNewId(), - new Alumni("test.mail@icloud.fr","password","admin","prenom","nom"), - $nom, - $desc, - $img, - $logo, - $typeContrat, - $ville, - $entreprise, - $descposte, - $profilRecherche, - $exp, - $niveauEtudes, - $mail, - $num, - $site, - $remote, - $date); - - $this->offreGw->addOffers($offre); - - return $offre; - - } - public function getOffers() : array - { - $res = $this->offreGw->getOffers(); - $offers = $this->CreateOffersFromGw($res); - return $offers; - } - - - public function getOfferFromId(int $id) : ?Offre - { - $res = $this->offreGw->getOfferFromId($id); - if($res != null) - return $this->CreateOffersFromGw($res)[0]; - return null; - } - - public function CreateOffersFromGw($res) : array - { - $alGw = new AlumniGateway(new Connection(DB_HOST,DB_USER,DB_PASS)); - - $offers=[]; - foreach ($res as $row) - { - $resal = $alGw->ObtenirById($row['offreur']); - $profilGw = new ProfilGateway(new Connection(DB_HOST,DB_USER,DB_PASS)); - $resProfl = $profilGw->getProfilById($row['offreur']); - - $alumni = new Alumni($resal[0]['mail'],$resal[0]['mdp'],$resal[0]['role'],$resProfl[0]['nom'],$resProfl[0]["prenom"]); - - $date = \DateTime::createFromFormat('Y-m-d', $row['date']); - - $offers[]=new Offre( - $row['id'], - $alumni, - $row['titre'], - $row['description'], - $row["image"], - $row["logo"], - $row['typeContrat'], - $row['ville'], - $row["entreprise"], - $row['descriptifPoste'], - $row['profil'], - $row['experience'], - $row['niveauEtudes'], - $row['mailContact'], - $row['numero'], - $row['websiteURL'], - $row['remote'], - $date); - } - - - return $offers; - } - - public function getOfferLimit($start, $nbOffers): array - { - $res = $this->offreGw->getOfferLimit($start, $nbOffers); - return $this->CreateOffersFromGw($res); - } - - public function getNbOffers() : int - { - return $this->offreGw->getNbOffers(); - } - - - - public function getOffersWithFilters($params) : array - { - return $this->offreGw->getOffersWithFilters($params); - } - -} \ No newline at end of file From 7d5ece153270de54635e42c5094b75c4461b5e36 Mon Sep 17 00:00:00 2001 From: Baltazouu Date: Sat, 18 Nov 2023 17:59:09 +0100 Subject: [PATCH 03/10] debut altorouter --- php/.htaccess | 10 +- php/index.php | 1 + php/public/css/connexion.css | 2 +- php/public/css/offres.css | 9 ++ php/src/config/Validation.php | 4 +- php/src/controleur/FrontControleur.php | 135 +++++++++---------- php/src/controleur/MembreControleur.php | 26 +--- php/src/controleur/UtilisateurControleur.php | 122 +++++------------ php/src/gateway/AlumniGateway.php | 2 +- php/src/gateway/ImageSaver.php | 2 +- php/src/metier/Offre.php | 30 ++--- php/src/modele/MembreModele.php | 52 +++++++ php/src/modele/UtilisateurModele.php | 86 +++++++++++- php/templates/OffersList.html | 22 +-- php/templates/Offre.html | 10 -- php/templates/OffreDetailTest.html | 4 +- php/templates/accueil.html | 7 +- php/templates/connection.html | 10 +- php/templates/creerOffre.html | 2 +- php/templates/erreur.html | 4 +- php/templates/evenement.html | 2 +- php/templates/inscription.html | 8 +- php/templates/inscription_success.html | 4 +- php/templates/menu.html | 14 +- php/templates/offreDetail.html | 52 ------- 25 files changed, 316 insertions(+), 304 deletions(-) delete mode 100644 php/templates/Offre.html delete mode 100644 php/templates/offreDetail.html diff --git a/php/.htaccess b/php/.htaccess index 7ded04e..9837fc7 100644 --- a/php/.htaccess +++ b/php/.htaccess @@ -1,3 +1,11 @@ +#RewriteEngine On +# +#RewriteCond %{REQUEST_FILENAME} !-f +#RewriteCond %{REQUEST_FILENAME} !-d +#RewriteRule ^(.*)$ index.php/$1 [L] + + RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f -RewriteRule . index.php [L] \ No newline at end of file +RewriteRule . index.php [L] + diff --git a/php/index.php b/php/index.php index 8252479..5f9c18a 100755 --- a/php/index.php +++ b/php/index.php @@ -5,6 +5,7 @@ require_once __DIR__ . '/src/config/config.php'; require __DIR__ . '/vendor/autoload.php'; + /** Configuration twig */ $loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/templates'); $twig = new \Twig\Environment($loader, [ diff --git a/php/public/css/connexion.css b/php/public/css/connexion.css index 4c14d1d..77eb512 100755 --- a/php/public/css/connexion.css +++ b/php/public/css/connexion.css @@ -108,4 +108,4 @@ form{ color: #000; letter-spacing: 1px; font-size: 0.85em; -} \ No newline at end of file +} diff --git a/php/public/css/offres.css b/php/public/css/offres.css index de4ce90..01fa053 100644 --- a/php/public/css/offres.css +++ b/php/public/css/offres.css @@ -49,3 +49,12 @@ .row3 img { align-self: flex-start; } + +a{ + text-decoration: none; +} + +.current{ + + border-bottom: 1px solid black; +} diff --git a/php/src/config/Validation.php b/php/src/config/Validation.php index 4960b2a..ea17283 100755 --- a/php/src/config/Validation.php +++ b/php/src/config/Validation.php @@ -144,13 +144,13 @@ class Validation } - public function isAdmin() + public function isAdmin() : ?Alumni { if(isset($_SESSION['login']) && isset($_SESSION['role'])) { $login = self::nettoyerString($_SESSION['login']); $role = self::nettoyerString($_SESSION['role']); - return new Alumni() + return $_SESSION["utilisateur"]; } return null; } diff --git a/php/src/controleur/FrontControleur.php b/php/src/controleur/FrontControleur.php index e951b89..690eddc 100755 --- a/php/src/controleur/FrontControleur.php +++ b/php/src/controleur/FrontControleur.php @@ -1,112 +1,103 @@ setBasePath('/php'); + $router->setBasePath('/SAE_2A_FA-Reseau_ALICA/php'); - $router->map('GET','/','UtilisateurControleur'); + $router->map('GET', '/', 'UtilisateurControleur'); - $router->map('GET|POST','/user/[i:id]/[a:action]?','MembreControleur'); + $router->map('GET','/[a:action]?','UtilisateurControleur'); - $router->map('GET|POST','/admin/[i:id]/[a:action]?','AdminControleur'); + $router->map('POST','/[a:action]?','UtilisateurControleur'); - $id = 0; + $router->map('GET', '/[a:action]?', 'UtilisateurControleur'); + $router->map('GET|POST', '/user/[i:id]/[a:action]?', 'MembreControleur'); + + $router->map('GET|POST', '/admin/[i:id]/[a:action]?', 'AdminControleur'); + + $id = 0; $match = $router->match(); + $action = array(); - $id=array(); + $id = array(); + + $twig->render("accueil.html",[]); - if(!$match) - { + if (!$match) { + + $dVueErreur[] = "Error 404 Page not found"; global $twig; - $dVueErreur[] = "Error 404 Page not found"; echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]); } - if($match) - { + if ($match) { + $controller = $match['target'] ?? NULL; - $action = $match['params']['actions'] ?? NULL; + $action = $match['params']['action'] ?? NULL; $id = $match['params']['id'] ?? NULL; - } + try { + if ($controller == "MembreControleur") { + if ($_SESSION["utilisateur"] != NULL) { + echo 'not implemented'; + return; + } + } - try{ - $controller = new $controller; - } - catch (Error $error) - { - $dVueErreur = ['Erreur : Action inconnue']; - $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); - } + if ($controller == "AdminControleur") { + $Alumni = $_SESSION["utilisateur"]; + if ($Alumni->getRole() != "Admin") { + $dVueErreur = ["Erreur : Vous n'avez pas les privileges pour cette action"]; - } + global $twig; + echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); + return; + } + } else { + $namespace = 'App\\Controleur\\'; + $controller = $namespace . $controller; + $controller = new $controller(); + } + if (is_callable(array($controller, $action))) { + call_user_func(array($controller, $action), $match['params']); + } else { + $dVueErreur = ['Erreur : Action inconnue']; + + echo $twig->render('accueil.html', ['dVueErreur' => $dVueErreur]); + } + + } catch (Error $error) { + $dVueErreur = ['Erreur : Action inconnue']; -} -/*class FrontControleur -{ - public function __construct() - { - global $twig; - session_start(); - $dVueErreur = []; - $actions = array( - "Admin" => [ - "supprimerCompte", "consulterSignalement","supprimerOffre" - ], - "Moderateur" => [ - //TODO - ], - "Membre" => [ - "deconnexion","proposerOffre","consulterProfil","modifierProfil","signaler", - ], - "Utilisateur" => [ - - "connexion", "inscription", "accueil", "consulterProfilLimite", "publierOffre", "listerEvenement", "creerEvenement", "supprimerEvenement", "avoirDetailEvenement", "rechercherEvenement" - ] - ); - - $action = \App\config\Validation::nettoyerString($_GET["action"] ?? ""); - if(in_array($action,$actions['Admin'])) { - if (!isset($_SESSION["role"]) || $_SESSION["role"]!="admin") { - $dVueErreur[] = 'Veuillez vous connecter'; - echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); - } else{ - new AdminControleur(); - } - } - else if(in_array($action,$actions['Moderateur'])) { - if (!isset($_SESSION["role"]) || ($_SESSION["role"]!="moderateur" && $_SESSION["role"]!="admin")) { - $dVueErreur[] = 'Veuillez vous connecter'; - echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); - } else{ - new ModerateurControleur(); - } - } - else if(in_array($action,$actions['Membre'])) { - if (!isset($_SESSION["utilisateur"])) { - $dVueErreur[] = 'Veuillez vous connecter'; echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); - } else{ - new MembreControleur(); } - }else{ - new UtilisateurControleur(); } } -}*/ + +} diff --git a/php/src/controleur/MembreControleur.php b/php/src/controleur/MembreControleur.php index 151c410..715c419 100755 --- a/php/src/controleur/MembreControleur.php +++ b/php/src/controleur/MembreControleur.php @@ -5,36 +5,12 @@ class MembreControleur extends UtilisateurControleur { public function __construct() { - global $twig; - if (!isset($_REQUEST["action"])) { - $action = NULL; - } else { - $action = \App\config\Validation::nettoyerString($_REQUEST["action"]); - } - switch ($action) { - case "deconnexion": - $this->deconnexion(); - break; - case "proposerOffre": - $this->proposerOffre(); - break; - case "consulterProfil": - $this->consulterProfil(); - break; - case "modifierProfil": - $this->modifierProfil(); - break; - case "signaler": - $this->signaler(); - break; - default: - parent::__construct(); - } } protected function deconnexion() { session_destroy(); + echo "on est passes ici"; header('Location: index.php?action=accueil'); exit(); } diff --git a/php/src/controleur/UtilisateurControleur.php b/php/src/controleur/UtilisateurControleur.php index 42f3231..8f90a5d 100755 --- a/php/src/controleur/UtilisateurControleur.php +++ b/php/src/controleur/UtilisateurControleur.php @@ -5,7 +5,7 @@ namespace App\controleur; use App\config\Validation; use App\gateway\ImageSaver; use App\metier\Alumni; -use App\modele\OffreModele; +use App\modele\MembreModele; use App\modele\UtilisateurModele; class UtilisateurControleur @@ -13,63 +13,9 @@ class UtilisateurControleur public function __construct() { - global $twig; - if (!isset($_REQUEST["action"])) { - $action = NULL; - } else { - $action = Validation::nettoyerString($_REQUEST["action"]); - } - switch ($action) { - case NULL: - case "accueil": - $this->accueil(); - break; - case "inscription_success": - $this->inscription_success(); - break; - case "connection": - $this->connection(); - break; - case "inscription": - $this->inscription(); - break; - case "consultOffers": - $this->consultOffers(); - break; - case "consulterProfilLimite": - $this->consulterProfilLimite(); - break; - case "createOffer": - $this->createOffer(); - break; - case "createOfferForm": - $this->createOfferForm(); - break; - case "displayOffer": - $this->displayOffer(); - break; - case "listerEvenement": - $this->listerEvenement(); - break; - case "creerEvenement": - $this->creerEvenement(); - break; - case "supprimerEvenement": - $this->supprimerEvenement(); - break; - case "avoirDetailEvenement": - $this->avoirDetailEvenement(); - break; - case "rechercherEvenement": - $this->rechercherEvenement(); - break; - default: - $dVueErreur[] = "Action inconnue ou non autorisée"; - echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]); - } } - protected function connection() + public function connection() { global $twig; $dVueErreur = []; // Tableau pour stocker les erreurs, le cas échéant @@ -81,7 +27,7 @@ class UtilisateurControleur $utilisateur = $userModel->connection($email, $motDePasse); if ($utilisateur instanceof Alumni) { $_SESSION['utilisateur'] = $utilisateur; - header('Location: index.php?action=accueil'); + $this->accueil(); exit(); } else { $dVueErreur[] = "L'adresse email ou le mot de passe est incorrect."; @@ -90,7 +36,7 @@ class UtilisateurControleur echo $twig->render('connection.html', ['dVueErreur' => $dVueErreur]); } - protected function inscription() + public function inscription() { global $twig; $dVueErreur = []; // Tableau pour stocker les erreurs, le cas échéant @@ -124,13 +70,17 @@ class UtilisateurControleur echo $twig->render('inscription.html', ['dVueErreur' => $dVueErreur]); } - protected function accueil() + public function accueil() { + var_dump($_SESSION['utilisateur']); global $twig; // Ajout d'un var_dump pour déboguer if (isset($_SESSION['utilisateur']) && $_SESSION['utilisateur'] instanceof Alumni) { $prenom = $_SESSION['utilisateur']->getPrenom(); $nom = $_SESSION['utilisateur']->getNom(); +// $id = $_SESSION['utilisateur']->get + echo $twig->render('/user/accueil.html', ['prenom' => $prenom, 'nom' => $nom]); + } else{ $prenom = null; @@ -140,19 +90,14 @@ class UtilisateurControleur echo $twig->render('accueil.html', ['prenom' => $prenom, 'nom' => $nom]); } - protected function inscription_success() - { - global $twig; - echo $twig->render('inscription_success.html'); - } - protected function consulterProfilLimite() + public function consulterProfilLimite() { //TODO } - protected function consultOffers() + public function consultOffers() { - $offerMdl = new OffreModele(); + $userMdl = new UtilisateurModele(); global $twig; $niveauEtudes=null; @@ -174,14 +119,14 @@ class UtilisateurControleur } if ($niveauEtudes == null && $typeContrat == null && $exp == null) { - $totalOffers = $offerMdl->getNbOffers(); + $totalOffers = $userMdl->getNbOffers(); } else { $params = array( 'typeContrat' => $typeContrat, 'exp' => $exp, 'niveauEtudes' => $niveauEtudes, ); - $offers = $offerMdl->getOffersWithFilters($params); + $offers = $userMdl->getOffersWithFilters($params); $totalOffers = count($offers); } @@ -189,8 +134,8 @@ class UtilisateurControleur if($numberPages == 0 ) { - - echo $twig->render("erreur.html",['dVueErreur' => ['Aucune Offre Trouvée']]); + $msg = 'Aucune Offre Trouvée'; + echo $twig->render("OffersList.html",['message' => $msg]); return; } @@ -198,7 +143,7 @@ class UtilisateurControleur $page = intval($_GET["page"]); if ($page > $numberPages || $page < 1) { $dVueErreur[] = "Page introuvable"; - echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]); + echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur ]); return; } } else { @@ -208,11 +153,11 @@ class UtilisateurControleur $start = intval(($page - 1) * 5); if ($niveauEtudes == null && $typeContrat == null && $exp == null) { - $offers = $offerMdl->getOfferLimit($start, $nbOffers); + $offers = $userMdl->getOfferLimit($start, $nbOffers); } else { $params['start'] = $start; $params['nbOffers'] = 5; - $offers = $offerMdl->getOffersWithFilters($params); + $offers = $userMdl->getOffersWithFilters($params); } /* echo "filtre :".$niveauEtudes."
"; @@ -232,13 +177,13 @@ class UtilisateurControleur ]); } - protected function createOfferForm() + public function createOfferForm() { global $twig; echo $twig->render("CreerOffre.html", []); } - protected function createOffer() + public function createOffer() { global $twig; $taberror = []; @@ -291,10 +236,10 @@ class UtilisateurControleur $saveImg1 = ImageSaver::SaveImage("image"); $saveImg2 = ImageSaver::SaveImage("logo"); if($saveImg1[0] && $saveImg2[0]) { - $offreMdl = new OffreModele(); + $mbrModel = new MembreModele(); - $offre = $offreMdl->publishOffer($saveImg1[1], $saveImg2[1]); + $offre = $mbrModel->publishOffer($saveImg1[1], $saveImg2[1]); echo $twig->render("OffreDetailTest.html", ['offre' => $offre]); } @@ -312,8 +257,8 @@ class UtilisateurControleur if (isset($_GET["id"]) && intval($_GET["id"]) != null) { - $offreMdl = new OffreModele(); - $offre = $offreMdl->getOfferFromId(intval($_GET["id"])); + $uttilsMdl = new UtilisateurModele(); + $offre = $uttilsMdl->getOfferFromId(intval($_GET["id"])); if($offre != NULL) { echo $twig->render("OffreDetailTest.html",['offre' => $offre]); @@ -324,7 +269,7 @@ class UtilisateurControleur echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]); } - protected function listerEvenement() + public function listerEvenement() { $mdl = new UtilisateurModele(); $evenements = $mdl->getEvenement(); @@ -333,7 +278,7 @@ class UtilisateurControleur echo $twig->render('evenement.html', ['evenements' => $evenements]); } - protected function creerEvenement() + public function creerEvenement() { global $twig; @@ -354,7 +299,7 @@ class UtilisateurControleur } } - protected function supprimerEvenement() + public function supprimerEvenement() { $mdl = new UtilisateurModele(); $mdl->deleteEvenement($_GET["id"]); @@ -362,7 +307,7 @@ class UtilisateurControleur $this->listerEvenement(); } - protected function avoirDetailEvenement() + public function avoirDetailEvenement() { $mdl = new UtilisateurModele(); $evenement = $mdl->getEvenementById($_GET["id"]); @@ -371,13 +316,12 @@ class UtilisateurControleur echo $twig->render('detailEvenement.html', ['evenement' => $evenement]); } - protected function rechercherEvenement() + public function rechercherEvenement() { $mdl = new UtilisateurModele(); $evenements = $mdl->getEvenement(); - if(isset($_POST["recherche"]) AND !empty($_POST["recherche"])) - { + if (isset($_POST["recherche"]) and !empty($_POST["recherche"])) { $recherche = Validation::nettoyerString($_POST["recherche"]); $evenements = $mdl->getEvenementByTitre($recherche); } @@ -385,4 +329,8 @@ class UtilisateurControleur global $twig; echo $twig->render('evenement.html', ['evenements' => $evenements]); } + + + + } \ No newline at end of file diff --git a/php/src/gateway/AlumniGateway.php b/php/src/gateway/AlumniGateway.php index 5e19480..761011c 100644 --- a/php/src/gateway/AlumniGateway.php +++ b/php/src/gateway/AlumniGateway.php @@ -44,7 +44,7 @@ class AlumniGateway } public function findByEmail(string $email){ - $query = 'SELECT Alumni.mail, Alumni.mdp, Alumni.role, Profil.nom, Profil.prenom + $query = 'SELECT Alumni.mail, Alumni.mdp, Alumni.role, Profil.nom, Profil.prenom ,Alumni.id FROM Alumni LEFT JOIN Profil ON Alumni.id = Profil.alumni WHERE Alumni.mail = :e'; diff --git a/php/src/gateway/ImageSaver.php b/php/src/gateway/ImageSaver.php index a6d189d..5897413 100644 --- a/php/src/gateway/ImageSaver.php +++ b/php/src/gateway/ImageSaver.php @@ -17,7 +17,7 @@ class ImageSaver $name = substr($_FILES[$filename]["name"], 0, 45); $name = self::getId().$name; - move_uploaded_file($_FILES[$filename]['tmp_name'], "../public/uploads/$name"); + move_uploaded_file($_FILES[$filename]['tmp_name'], "public/uploads/$name"); $return[]=true; $return[]=$name; return $return; diff --git a/php/src/metier/Offre.php b/php/src/metier/Offre.php index bd9b494..2264363 100755 --- a/php/src/metier/Offre.php +++ b/php/src/metier/Offre.php @@ -10,21 +10,21 @@ class TypeContrat { const Alternance = "Alternance"; const Stage = "Stage"; } - -enum ProfilRecherche : string -{ - case Junior = "Junior"; - case Senior = "Senior"; - case Indifferent = "Indifferent"; -} - -enum NiveauEtudes: string -{ - case Bac2 = "Bac+2"; - case Bac3 = "Bac+3"; - case Bac5 = "Bac+5"; - case Indifferent = "Indifferent"; -} +// +//enum ProfilRecherche : string +//{ +// case Junior = "Junior"; +// case Senior = "Senior"; +// case Indifferent = "Indifferent"; +//} +// +//enum NiveauEtudes: string +//{ +// case Bac2 = "Bac+2"; +// case Bac3 = "Bac+3"; +// case Bac5 = "Bac+5"; +// case Indifferent = "Indifferent"; +//} class Offre { diff --git a/php/src/modele/MembreModele.php b/php/src/modele/MembreModele.php index 2a8c65c..97231c7 100755 --- a/php/src/modele/MembreModele.php +++ b/php/src/modele/MembreModele.php @@ -2,6 +2,9 @@ namespace App\modele; +use App\metier\Alumni; +use App\metier\Offre; + class MembreModele extends UtilisateurModele { @@ -65,4 +68,53 @@ class MembreModele extends UtilisateurModele + public function publishOffer(string $img, string $logo) + { + $desc = $_POST["description"]; + $descposte = $_POST["descriptPoste"]; + $nom = $_POST["name"]; + $ville = $_POST["ville"]; + $entreprise = $_POST["entreprise"]; + $profilRecherche = $_POST["profilRecherche"]; + $mail = $_POST["mail"]; + $num = $_POST["num"]; + $site = $_POST["site"]; + $exp = $_POST["choixExp"]; + $typeContrat = $_POST["typeContrat"]; + $niveauEtudes = $_POST["education"]; + $date = new \DateTime(); + + if(isset($_POST["fullRemote"])) + { + $remote = true; + } + else $remote = false; + + // à la place de NULL passer id utilisateur créateur offre + $offre = new Offre($this->offreGw->getNewId(), + new Alumni("test.mail@icloud.fr","password","admin","prenom","nom"), + $nom, + $desc, + $img, + $logo, + $typeContrat, + $ville, + $entreprise, + $descposte, + $profilRecherche, + $exp, + $niveauEtudes, + $mail, + $num, + $site, + $remote, + $date); + + $this->offreGw->addOffers($offre); + + return $offre; + + } + + } \ No newline at end of file diff --git a/php/src/modele/UtilisateurModele.php b/php/src/modele/UtilisateurModele.php index bdea578..a6c6afc 100755 --- a/php/src/modele/UtilisateurModele.php +++ b/php/src/modele/UtilisateurModele.php @@ -3,19 +3,24 @@ namespace App\modele; use App\gateway\Connection; use App\gateway\EvenementGateway; +use App\gateway\OffreGateway; use App\metier\Evenement; use App\metier\Alumni; use App\gateway\AlumniGateway; use App\gateway\ProfilGateway; +use App\metier\Offre; class UtilisateurModele { private $con; + protected $offreGw; + public function __construct() { $this->con = new Connection(DB_HOST,DB_USER,DB_PASS); + $this->offreGw = new OffreGateway($this->con); } /** @@ -35,7 +40,7 @@ class UtilisateurModele // L'utilisateur existe, vérifiez le mot de passe if (password_verify($mdp, $utilisateur->getPassword())) { // Le mot de passe est correct, retournez l'utilisateur - session_start(); + //session_start(); return $utilisateur; } else { // Le mot de passe est incorrect, renvoyez null @@ -179,4 +184,83 @@ class UtilisateurModele return $evenement; } + + + public function getOfferFromId(int $id) : ?Offre + { + $res = $this->offreGw->getOfferFromId($id); + if($res != null) + return $this->CreateOffersFromGw($res)[0]; + return null; + } + + + + + public function CreateOffersFromGw($res) : array + { + $alGw = new AlumniGateway(new Connection(DB_HOST,DB_USER,DB_PASS)); + + $offers=[]; + foreach ($res as $row) + { + $resal = $alGw->ObtenirById($row['offreur']); + $profilGw = new ProfilGateway(new Connection(DB_HOST,DB_USER,DB_PASS)); + $resProfl = $profilGw->getProfilById($row['offreur']); + + $alumni = new Alumni($resal[0]['mail'],$resal[0]['mdp'],$resal[0]['role'],$resProfl[0]['nom'],$resProfl[0]["prenom"]); + + $date = \DateTime::createFromFormat('Y-m-d', $row['date']); + + $offers[]=new Offre( + $row['id'], + $alumni, + $row['titre'], + $row['description'], + $row["image"], + $row["logo"], + $row['typeContrat'], + $row['ville'], + $row["entreprise"], + $row['descriptifPoste'], + $row['profil'], + $row['experience'], + $row['niveauEtudes'], + $row['mailContact'], + $row['numero'], + $row['websiteURL'], + $row['remote'], + $date); + } + + + return $offers; + } + + public function getOfferLimit($start, $nbOffers): array + { + $res = $this->offreGw->getOfferLimit($start, $nbOffers); + return $this->CreateOffersFromGw($res); + } + + public function getNbOffers() : int + { + return $this->offreGw->getNbOffers(); + } + + + + public function getOffersWithFilters($params) : array + { + return $this->offreGw->getOffersWithFilters($params); + } + + public function getOffers() : array + { + $res = $this->offreGw->getOffers(); + $offers = $this->CreateOffersFromGw($res); + return $offers; + } + + } \ No newline at end of file diff --git a/php/templates/OffersList.html b/php/templates/OffersList.html index c86f465..475c267 100644 --- a/php/templates/OffersList.html +++ b/php/templates/OffersList.html @@ -5,7 +5,7 @@ Alica - Offres - +
@@ -14,13 +14,13 @@
-
+

Filtrer les offres

@@ -79,7 +79,7 @@
@@ -87,13 +87,16 @@

Offres d'emploi

+{% if message is defined %} +

{{ message }}

+{% endif %}
{% for offre in offres %}
- logo + logo

{{ offre.getNom() }}

@@ -102,12 +105,11 @@
- location + location

{{offre.getVille()}}

+ onclick="window.location.href = 'displayOffer&id={{offre.getId()}}'">En savoir plus
{% endfor %} @@ -121,9 +123,9 @@ - {{ i }} + {{ i }} {% else %} - {{ i }} + {{ i }} {% endif %} {% endfor %} {% endif %} diff --git a/php/templates/Offre.html b/php/templates/Offre.html deleted file mode 100644 index 7211ce4..0000000 --- a/php/templates/Offre.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Offre {{ offre.getNom() }} - - - - - \ No newline at end of file diff --git a/php/templates/OffreDetailTest.html b/php/templates/OffreDetailTest.html index e404b79..852841c 100644 --- a/php/templates/OffreDetailTest.html +++ b/php/templates/OffreDetailTest.html @@ -17,8 +17,8 @@
    -
  • Logo -
  • Offer Image
  • +
  • Logo +
  • Offer Image
  • Offreur: {{ offre.getOffreur().getNom() }}
  • Nom de l'offre: {{ offre.getNom() }}
  • diff --git a/php/templates/accueil.html b/php/templates/accueil.html index b6118c7..d6a5ab9 100755 --- a/php/templates/accueil.html +++ b/php/templates/accueil.html @@ -3,15 +3,18 @@ - + Alica - Accueil +
    {% include 'menu.html' %}
    + +

    Accueil

    {% if prenom and nom %} @@ -33,6 +36,8 @@

{% endif %} +
+ diff --git a/php/templates/connection.html b/php/templates/connection.html index 872f803..0b8a3fb 100755 --- a/php/templates/connection.html +++ b/php/templates/connection.html @@ -4,11 +4,13 @@ Alica - Connexion - + + +
- +

Connexion

Identifiant @@ -37,9 +39,7 @@
-
- -
+ S'inscrire
{% if dVueErreur is not empty %} diff --git a/php/templates/creerOffre.html b/php/templates/creerOffre.html index 8a1e867..54d0710 100644 --- a/php/templates/creerOffre.html +++ b/php/templates/creerOffre.html @@ -15,7 +15,7 @@

Publier Une Offre

-
+ {% if tabError is defined %} {% for error in tabError %} diff --git a/php/templates/erreur.html b/php/templates/erreur.html index 5b78019..332d820 100755 --- a/php/templates/erreur.html +++ b/php/templates/erreur.html @@ -3,7 +3,7 @@ - + Alica - Erreur @@ -21,7 +21,7 @@

{{value}}

{% endfor %} {% endif %} - +
diff --git a/php/templates/evenement.html b/php/templates/evenement.html index 3e68ce5..47eb0de 100644 --- a/php/templates/evenement.html +++ b/php/templates/evenement.html @@ -5,7 +5,7 @@ Liste des Événements - + diff --git a/php/templates/inscription.html b/php/templates/inscription.html index 456c0f2..64cabea 100755 --- a/php/templates/inscription.html +++ b/php/templates/inscription.html @@ -4,11 +4,11 @@ Alica - Inscription - +
-
+

S'inscrire

Prénom : @@ -62,9 +62,7 @@
-
- -
+ Se Connecter
{% if dVueErreur is not empty %} diff --git a/php/templates/inscription_success.html b/php/templates/inscription_success.html index 2843e6c..8f9995d 100644 --- a/php/templates/inscription_success.html +++ b/php/templates/inscription_success.html @@ -3,7 +3,7 @@ Success - +

Inscription effectuée avec succès, vous pouvez désormais vous connecter

@@ -15,7 +15,7 @@
diff --git a/php/templates/menu.html b/php/templates/menu.html index 3e29b53..4e3339a 100644 --- a/php/templates/menu.html +++ b/php/templates/menu.html @@ -1,13 +1,13 @@ - +