Modification altorouteur, tout ne fonctiontionne dans une autre branche

correction_routeur
Renaud BEURET 1 year ago
parent b73e92d0b6
commit b9e30eed17

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 107 KiB

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Before

Width:  |  Height:  |  Size: 159 KiB

After

Width:  |  Height:  |  Size: 159 KiB

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

@ -2,7 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Neutral.iml" filepath="$PROJECT_DIR$/.idea/Neutral.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/src.iml" filepath="$PROJECT_DIR$/.idea/src.iml" />
</modules>
</component>
</project>

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpIncludePathManager">
<include_path>
<path value="$PROJECT_DIR$/vendor/twig/twig" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
<path value="$PROJECT_DIR$/vendor/composer" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
<path value="$PROJECT_DIR$/vendor/altorouter/altorouter" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.4">
<option name="suggestChangeDefaultLanguageLevel" value="false" />
</component>
</project>

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/config" isTestSource="false" packagePrefix="config\" />
<sourceFolder url="file://$MODULE_DIR$/controller" isTestSource="false" packagePrefix="controller\" />
<sourceFolder url="file://$MODULE_DIR$/model" isTestSource="false" packagePrefix="model\" />
<sourceFolder url="file://$MODULE_DIR$/model/gateways" isTestSource="false" packagePrefix="model\" />
<sourceFolder url="file://$MODULE_DIR$/model/metier" isTestSource="false" packagePrefix="model\" />
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/vendor/twig/twig" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" />
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
<excludeFolder url="file://$MODULE_DIR$/vendor/altorouter/altorouter" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

@ -8,6 +8,7 @@
},
"require": {
"altorouter/altorouter": "^2.0",
"twig/twig": "^3.7"
"twig/twig": "^3.7",
"ext-pdo": "*"
}
}

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6539a3b2ab32d0f1df8933f4838b0c34",
"content-hash": "1dace5e05aa6a83586228ea227d11d71",
"packages": [
{
"name": "altorouter/altorouter",
@ -309,7 +309,9 @@
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform": {
"ext-pdo": "*"
},
"platform-dev": [],
"plugin-api-version": "2.6.0"
}

@ -11,10 +11,9 @@ $rep=__DIR__.'/../';
//BD
$dsn="sasa";
$login="";
$mdp="";
$base = 'mysql:host=londres.uca.local;dbname=dbrebeuret';
$login = 'rebeuret';
$mdp = 'achanger';
//Vues
$vues['index']='vues/index.php';

@ -2,7 +2,9 @@
namespace controller;
use config\Validation;
use http\Params;
use model\Connection;
use model\ModelAdmin;
use model\UserGateway;
class FrontController
@ -10,14 +12,23 @@ class FrontController
public function __construct()
{
global $twig, $router;
$con = new Connection("mysql:host=mysql;dbname=iut", "aljeudilem", "22061337");
$router->map('GET|POST', '/', 'null');
$router->map('GET|POST', '/join', 'join');
$router->map('GET|POST', '/create', 'create');
$router->map('GET|POST', '/login', 'login');
$router->map('GET|POST', '/admin/[a:action]?', 'admin');
global $login;
global $mdp;
global $base;
$con = new Connection($base, $login, $mdp);
//altorouter
$router = new \AltoRouter();
$router->setBasePath('~rebeuret/ScienceQuest/Project/src/');
$router->map('GET|POST','/[a:action]?','UserController');
$router->map('GET|POST','/admin/[a:action]','AdminController');
// $router->map('GET|POST', '/', 'null');
// $router->map('GET|POST', '/join', 'join');
// $router->map('GET|POST', '/create', 'create');
// $router->map('GET|POST', '/login', 'login');
// $router->map('GET|POST', '/admin/[a:action]?', 'admin');
$router->map('GET|POST', '/validationFormulaire', 'validationFormulaire');
$router->map('GET|POST', '/logout', 'disconnect');
@ -33,52 +44,29 @@ class FrontController
try {
$match = $router->match();
if (!$match) {
throw new \Exception('Wrong call');
}
$action=$match['params']['action'] ?? "";
switch($match['target']) {
case 'null':
echo $twig->render('accueil.html', ['dVue' => $dVue]);
case 'UserController':
$this->callController('UserController',$match);
break;
case 'join':
echo $twig->render('join.html');
break;
case 'create':
$this->CreateParty();
case 'AdminController':
$action = $match['params']['action'];
if (!ModelAdmin::isAdmin()) {
$action = 'login';
}
$this->callController('AdminController',$action);
break;
case 'validationFormulaire':
$this->ValidationFormulaire($dVueErreur, $dVue);
break;
case 'admin':
new AdminController($action);
break;
case 'login':
if(empty($_SESSION) && !isset($_REQUEST['login']))
echo $twig->render('login.html');
elseif(isset($_REQUEST['login'])) {
Validation::valUserLogin($_REQUEST['login'], $dVueErreur);
$ug = new UserGateway($con);
if($ug->login($_REQUEST['login'], $_REQUEST['password'])) {
$_SESSION['pseudo'] = $_REQUEST['login'];
header("Location: .");
} else {
$dVueErreur[] = "Connexion échouée";
throw new LoginException("Connexion err");
}
} else
header("Location: .");
break;
case 'disconnect':
session_unset();
session_destroy();
$_SESSION = array();
header("Location: .");
break;
//mauvaise action
default:
$dVueErreur[] = "Erreur d'appel php";
echo $twig->render('accueil.html', ['dVueErreur' => $dVueErreur]);
@ -98,12 +86,18 @@ class FrontController
exit(0);
}
public function CreateParty() : void
{
private function callController(string $cont, array $match) {
global $twig;
$dVueCreate = \model\GameGateway::getGames();
echo $twig->render('create.html', ['dVueCreate' => $dVueCreate]);
$controller = '\\controller\\'.$cont;
$controller = new $controller;
$action = $match['params']['action'] ?? 'accueil';
if (is_callable(array($controller,$action))) {
call_user_func_array(array($controller,$action),array($match['params']));
} else {
echo $twig->render('erreur.html', ['dVueErreur' => array('Page inconnue')]);
}
}
public function ValidationFormulaire(array &$dVueErreur, array &$dVue)

@ -0,0 +1,41 @@
<?php
namespace controller;
use model\Connection;
use model\GameGateway;
class UserController {
public function CreateParty() {
global $twig;
$dVueCreate = \model\GameGateway::getGames();
echo $twig->render('create.html', ['dVueCreate' => $dVueCreate]);
}
public function JoinParty() {
global $twig;
global $base;
global $login;
global $mdp;
$con = new Connection($base, $login, $mdp);
$gg = new GameGateway($con);
if(!isset($_REQUEST['code'])) {
echo $twig->render('join.html');
} elseif (empty($_REQUEST['code']) || !sizeof($gg->getGameByCode($_REQUEST['code']))) {
$dErreur[] = 'Code de partie invalide';
echo $twig->render('join.html',['dErreur' => $dErreur]);
} else {
// rejoindre la partie
}
}
public function accueil(array $params) {
global $twig;
global $dVue;
echo $twig->render('accueil.html',['dVue' => $dVue]);
}
}

@ -11,11 +11,6 @@
'cache' => false,
]);
//altorouter
$router = new AltoRouter();
$router->setBasePath('/public_html/ScienceQuest');
$cont = new FrontController();

@ -0,0 +1,25 @@
<?php
namespace model;
class ModelAdmin {
public static function isAdmin() {
if(!isset($_SESSION['admin'])
|| !$_SESSION['admin']
|| !isset($_SESSION['email'])
|| $_SESSION['email'] == null) {
return false;
}
return true;
}
public static function logout() {
global $basePath;
session_unset();
session_destroy();
$_SESSION = array();
header("Location: .");
}
}

@ -4,6 +4,11 @@ namespace model;
class GameGateway
{
private $con;
function __construct(Connection $co) {
$this->con = $co;
}
public static function getGames() : array
{
// TODO: implémenter requête SQL
@ -12,4 +17,12 @@ class GameGateway
1 => ["Kahoot", "Le Kahoot permet..."]
);
}
public function getGameByCode(int $code) : array {
$query = 'SELECT * FROM Partie WHERE codeInvitation=:id';
$this->con->executeQuery($query,array(
':id' => array($code,\PDO::PARAM_INT)
));
return $this->con->getResults();
}
}

@ -26,8 +26,8 @@
<br><br><br><br>
<center>
<a href="join">Rejoindre une partie</a>
<a href="create">Créer une partie</a>
<a href="JoinParty">Rejoindre une partie</a>
<a href="CreateParty">Créer une partie</a>
</center>

@ -12,7 +12,7 @@
<p>Merci de vous munir de votre code de partie et de l'entrer dans le champ ci-dessous</p>
<form action="#" method="post">
<label for="partyCode">Code de la partie</label>
<input type="text" name="partyCode" id="partyCode">
<input type="text" name="code" id="partyCode">
<input type="submit" value="Valider">
</form>
</center>

@ -17,6 +17,12 @@
<input type="password" name="password" id="password">
<br><br>
<input type="submit" value="Valider">
{ % for error in dErreur % }
<br>
<p style="color: red">
{{error}}
</p>
{% endfor %}
</form>
</center>

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit6a6772df2521c6860a448e9115f2793a::getLoader();
return ComposerAutoloaderInit6539a3b2ab32d0f1df8933f4838b0c34::getLoader();

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save