diff --git a/.gitignore b/.gitignore index a5bdaf7c..a6967c98 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,6 @@ /node_modules/ -/.idea \ No newline at end of file +/.idea + +*.db \ No newline at end of file diff --git a/.vs/Scripted/v17/.suo b/.vs/Scripted/v17/.suo new file mode 100644 index 00000000..3be1f926 Binary files /dev/null and b/.vs/Scripted/v17/.suo differ diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 00000000..f524a4dc Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/EnigmePython/Multi/ASCII.py b/EnigmePython/Multi/ASCII.py new file mode 100644 index 00000000..053ed9b3 --- /dev/null +++ b/EnigmePython/Multi/ASCII.py @@ -0,0 +1 @@ +def ascii() \ No newline at end of file diff --git a/EnigmePython/Solo/premiere.py b/EnigmePython/Solo/premiere.py new file mode 100644 index 00000000..da3a2bfe --- /dev/null +++ b/EnigmePython/Solo/premiere.py @@ -0,0 +1,14 @@ +# Affiche Hello world ! + +print("Hello World !") + +# Declaration de variable + +num = 1 +string = "Oi" +liste=[num,string] + +print(liste) + + +# Utilisation de fonction \ No newline at end of file diff --git a/WEB/.htaccess b/WEB/.htaccess new file mode 100644 index 00000000..d2073e34 --- /dev/null +++ b/WEB/.htaccess @@ -0,0 +1,2 @@ +php_flag display_errors on +php_value error_reporting E_ALL \ No newline at end of file diff --git a/WEB/.user.ini b/WEB/.user.ini new file mode 100644 index 00000000..3c7ddce4 --- /dev/null +++ b/WEB/.user.ini @@ -0,0 +1,3 @@ +display_errors = On +log_errors = Off +error_reporting = E_ALL & E_NOTICE & E_DEPRECATED & E_STRICT & E_WARNING \ No newline at end of file diff --git a/WEB/Config/Autoload.php b/WEB/Config/Autoload.php index c67bf2f5..dfa0c5e3 100644 --- a/WEB/Config/Autoload.php +++ b/WEB/Config/Autoload.php @@ -34,10 +34,10 @@ class Autoload { global $rep; $filename = $class.'.php'; - $dir =array('Model/','./','Config/','Controller/'); + $dir =array('Model/','./','Config/','Controller/','Metier/', 'Factory/'); foreach ($dir as $d){ $file=$rep.$d.$filename; - //echo $file; + // echo $file."\n"; if (file_exists($file)) { include $file; diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index 78c5f776..0a73bfe1 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -1,20 +1,10 @@ open($dsn); $this->enableExceptions(true); } - public function executeQuery(string $query, array $parameters = []) :bool { - $this->stmt = parent::prepare($query); - foreach ($parameters as $name => $value) { - $this->stmt->bindValue($name, $value[0], $value[1]); - } - $this->result=$this->stmt->execute(); - return $this->result; - } - - public function getResults(): array { - return $this->result->fetchArray(); - } -} + public function executeQuery(string $query, array $parameters = []): bool + { + $this->stmt = parent::prepare($query); + foreach ($parameters as $name => $value) { + $this->stmt->bindValue($name, $value[0], $value[1]); + } + $this->result = $this->stmt->execute(); + if ($this->result == false) { + $this->result->finalize(); + return false; + } else { + $this->result->finalize(); + return true; + } + } -// class Connection extends SQLite3{ -// function __construct() -// { -// $this->open("./Model/scripted.db"); -// } -// } \ No newline at end of file + public function getResults(): array + { + $resultArray = $this->result->fetchArray(SQLITE3_ASSOC); + $multiArray = array(); + while($resultArray != false){ //read next row + $multiArray[]=$resultArray; + $resultArray = $this->result->fetchArray(SQLITE3_ASSOC); //insert all rows to $multiArray + } + if ($multiArray == NULL) + return array(); + else + return $multiArray; + } +} \ No newline at end of file diff --git a/WEB/Controller/EnigmeGateway.php b/WEB/Controller/EnigmeGateway.php index 6cf7de12..7b168d29 100644 --- a/WEB/Controller/EnigmeGateway.php +++ b/WEB/Controller/EnigmeGateway.php @@ -1,5 +1,4 @@ con = $con; + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } } /** @@ -21,6 +27,12 @@ class EnigmeGateway $this->con = $con; } + /** + * It inserts a new row in the Enigme table, with the values of the Enigme object passed as + * parameter + * + * @param Enigme enigme + */ public function insert(Enigme $enigme) { $query = "INSERT INTO Enigme VALUES (:id,:admin,:enonce,:aide,:rappel,:solution,:test,:tempsDeResolution,:points)"; @@ -37,6 +49,12 @@ class EnigmeGateway )); } + /** + * It deletes a row from the table Enigme where the idEnigme is equal to the idEnigme passed as a + * parameter + * + * @param string idEnigme the id of the enigma + */ public function delete(string $idEnigme) { $query= "DELETE FROM Enigme WHERE idEnigme=:idEnigme"; @@ -45,6 +63,45 @@ class EnigmeGateway )); } + /** + * It returns an array of Enigme objects + * For multiplayer Enigma + * + * @return array An array of Enigme objects. + */ + public function findMultiEnigma() : array + { + $query = "SELECT * FROM Enigme + WHERE points IS NOT NULL OR points != 0"; + $this->con->executeQuery($query); + $tabEnigme=EnigmeFactory::create($this->con->getResults()); + return $tabEnigme; + } + + /** + * It returns an array of Enigma objects + * For Solo enigma + * + * @return array of objects. + */ + public function findSoloEnigma(){ + $query = "SELECT * FROM Enigme + WHERE points IS NULL OR points = 0"; + $this->con->executeQuery($query); + $tabEnigme=EnigmeFactory::create($this->con->getResults()); + return $tabEnigme; + } + + public function findEnigmaFromPartie(string $idPartie){ + $query = "SELECT * FROM Enigme e, Contenir c + WHERE c.partie=:idPartie"; + $this->con->executeQuery($query, array( + 'idPartie' => array($idPartie, SQLITE3_TEXT) + )); + $tabEnigme=EnigmeFactory::create($this->con->getResults()); + return $tabEnigme; + } + public function findById(string $idEnigme) : array { $query="SELECT * FROM Enigme WHERE idEnigme =:idEnigme"; diff --git a/WEB/Controller/FrontController.php b/WEB/Controller/FrontController.php index 8870beaf..b9258da9 100644 --- a/WEB/Controller/FrontController.php +++ b/WEB/Controller/FrontController.php @@ -3,16 +3,33 @@ class FrontController { function __construct() { - global $rep, $vues, $error; - session_start(); - // $role=$_SESSION['role']; - // $action=$_REQUEST['action']; - echo "frontController"; - try { - new UserController(); + try { + global $error, $view, $rep; + session_start(); + // Check role permissions + if (isset($_SESSION['role'])) { + $role = $_SESSION['role']; + } else { + $role = "visitor"; + } + // Check if action exists + $action = $_REQUEST['action']; + if ($role == "user") { + if ($action == NULL) { + new UserController(); + } else if (method_exists('UserController', $action) == false) { + $error = "Action non valide " . $action; + require($rep . $view['erreur']); + } + else { + new UserController(); + } + } else { + new VisitorController(); + } } catch (Exception $e) { $error = $e->getMessage(); - require ($rep . $vues['erreur']); + require($rep . $view['erreur']); } } } \ No newline at end of file diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index a5622975..0e983213 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -1,6 +1,4 @@ con = $con; + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } } /** - * @param array $listeJoueur + * @param array $listeUtilisateur */ - - public function creerPartieMulti(array $listeJoueur){ - $query = "SELECT * FROM Enigme - WHERE points IS NOT NULL OR points != 0"; + public function partieInQueueExists() : bool{ + $query = "SELECT count(*) FROM PARTICIPER WHERE etat = 0"; $this->con->executeQuery($query); $results = $this->con->getResults(); - $query= "SELECT max(p.id) - FROM PARTIE p;"; + if ($results[0]['count(*)'] == 0) + return false; + else + return true; + } + + public function findPartieMaxId() : int{ + $query = "SELECT max(id) FROM Partie"; $this->con->executeQuery($query); - $max=$this->con->getResults()[0]["max"]; - $partie=PartieFactory::createPartieMulti($max,$results); - $query= "INSERT INTO Partie VALUES (:idPartie,:idEnigme)"; + $results=$this->con->getResults(); + if ($results[0]['max(id)']==NULL) + return 0; + else + return $results[0]['max(id)']; + } + public function creerPartieMulti(int $max, array $tabEnigme) : Partie{ + $partie=PartieFactory::createPartieMulti($max+1,$tabEnigme); + $query= "INSERT INTO Partie VALUES (:idPartie,CURRENT_DATE)"; $this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER))); - foreach($partie->getListeEnigme() as $Enigme){ - $query= "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)"; - $this->con->executeQuery($query, array( - ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), - ':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER))); - } - foreach($listeJoueur as $Joueur){ - $query= "INSERT INTO Participer VALUES (:idPartie, :idJoueur, TRUE)"; - $this->con->executeQuery($query, array( - ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), - ':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER))); + if (count($partie->getListeEnigme()) != 0) { + foreach ($partie->getListeEnigme() as $Enigme) { + $query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)"; + $this->con->executeQuery($query, array( + ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), + ':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER) + ) + ); + } } + return $partie; + } + + public function rejoindrePartieMulti(int $idPartieInQueue,array $tabEnigme) : Partie{ + $partie = PartieFactory::createPartieMulti($idPartieInQueue,$tabEnigme); + return $partie; + } + + public function findPartieInQueue(){ + $query = "SELECT p.id + FROM Partie p, Participer pa + WHERE pa.etat=0 + AND pa.partie=p.id"; + $this->con->executeQuery($query); + $results = $this->con->getResults(); + return $results[0]['id']; } public function creerPartieSolo(Utilisateur $utilisateur){ @@ -67,10 +96,10 @@ class PartieGateway ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), ':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER))); } - $query= "INSERT INTO Participer VALUES (:idPartie, :idJoueur, TRUE)"; + $query= "INSERT INTO Participer VALUES (:idPartie, :idUtilisateur, TRUE)"; $this->con->executeQuery($query, array( 'idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), - 'idJoueur' => array($utilisateur->getEmail(), SQLITE3_INTEGER))); + 'idUtilisateur' => array($utilisateur->getEmail(), SQLITE3_INTEGER))); } public function delete(string $idPartie){ diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index bd6b4c53..435ce0cd 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -2,179 +2,194 @@ class UserController { - private Connection $con; - - function __construct() { - try{ - echo "UserController"; + private UserModel $model; + function __construct() + { + try { global $dsn, $rep, $vues, $error; - $this->con=new Connection($dsn); - echo "USconection"; - $action=$_REQUEST['action']; - switch($action) { + $this->model = new UserModel(); + $action = $_REQUEST['action']; + //register_event_handler('add_to_queue',array($this,"onAddToQueue")); + switch ($action) { case NULL: $this->goToHome(); break; - case "signUp": - $this->signUp(); - break; - case "login": - $this->login(); - break; case "goToPresentation": $this->goToPresentation(); break; case "goToHome": $this->goToHome(); break; - case "goToLogin": - $this->goToLogin(); - break; - case "goToSignUp": - $this->goToSignUp(); + case "goToTest": + $this->goToTest(); break; case "goToEnigme": $this->goToEnigme(); break; + case "goToChouette" : + $this->goToChouette(); + break; + case "goToCesarEncrypt": + $this->goToCesarEncrypt(); + break; + case "goToCesarDecrypt": + $this->goToCesarDecrypt(); + break; + case "goToChuckNorris" : + $this->goToChuckNorris(); + break; + case "goToHanoi" : + $this->goToHanoi(); + break; + case "goToTrianglePascal": + $this->goToTrianglePascal(); + break; case "goToQueue": $this->goToQueue(); break; + case "goToNext": + $this->goToNext(); + break; + case "logout": + $this->logout(); + break; + default: + $error = "Action non valide"; + require($rep . $vues['erreur']); + break; } - } catch (PDOException $e) - { - $error = $e->getMessage(); - require ($rep.$vues['erreur']); - }catch (Exception $e) - { + } catch (PDOException $e) { $error = $e->getMessage(); - require ($rep.$vues['erreur']); + require($rep . $vues['erreur']); + } catch (Exception $e2) { + $error = $e2->getMessage(); + require($rep . $vues['erreur']); } } - - private function signUp() { - global $rep, $vues, $sel, $error; + public function goToHome() + { try { - $gateway = new UtilisateurGateway($this->con); - $validation = new Validation(); - if (! $validation->ValidateEmail($_REQUEST['email'])) { - $error = "Email invalides."; - throw (new Exception("Email non valide")); - } - if(! $validation->ValidateUsername($_REQUEST['username'])){ - $error = "Nom d'utilisateur invalides. Il ne doit pas contenir de caractère spéciaux."; - throw(new Exception("Pseudo non valide")); - } - if(! $validation->ValidatePassword($_REQUEST['password'])){ - $error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères."; - throw(new Exception("Mot de passe non valide")); - } - $j = $gateway->getUtilisateurByEmail($_REQUEST['email']); - if ($j != null) { - $error = "Email déjà utilisé."; - throw (new Exception("Email déjà utilisé")); - } - $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); - $estAdmin = $gateway->getEstAdminByEmail($_REQUEST['email']); - $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin); - $gateway->insert($Utilisateur); - $_SESSION['connected'] = 'true'; - $_SESSION['role'] = 'utilisateur'; - require ($rep.$vues['main']); - }catch (PDOException $e) - { - $error = "Erreur de connexion à la base de données."; - require ($rep.$vues['erreur']); + global $rep, $vues; + require($rep . $vues['main']); + } catch (Exception $e) { + $error = "404"; + require($rep . $vues['erreur']); } - catch (Exception $e){ - require($rep.$vues['erreur']); + } + public function goToPresentation() + { + try { + global $rep, $vues; + require($rep . $vues['presentation']); + } catch (Exception $e) { + $error = "404"; + require($rep . $vues['erreur']); } } - private function login(){ - global $rep, $vues, $sel, $error; + public function goToTest() + { try { - $gateway = new UtilisateurGateway($this->con); - $Utilisateur = $gateway->getUtilisateurByEmail($_REQUEST['email']); - if ($Utilisateur->getEmail() == null){ - $error = "Utilisateur non trouvé."; - throw new Exception("Utilisateur introuvable"); - } - $mdp = $gateway->getMdpByEmail($_REQUEST['email']); - if (password_verify($mdp, $_REQUEST['password'])){ - $error = "Mot de passe incorrect."; - throw new Exception("Mot de passe invalide"); - } - $estAdmin =$gateway->getEstAdminByEmail($_REQUEST['email']); - if ($estAdmin == true) { - $_SESSION['role'] = "admin"; - } - else{ - $_SESSION['role'] = "utilisateur"; - } - - $_SESSION['connected'] = 'true'; - require ($rep.$vues['main']); - }catch (Exception $e){ - require($rep.$vues['erreur']); + global $rep, $vues; + require($rep . $vues['test']); + } catch (Exception $e) { + $error = "404"; + require($rep . $vues['erreur']); + } + } + public function goToEnigme() + { + try { + global $rep, $vues; + require($rep . $vues['enigme']); + } catch (Exception $e) { + $error = "404"; + require($rep . $vues['erreur']); } } - - private function goToPresentation() { - global $rep, $vues, $error; + public function goToChouette() + { try { - require ($rep.$vues['presentation']); - }catch (Exception $e){ - $error = "Erreur Inconnue"; - require($rep.$vues['erreur']); + global $rep, $vues; + require($rep . $vues['chouette']); + } catch (Exception $e) { + $error = "404"; + require($rep . $vues['erreur']); } } - - private function goToHome() { - global $rep, $vues, $error; + public function goToCesarEncrypt() + { try { - require ($rep.$vues['main']); - }catch (Exception $e){ + global $rep, $vues; + require($rep . $vues['cesarEncrypt']); + } catch (Exception $e) { $error = "404"; - require($rep.$vues['erreur']); + require($rep . $vues['erreur']); } } - - private function goToLogin() { - global $rep, $vues, $error; + public function goToCesarDecrypt() + { try { - require ($rep.$vues['login']); - }catch (Exception $e){ + global $rep, $vues; + require($rep . $vues['cesarDecrypt']); + } catch (Exception $e) { $error = "404"; - require($rep.$vues['erreur']); + require($rep . $vues['erreur']); } } - - private function goToSignUp() { - global $rep, $vues, $error; + public function goToChuckNorris() + { try { - require ($rep.$vues['signUp']); - }catch (Exception $e){ + global $rep, $vues; + require($rep . $vues['chuckNorris']); + } catch (Exception $e) { $error = "404"; - require($rep.$vues['erreur']); + require($rep . $vues['erreur']); } } - - private function goToEnigme() { - global $rep, $vues, $error; + public function goToHanoi() + { try { - require ($rep.$vues['enigme']); - }catch (Exception $e){ + global $rep, $vues; + require($rep . $vues['hanoi']); + } catch (Exception $e) { $error = "404"; - require($rep.$vues['erreur']); + require($rep . $vues['erreur']); } } - - private function goToQueue() { - global $rep, $vues, $error; + public function goToTrianglePascal() + { try { - require ($rep.$vues['Queue']); - }catch (Exception $e){ + global $rep, $vues; + require($rep . $vues['trianglePascal']); + } catch (Exception $e) { $error = "404"; - require($rep.$vues['erreur']); + require($rep . $vues['erreur']); + } + } + public function goToNext() + { + try { + global $rep, $vues, $error; + require($rep . $vues['next'].$_REQUEST['num'].".html"); + } catch (Exception $e) { + $error = "Erreur Inconnue"; + require($rep . $vues['erreur']); + } + } + public function goToQueue() + { + try { + global $rep, $vues, $error; + //require($rep . $vues['Queue']); + $this->model->addToQueue(); + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); } } + public function logout() + { + $_SESSION['role'] = 'visitor'; + header('Location: index.php'); + } } \ No newline at end of file diff --git a/WEB/Controller/UtilisateurGateway.php b/WEB/Controller/UtilisateurGateway.php index e9c2ec01..0404b4a9 100644 --- a/WEB/Controller/UtilisateurGateway.php +++ b/WEB/Controller/UtilisateurGateway.php @@ -1,5 +1,4 @@ con = $con; + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } } /** @@ -20,18 +26,18 @@ class UtilisateurGateway } public function insert(Utilisateur $utilisateur) : void{ - $query = "INSERT INTO Utilisateur VALUE (:email,:pseudo,:mdp,:estAdmin)"; + $query = "INSERT INTO Utilisateur VALUES (:email,:pseudo,:mdp,:estAdmin)"; $this->con->executeQuery($query, array( - ':email' => array($utilisateur->getEmail(),PDO::PARAM_STR), - ':pseudo' => array($utilisateur->getPseudo(),PDO::PARAM_STR), - ':mdp' => array($utilisateur->getMdp(),PDO::PARAM_STR), - ':estAdmin' => array($utilisateur->getEstAdmin(),PDO::PARAM_BOOL))); + ':email' => array($utilisateur->getEmail(),SQLITE3_TEXT), + ':pseudo' => array($utilisateur->getPseudo(),SQLITE3_TEXT), + ':mdp' => array($utilisateur->getMdp(),SQLITE3_TEXT), + ':estAdmin' => array($utilisateur->getEstAdmin(),SQLITE3_INTEGER))); } public function delete(string $email) : void{ $query = "DELETE FROM utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email ,PDO::PARAM_STR) + ':email' => array($email ,SQLITE3_TEXT) )); } @@ -39,26 +45,17 @@ class UtilisateurGateway global $error; $query = "SELECT * FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email,PDO::PARAM_STR) + ':email' => array($email,SQLITE3_TEXT) )); $results=$this->con->getResults(); - foreach ($results as $row) { - $email=$row['email']; - $pseudo=$row['pseudo']; - $mdp=$row['mdp']; - $estAdmin=$row['estAdmin']; - } - if ($results == null){ - return new Utilisateur("null", "null", "null", false); - } - return new Utilisateur($email, $pseudo, $mdp,false); + return UtilisateurFactory::createUtilisateur($results); } public function getMdpByEmail(string $email) : string{ global $error; $query = "SELECT mdp FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email,PDO::PARAM_STR) + ':email' => array($email,SQLITE3_TEXT) )); $results=$this->con->getResults(); foreach ($results as $row) { @@ -74,19 +71,63 @@ class UtilisateurGateway public function getEstAdminByEmail(string $email) : bool{ $query = "SELECT estAdmin FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email,PDO::PARAM_STR) + ':email' => array($email,SQLITE3_TEXT) )); $results=$this->con->getResults(); - foreach ($results as $row) { - $estAdmin=$row['estAdmin']; - } + $estAdmin=$results[0]['estAdmin']; return $estAdmin; } + public function addToQueue(Utilisateur $utilisateur,Partie $partie){ + $query = "INSERT INTO Participer VALUES (:idPartie,:idUtilisateur,0)"; + $this->con->executeQuery($query,array( + ':idUtilisateur' => array($utilisateur->getEmail(),SQLITE3_TEXT), + ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER) + )); + } + + public function findUsersInQueue() : array{ + $query = "SELECT u.* FROM Utilisateur u, Participer p + WHERE u.email=p.utilisateur + AND p.etat=0"; + $this->con->executeQuery($query); + $results = $this->con->getResults(); + $user_group = UtilisateurFactory::createTabUtilisateur($results); + return $user_group; + } + + public function isAlreadyInqueue(Utilisateur $utilisateur) : bool{ + $query="SELECT utilisateur FROM Participer WHERE utilisateur=:utilisateur"; + $this->con->executeQuery($query, array( + ':utilisateur' => array($utilisateur->getEmail(),SQLITE3_TEXT) + ) + ); + $results=$this->con->getResults(); + if (empty($results)) + return false; + else + return true; + } + + public function queueFilled(){ + $query = "SELECT count(*) FROM Participer WHERE etat=0"; + $this->con->executeQuery($query); + if ($this->con->getResults()[0]['count(*)'] >= 4) + return True; + else + return False; + } + + private function launchGame(Utilisateur $utilisateur){ + $query = "UPDATE Participer SET etat=1 WHERE etat=0 AND utilisateur=:utilisateur"; + $this->con->executeQuery($query,array( + 'utilisateur' => array($utilisateur->getEmail(),SQLITE3_TEXT))); + } + /*public function resoudreEnigmeMulti(string $emailUtilisateur) { $query="SELECT c.partie FROM Contenir - WHERE c.joueur = :emailUtilisateur + WHERE c.utilisateur = :emailUtilisateur and c.enCours = TRUE"; $this->con->executeQuery($query, array( ':emailUtilisateur' => array($emailUtilisateur,SQLITE3_TEXT) @@ -95,7 +136,7 @@ class UtilisateurGateway $query="SELECT e.id, c2.indexEnigme FROM Resoudre r, Contenir c1,Contenir c2, Enigme e WHERE r.id = :idPartie - AND r.joueur=:idJoueur + AND r.utilisateur=:idutilisateur AND r.partie=:idPartie AND r.temps IS NOT NULL AND c1.partie = r.partie @@ -124,19 +165,19 @@ class UtilisateurGateway $classement=$results[0]["max"]+1; $query="SELECT * FROM Resoudre - WHERE r.joueur=:joueur + WHERE r.utilisateur=:utilisateur AND r.enigme=:idEnigme AND r.partie=:idPartie"; $this->con->executeQuery($query, array( - "joueur" => array($emailUtilisateur, SQLITE3_TEXT), + "utilisateur" => array($emailUtilisateur, SQLITE3_TEXT), "enigme" => array($idEnigme, SQLITE3_INTEGER), "partie" => array($idPartie, SQLITE3_INTEGER))); $results=$this->con->getResults(); if(empty($results)) { - $query="INSERT INTO Resoudre VALUES (:joueur, :enigme,:partie,:classement,:index,:temps,TRUE)"; + $query="INSERT INTO Resoudre VALUES (:utilisateur, :enigme,:partie,:classement,:index,:temps,TRUE)"; $this->con->executeQuery($query, array( - "joueur" => array($emailUtilisateur, SQLITE3_TEXT), + "utilisateur" => array($emailUtilisateur, SQLITE3_TEXT), "enigme" => array($idEnigme, SQLITE3_INTEGER), "partie" => array($idPartie, SQLITE3_INTEGER), "classement" => array($classement, SQLITE3_INTEGER), @@ -148,11 +189,11 @@ class UtilisateurGateway { $query="UPDATE Resoudre SET classement=:classement; - WHERE joueur=:joueur + WHERE utilisateur=:utilisateur AND enigme=:idEnigme AND partie=:idPartie"; $this->con->executeQuery($query, array( - "joueur" => array($emailUtilisateur, SQLITE3_TEXT), + "utilisateur" => array($emailUtilisateur, SQLITE3_TEXT), "enigme" => array($idEnigme, SQLITE3_INTEGER), "partie" => array($idPartie, SQLITE3_INTEGER), "classement" => array($classement, SQLITE3_INTEGER))); @@ -162,7 +203,7 @@ class UtilisateurGateway public function passerEnigmeMulti(string $emailUtilisateur){ $query="SELECT p.partie FROM Participer - WHERE p.joueur = :emailUtilisateur + WHERE p.utilisateur = :emailUtilisateur and p.enCours = TRUE"; $this->con->executeQuery($query, array( ':emailUtilisateur' => array($emailUtilisateur,SQLITE3_TEXT) @@ -171,7 +212,7 @@ class UtilisateurGateway $query="SELECT e.id, c2.indexEnigme FROM Resoudre r, Contenir c1,Contenir c2, Enigme e WHERE r.id = :idPartie - AND r.joueur=:idJoueur + AND r.utilisateur=:idUtilisateur AND r.partie=:idPartie AND r.temps IS NOT NULL AND r.enigme=c1.enigme @@ -189,9 +230,9 @@ class UtilisateurGateway $idEnigme=$results[0]["enigme"]; $index=$results[0]["indexEnigme"]; - $query="INSERT INTO Resoudre VALUES (:joueur, :enigme,:partie,:classement,:index,:temps,TRUE)"; + $query="INSERT INTO Resoudre VALUES (:utilisateur, :enigme,:partie,:classement,:index,:temps,TRUE)"; $this->con->executeQuery($query, array( - "joueur" => array($emailUtilisateur, SQLITE3_TEXT), + "utilisateur" => array($emailUtilisateur, SQLITE3_TEXT), "enigme" => array($idEnigme, SQLITE3_INTEGER), "partie" => array($idPartie, SQLITE3_INTEGER), "classement" => array(NULL, SQLITE3_NULL), @@ -202,7 +243,7 @@ class UtilisateurGateway public function resoudreEnigmeSolo(string $emailUtilisateur) { $query="SELECT c.partie FROM Contenir - WHERE c.joueur = :emailUtilisateur + WHERE c.utilisateur = :emailUtilisateur and c.enCours = TRUE"; $this->con->executeQuery($query, array( ':emailUtilisateur' => array($emailUtilisateur,SQLITE3_TEXT) @@ -211,7 +252,7 @@ class UtilisateurGateway $query="SELECT e.id, c2.indexEnigme FROM Resoudre r, Contenir c1,Contenir c2, Enigme e WHERE r.id = :idPartie - AND r.joueur=:idJoueur + AND r.utilisateur=:idUtilisateur AND r.partie=:idPartie AND r.enigme = c1.enigme AND c1.partie = r.partie @@ -241,19 +282,19 @@ class UtilisateurGateway $classement=$results[0]["max"]+1; $query="SELECT * FROM Resoudre - WHERE r.joueur=:joueur + WHERE r.utilisateur=:utilisateur AND r.enigme=:idEnigme AND r.partie=:idPartie"; $this->con->executeQuery($query, array( - "joueur" => array($emailUtilisateur, SQLITE3_TEXT), + "utilisateur" => array($emailUtilisateur, SQLITE3_TEXT), "enigme" => array($idEnigme, SQLITE3_INTEGER), "partie" => array($idPartie, SQLITE3_INTEGER))); $results=$this->con->getResults(); if(empty($results)) { - $query="INSERT INTO Resoudre VALUES (:joueur, :enigme,:partie,:classement,:index,:temps,TRUE)"; + $query="INSERT INTO Resoudre VALUES (:utilisateur, :enigme,:partie,:classement,:index,:temps,TRUE)"; $this->con->executeQuery($query, array( - "joueur" => array($emailUtilisateur, SQLITE3_TEXT), + "utilisateur" => array($emailUtilisateur, SQLITE3_TEXT), "enigme" => array($idEnigme, SQLITE3_INTEGER), "partie" => array($idPartie, SQLITE3_INTEGER), "classement" => array($classement, SQLITE3_INTEGER), @@ -264,11 +305,11 @@ class UtilisateurGateway { $query="UPDATE Resoudre SET classement=:classement; - WHERE joueur=:joueur + WHERE utilisateur=:utilisateur AND enigme=:idEnigme AND partie=:idPartie"; $this->con->executeQuery($query, array( - "joueur" => array($emailUtilisateur, SQLITE3_TEXT), + "utilisateur" => array($emailUtilisateur, SQLITE3_TEXT), "enigme" => array($idEnigme, SQLITE3_INTEGER), "partie" => array($idPartie, SQLITE3_INTEGER), "classement" => array($classement, SQLITE3_INTEGER))); diff --git a/WEB/Controller/VisitorController.php b/WEB/Controller/VisitorController.php new file mode 100644 index 00000000..af65f75d --- /dev/null +++ b/WEB/Controller/VisitorController.php @@ -0,0 +1,105 @@ +model = new VisitorModel(); + $action = $_REQUEST['action']; + switch ($action) { + case NULL: + $this->goToHome(); + break; + case "signUp": + $this->signUp(); + break; + case "login": + $this->login(); + break; + case "goToHome": + $this->goToHome(); + break; + case "goToLogin": + $this->goToLogin(); + break; + case "goToSignUp": + $this->goToSignUp(); + break; + case "goToQueue": + $this->goToLogin(); + break; + default: + $error = "Action non valide"; + require($rep . $vues['erreur']); + break; + } + } catch (PDOException $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } catch (Exception $e2) { + $error = $e2->getMessage(); + require($rep . $vues['erreur']); + } + } + public function goToHome() + { + try { + global $rep, $vues; + require($rep . $vues['main']); + } catch (Exception $e) { + $error = "404"; + require($rep . $vues['erreur']); + } + } + public function goToLogin() + { + try { + global $rep, $vues; + require($rep . $vues['login']); + } catch (Exception $e) { + $error = "404"; + require($rep . $vues['erreur']); + } + } + public function goToSignUp() + { + try { + global $rep, $vues; + require($rep . $vues['signUp']); + } catch (Exception $e) { + $error = "404"; + require($rep . $vues['erreur']); + } + } + public function signUp() + { + try { + global $rep, $vues, $error; + $this->model->signUp(); + $this->goToHome(); + } catch (PDOException $e) { + $error = "Erreur de connexion à la base de données."; + require($rep . $vues['erreur']); + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } + } + public function login() + { + try { + global $rep, $vues, $error; + $this->model->login(); + $this->goToHome(); + } catch (PDOException $e) { + $error = "Erreur de connexion à la base de données."; + require($rep . $vues['erreur']); + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } + } +} \ No newline at end of file diff --git a/WEB/Factory/PartieFactory.php b/WEB/Factory/PartieFactory.php index 58f3bb53..ceaf1ef0 100644 --- a/WEB/Factory/PartieFactory.php +++ b/WEB/Factory/PartieFactory.php @@ -1,21 +1,21 @@ getTempsDeResolution(); unset($tabIndex[$randomNumber]); } - $partie=new Partie($idMax+1,$tabEnigme); + $partie=new Partie($newId,$tabEnigme); return $partie; } diff --git a/WEB/Factory/UtilisateurFactory.php b/WEB/Factory/UtilisateurFactory.php new file mode 100644 index 00000000..860f6d63 --- /dev/null +++ b/WEB/Factory/UtilisateurFactory.php @@ -0,0 +1,26 @@ +idPartie = $idPartie; $this->datePartie = new DateTime(); - $this->$listeEnigme = $listeEnigme; + $this->listeEnigme = $listeEnigme; } /** - * @return string + * @return int */ - public function getIdPartie(): string + public function getIdPartie(): int { return $this->idPartie; } /** - * @param string $idPartie + * @param int $idPartie */ - public function setIdPartie(string $idPartie): void + public function setIdPartie(int $idPartie): void { $this->idPartie = $idPartie; } diff --git a/WEB/Model/Utilisateur.php b/WEB/Metier/Utilisateur.php similarity index 100% rename from WEB/Model/Utilisateur.php rename to WEB/Metier/Utilisateur.php diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php new file mode 100644 index 00000000..381b182e --- /dev/null +++ b/WEB/Model/UserModel.php @@ -0,0 +1,56 @@ +enigme_gateway = new EnigmeGateway(); + $this->partie_gateway = new PartieGateway(); + $this->utilisateur_gateway = new UtilisateurGateway(); + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $view['erreur']); + } + } + public function addToQueue(){ + echo '1'; + if($this->utilisateur_gateway->isAlreadyInqueue($_SESSION['utilisateur'])) + { + return; + } + echo '2'; + if (!$this->partie_gateway->partieInQueueExists()) { + echo '3'; + $tabEnigme = $this->enigme_gateway->findMultiEnigma(); + $idNewPartie = $this->partie_gateway->findPartieMaxId(); + $partie=$this->partie_gateway->creerPartieMulti($idNewPartie,$tabEnigme); + } + else{ + echo '4'; + $idPartieInQueue = $this->partie_gateway->findPartieInQueue(); + echo '5'; + $tabEnigme = $this->enigme_gateway->findEnigmaFromPartie($idPartieInQueue); + echo '6'; + $partie = $this->partie_gateway->rejoindrePartieMulti($idPartieInQueue, $tabEnigme); + echo '7'; + } + echo '8'; + $this->utilisateur_gateway->addToQueue($_SESSION['utilisateur'],$partie); + $userGroup=$this->utilisateur_gateway->findUsersInQueue(); + //trigger_event('add_to_queue',$userGroup); + } + + public function AddUserToQueueEvent(){ + $userGroup=$this->utilisateur_gateway->findUsersInQueue(); + if($userGroup.count()>=4) + { + $this->utilisateur_gateway->launchGame(); + } + } +} \ No newline at end of file diff --git a/WEB/Model/VisitorModel.php b/WEB/Model/VisitorModel.php new file mode 100644 index 00000000..288a7d8e --- /dev/null +++ b/WEB/Model/VisitorModel.php @@ -0,0 +1,71 @@ +enigme_gateway = new EnigmeGateway(); + $this->partie_gateway = new PartieGateway(); + $this->utilisateur_gateway = new UtilisateurGateway(); + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $view['erreur']); + } + } + + public function signUp() + { + global $sel, $error; + $validation = new Validation(); + if (!$validation->ValidateEmail($_REQUEST['email'])) { + $error = "Email invalides."; + throw (new Exception("Email non valide")); + } + if (!$validation->ValidateUsername($_REQUEST['username'])) { + $error = "Nom d'utilisateur invalides. Il ne doit pas contenir de caractère spéciaux."; + throw (new Exception("Pseudo non valide")); + } + if (!$validation->ValidatePassword($_REQUEST['password'])) { + $error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères."; + throw (new Exception("Mot de passe non valide")); + } + $j = $this->utilisateur_gateway->getUtilisateurByEmail($_REQUEST['email']); + if ($j->getEmail() != "null") { + $error = "Email déjà utilisé."; + throw (new Exception("Email déjà utilisé")); + } + $password = password_hash($_REQUEST['password'] . $sel, PASSWORD_DEFAULT); + $utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, false); + $this->utilisateur_gateway->insert($utilisateur); + $_SESSION['role'] = 'user'; + $_SESSION['utilisateur'] = $utilisateur; + } + public function login() + { + global $vue, $sel, $error; + $utilisateur = $this->utilisateur_gateway->getUtilisateurByEmail($_REQUEST['email']); + if ($utilisateur->getEmail() == "null") { + $error = "Utilisateur non trouvé."; + throw new Exception("Utilisateur introuvable"); + } + $mdp = $this->utilisateur_gateway->getMdpByEmail($_REQUEST['email']); + if (! password_verify($_REQUEST['password'] . $sel, $mdp)) { + $error = "Mot de passe incorrect."; + throw new Exception("Mot de passe invalide"); + } + $estAdmin = $this->utilisateur_gateway->getEstAdminByEmail($_REQUEST['email']); + if ($estAdmin == true) { + $_SESSION['role'] = "admin"; + } else { + $_SESSION['role'] = "user"; + } + $_SESSION['utilisateur'] = $utilisateur; + $_SESSION['connected'] = 'true'; + } +} \ No newline at end of file diff --git a/WEB/View/assets/img/ImgMain.png b/WEB/View/assets/img/ImgMain.png new file mode 100644 index 00000000..6040317c Binary files /dev/null and b/WEB/View/assets/img/ImgMain.png differ diff --git a/WEB/View/assets/img/SecondMainBack.jpg b/WEB/View/assets/img/SecondMainBack.jpg new file mode 100644 index 00000000..4b86ffd0 Binary files /dev/null and b/WEB/View/assets/img/SecondMainBack.jpg differ diff --git a/WEB/View/assets/img/neonHead.jpg b/WEB/View/assets/img/neonHead.jpg deleted file mode 100644 index 813b578b..00000000 Binary files a/WEB/View/assets/img/neonHead.jpg and /dev/null differ diff --git a/WEB/View/src/CSS/Enigme.css b/WEB/View/src/CSS/Enigme.css index 02f79283..37305c82 100644 --- a/WEB/View/src/CSS/Enigme.css +++ b/WEB/View/src/CSS/Enigme.css @@ -1,23 +1,19 @@ -/*Fonts CSS */ - -@import url("https://fonts.googleapis.com/css2?family=Orbitron&display=swap"); - -/*Default CSS*/ -* { - margin: 0; - padding: 0; - box-sizing: border-box; +@font-face { + font-family: Fauna; + src: url("../../assets/fonts/Fauna.ttf"); +} +@font-face { + font-family: Equinox; + src: url("../../assets/fonts/Equinox.otf"); } -h1, -h2, -h3, -h4, -h5, -h6 { - margin: 0; - padding: 0; - line-height: normal; +body { + min-height: 100vh; + font-family: Verdana, Arial, Helvetica, sans-serif; + color: white; + scroll-behavior: smooth; + height: 100vh; + background-color: #050E15; } p, @@ -29,105 +25,63 @@ ul { padding: 0; line-height: normal; text-decoration: none !important; + font-family: "Fauna", sans-serif; + font-size: 14px; + line-height: 20px; + letter-spacing: 0.8px; } -a:hover { - text-decoration: none !important; -} - -input:focus, -textarea:focus, -select:focus { - outline: none; -} +/***** Text CSS *****/ -@media (min-width: 1700px) { - main .buttons { - max-width: 100%; - padding: 0 150px; - } +p{ + font-family: "Fauna", sans-serif; + font-size: 14px; + line-height: 20px; + letter-spacing: 0.8px; } -/* Main CSS */ -html { - scroll-behavior: smooth; - height: 100vh; - background-position: center center; - background-color: #464646; - background-attachment: fixed; - background-repeat: no-repeat; - background-size: cover; +h1, h2, h3, h4, h5, h6 { + font-family: "Equinox", sans-serif; } -body { - display: flex; - font-family: "Orbitron", sans-serif; - flex-direction: row; - align-items: stretch; - height: 95%; - margin-top: 10px; - padding: 0; +/***** End Text CSS *****/ - --light: hsl(220, 50%, 90%); - --primary: hsl(255, 30%, 55%); - --focus: hsl(210, 90%, 50%); - --border-color: hsla(0, 0%, 100%, 0.2); - --global-background: hsl(220, 25%, 10%); - --background: linear-gradient(to right, #040a29, #0e1538); - --shadow-1: #0b1b78; - --shadow-2: #173c45; -} -.enigme { - width: 25%; - height: fit-content; - color: aliceblue; - background: rgba(0, 0, 0, 0.6); - box-sizing: border-box; - border-radius: 10px; - padding: 10px; - margin-left: 10px; - margin-right: 20px; - letter-spacing: 1.2px; -} +/***** Editor + Console CSS *****/ -.titre_pre { - display: flex; - margin-top: 10px; - margin-right: 10px; - margin-bottom: 20px; - padding-left: 10px; +#editor { + width: 100%; + min-height: 80vh; + height: auto; } -.sign { - margin-left: 5%; +#console { + font-family: DejaVu Sans Mono, monospace; + font-size: 0.8rem; + letter-spacing: 1px; + background-color: #222831; + resize: none; + color: #fff; + border: 1px solid #44fff6; + box-shadow: 0 0 1px #fff, + 0 0 1px #fff, + 0 0 5px #44fff6, + 0 0 5px #44fff6, + inset 0 0 5px #44fff6; } -/* Main Button Css */ - -.buttons { - display: flex; - justify-content: center; - align-items: center; - flex-direction: column; - cursor: pointer; -} +/***** End Editor + Console CSS *****/ -.compiler_class .buttons div { - display: flex; -} +/* Buttons */ -.buttons .btn { +.btn{ position: relative; width: 120px; height: 60px; - display: inline-block; background: transparent; - margin: 20px; } -.buttons .btn:before, -.buttons .btn:after { +.btn:before, .btn:after{ content: ""; position: absolute; inset: 0; @@ -135,220 +89,34 @@ body { background: #f00; } -.buttons .btn:nth-child(1):before, -.buttons .btn:nth-child(1):after { +.btn:nth-child(1):before, .btn:nth-child(1):after{ background: linear-gradient(45deg, #00ccff, #0e1538, #d400d4); } -.buttons .btn:nth-child(2):before, -.buttons .btn:nth-child(2):after { +.btn:nth-child(2):before, .btn:nth-child(2):after{ background: linear-gradient(45deg, #d400d4, #0e1538, #fb5942); } -.buttons .btn:hover:before { +.btn:hover:before{ inset: -3px; } -.buttons .btn:hover:after { +.btn:hover:after{ inset: -3px; filter: blur(10px); } -.buttons .btn span { +.btn span{ position: absolute; top: 0; left: 0; width: 100%; height: 100%; - display: inline-block; background: #0e1538; z-index: 10; display: flex; justify-content: center; align-items: center; - font-size: 1.2em; text-transform: uppercase; - letter-spacing: 2px; - color: #fff; - border: 1px solid #040a29; - overflow: hidden; -} - -.buttons .btn span::before { - content: ""; - position: absolute; - top: 0; - left: -50%; - width: 100%; - height: 100%; - background: rgba(255, 255, 255, 0.075); - transform: skew(25deg); -} - -.buttons .btn .noAnimation { - animation: none; - font-size: 1em; -} - -/* Console CSS*/ - -.compiler_class { - width: 30%; -} - -#console { - font-size: 0.8rem; - opacity: 0.85; - letter-spacing: 1px; - background-color: #040a29; color: #fff; - border: solid 1px #414141; - padding: 10px; - margin-left: 10px; - margin-right: 10px; - max-width: 95%; - max-height: 85%; - line-height: 1.5; - border-radius: 5px; - resize: none; -} - -/* Ace CSS*/ - -.ace { - width: 45%; - max-height: 100%; - margin-bottom: 0; - margin-right: 10px; -} - -/* Text Css */ - -.enigme h1 { - font-size: 1.5rem !important; - font-weight: 700; - text-align: center; -} -.enigme .sign { - display: contents; -} - -.enigme h2 { - font-size: 1.5rem; - font-weight: 600; -} - -.enigme p { - font-size: 1rem; - font-weight: 400; - margin-right: 10px; -} - -#result { - display: flex; - align-items: center; - margin: 0 30px; - font-size: 1.5rem; -} - -/* Modal CSS */ - -.modal-container { - position: fixed; - top: 0; - left: 0; - z-index: 10; - - display: none; - justify-content: center; - align-items: center; - - width: 100%; - height: 100%; - background: var(--m-background); -} - -.modal-container:target { - display: flex; - align-items: center; -} - -.modal { - display: flex; - justify-content: center; - align-items: flex-end; - width: 30%; - height: 35%; - padding: 10px 0; - border-radius: 0.8rem; - - color: aliceblue; - background: var(--background); - box-shadow: var(--m-shadow, 0.4rem 0.4rem 8.2rem 0.2rem) var(--shadow-1); - position: relative; - overflow: hidden; -} - -/* Modal H1 */ - -.modal #containerResult { - display: flex; - justify-content: center; - align-items: center; - flex-direction: column; - width: 80%; - height: 100%; -} - -/* Modal Container Buttons */ - -.modal .buttons { - display: flex; - align-items: flex-end; - height: 100%; - width: auto; -} - -.modal .buttons #top { - display: flex; - justify-content: flex-end; - align-items: flex-start; - width: auto; - height: 50%; -} - -.modal .buttons #bottom { - display: flex; - justify-content: center; - align-items: flex-end; - width: auto; - height: 50%; -} - -/* Modal buttons btn */ - -.modal .buttons .btn { - width: 30px; - height: 30px; - margin: 0 15px; -} - -.modal .buttons #bottom { - width: 100%; -} - -.modal .buttons #fleche { - display: none; - width: 75px; - height: 40px; -} - -.modal .buttons .btn span { - background: #06124b; - color: white; -} - -.modal .buttons #bottom .btn:nth-child(1):before, -.modal .buttons #bottom .btn:nth-child(1):after { - background: linear-gradient(45deg, #d400d4, #0e1538, #fb5942); -} +} \ No newline at end of file diff --git a/WEB/View/src/CSS/Enigmev2.css b/WEB/View/src/CSS/Enigmev2.css deleted file mode 100644 index 14b2a092..00000000 --- a/WEB/View/src/CSS/Enigmev2.css +++ /dev/null @@ -1,226 +0,0 @@ -/*Fonts CSS */ - -@import url('https://fonts.googleapis.com/css2?family=Orbitron&display=swap'); - -/*Default CSS*/ - - -/*Ace CSS */ - -.ace{ - width: 100%; - height: 100%; -} - - -/* Main Button Css */ - -.buttons{ - display: flex; - justify-content: center; - align-items: center; - flex-direction: column; - cursor: pointer; -} - -.compiler_class .buttons div{ - display: flex; -} - -.buttons .btn{ - position: relative; - width: 120px; - height: 60px; - display: inline-block; - background: transparent; - margin: 20px; - } - - - .buttons .btn:before, .buttons .btn:after - { - content:''; - position: absolute; - inset: 0; - transition: 0.5s; - background: #f00 - } - - -.buttons .btn:nth-child(1):before, .buttons .btn:nth-child(1):after -{ - background: linear-gradient(45deg, #00ccff, #0e1538, #d400d4) -} - -.buttons .btn:nth-child(2):before, .buttons .btn:nth-child(2):after -{ - background: linear-gradient(45deg, #d400d4, #0e1538, #fb5942); -} - -.buttons .btn:hover:before -{ - inset: -3px; -} - -.buttons .btn:hover:after -{ - inset: -3px; - filter: blur(10px); -} - -.buttons .btn span{ - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 100%; - display: inline-block; - background: #0e1538; - z-index: 10; - display: flex; - justify-content: center; - align-items: center; - font-size: 1.2em; - text-transform: uppercase; - letter-spacing: 2px; - color: #fff; - border: 1px solid #040a29; - overflow: hidden; -} - -.buttons .btn span::before{ - content:''; - position: absolute; - top: 0; - left: -50%; - width: 100%; - height: 100%; - background: rgba(255,255,255,0.075); - transform: skew(25deg) -} - - - -.buttons .btn .noAnimation { - animation: none; - font-size: 1em; -} - - -/* Modal CSS */ - -.modal-container { - position: fixed; - top: 0; - left: 0; - z-index: 10; - - display: none; - justify-content: center; - align-items: center; - - width: 100%; - height: 100%; - background: var(--m-background); - } - - .modal-container:target { - display: flex; - align-items: center; - } - - .modal { - display: flex; - justify-content: center; - align-items: flex-end; - width: 30%; - height: 35%; - padding: 10px 0; - border-radius: .8rem; - - color: aliceblue; - background: var(--background); - box-shadow: var(--m-shadow, .4rem .4rem 8.2rem .2rem) var(--shadow-1); - position: relative; - overflow: hidden; - } - - /* Modal H1 */ - - .modal #containerResult{ - display: flex; - justify-content: center; - align-items: center; - flex-direction: column; - width: 80%; - height: 100%; - } - - - /* Modal Container Buttons */ - - .modal .buttons{ - display: flex; - align-items: flex-end; - height: 100%; - width: auto; - } - - .modal .buttons #top{ - display: flex; - justify-content: flex-end; - align-items: flex-start; - width: auto; - height: 50%; - } - - .modal .buttons #bottom{ - display: flex; - justify-content: center; - align-items: flex-end; - width: auto; - height: 50%; - } - - /* Modal buttons btn */ - - .modal .buttons .btn{ - width: 30px; - height: 30px; - margin : 0 15px; - } - - .modal .buttons #bottom{ - width: 100%; - } - - .modal .buttons #fleche{ - display: none; - width: 75px; - height: 40px; - } - - .modal .buttons .btn span{ - background: #06124b; - color: white; - } - - .modal .buttons #bottom .btn:nth-child(1):before, .modal .buttons #bottom .btn:nth-child(1):after - { - background: linear-gradient(45deg, #d400d4, #0e1538, #fb5942); - } - - /* Console CSS*/ - -#console{ - font-size: .8rem; - opacity: 0.85; - letter-spacing: 1px; - background-color: #040a29; - color: #fff; - border: solid 1px #414141; - max-width: 95%; - max-height: 85%; - line-height: 1.5; - resize: none; -} \ No newline at end of file diff --git a/WEB/View/src/CSS/Eni.css b/WEB/View/src/CSS/FirstTest.css similarity index 55% rename from WEB/View/src/CSS/Eni.css rename to WEB/View/src/CSS/FirstTest.css index e496983c..f02fed44 100644 --- a/WEB/View/src/CSS/Eni.css +++ b/WEB/View/src/CSS/FirstTest.css @@ -9,51 +9,26 @@ body { min-height: 100vh; - font-family: Verdana, Arial, Helvetica, sans-serif; + font-family: "Equinox", sans-serif; color: white; scroll-behavior: smooth; - height: 100vh; - background-position: center center; - background-attachment: fixed; - background-repeat: no-repeat; - background-size: cover; - /* background-image: url("../../assets/img/Background5.jpg"); */ - background-color: #050E15; + background-color: #050e15; } -p, -a, -li, -button, -ul { - margin: 0; - padding: 0; - line-height: normal; - text-decoration: none !important; - font-family: "Fauna", sans-serif; - font-size: 14px; - line-height: 20px; - letter-spacing: 0.8px; +nav { + background-color: #050e15; } -/***** Text CSS *****/ - -p{ +p { font-family: "Fauna", sans-serif; font-size: 14px; - line-height: 20px; - letter-spacing: 0.8px; } -h1, h2, h3, h4, h5, h6 { - font-family: "Equinox", sans-serif; +li { + font-family: "Fauna", sans-serif; + font-size: 14px; } -/***** End Text CSS *****/ - - -/***** Editor + Console CSS *****/ - #editor { width: 100%; min-height: 80vh; @@ -61,27 +36,26 @@ h1, h2, h3, h4, h5, h6 { } #console { + font-family: DejaVu Sans Mono, monospace; font-size: 0.8rem; letter-spacing: 1px; background-color: #222831; - color: #fff; - border: solid 1px #414141; - border-radius: 5px; resize: none; + color: #fff; + border: 1px solid #44fff6; + box-shadow: 0 0 1px #fff, 0 0 1px #fff, 0 0 5px #44fff6, 0 0 5px #44fff6, + inset 0 0 5px #44fff6; } -/***** End Editor + Console CSS *****/ - -/* Buttons */ - -.btn{ +.btn { position: relative; width: 120px; height: 60px; background: transparent; } -.btn:before, .btn:after{ +.btn:before, +.btn:after { content: ""; position: absolute; inset: 0; @@ -89,24 +63,26 @@ h1, h2, h3, h4, h5, h6 { background: #f00; } -.btn:nth-child(1):before, .btn:nth-child(1):after{ +.btn:nth-child(1):before, +.btn:nth-child(1):after { background: linear-gradient(45deg, #00ccff, #0e1538, #d400d4); } -.btn:nth-child(2):before, .btn:nth-child(2):after{ +.btn:nth-child(2):before, +.btn:nth-child(2):after { background: linear-gradient(45deg, #d400d4, #0e1538, #fb5942); } -.btn:hover:before{ +.btn:hover:before { inset: -3px; } -.btn:hover:after{ +.btn:hover:after { inset: -3px; filter: blur(10px); } -.btn span{ +.btn span { position: absolute; top: 0; left: 0; @@ -118,6 +94,6 @@ h1, h2, h3, h4, h5, h6 { justify-content: center; align-items: center; text-transform: uppercase; - letter-spacing: 1.5px; + letter-spacing: 2px; color: #fff; -} \ No newline at end of file +} diff --git a/WEB/View/src/CSS/Main2.css b/WEB/View/src/CSS/Main2.css new file mode 100644 index 00000000..7108748c --- /dev/null +++ b/WEB/View/src/CSS/Main2.css @@ -0,0 +1,45 @@ +body { + min-height: 100vh; + font-family: "Orbitron", sans-serif; + color: white; + scroll-behavior: smooth; + height: 100vh; + background-image: url("../../assets/img/ImgMain.png"); + background-position: center center; + background-attachment: fixed; + background-repeat: no-repeat; + background-size: cover; + background-color: #000; +} + +#imgMain { + background-image: url("../../assets/img/SecondMainBack.jpg"); + background-position: bottom center; + background-attachment: fixed; + background-repeat: no-repeat; + background-size: cover; + display: block; + margin: auto; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + width: 85%; + height: 70%; + border-radius: 10px; + -webkit-border-radius: 10px; + -moz-border-radius: 10px; + -ms-border-radius: 10px; + -o-border-radius: 10px; +} + +#AllBg { + background-color: #511949; + opacity: 0.8; + background-size: 10px 10px; + border-radius: 5px; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + -ms-border-radius: 5px; + -o-border-radius: 5px; +} diff --git a/WEB/View/src/CSS/Presentation.css b/WEB/View/src/CSS/Presentation.css index 03f8b5ab..1d9a7e0b 100644 --- a/WEB/View/src/CSS/Presentation.css +++ b/WEB/View/src/CSS/Presentation.css @@ -41,7 +41,7 @@ nav { /* Section Histoire */ section{ - min-height: 60vh; + min-height: 70vh; margin-bottom: 10px; } @@ -67,4 +67,5 @@ section{ p { font-family: "Fauna", sans-serif; font-size: 20px; -} \ No newline at end of file +} + diff --git a/WEB/View/src/JS/FirstFunction.js b/WEB/View/src/JS/FirstFunction.js new file mode 100644 index 00000000..0a830ef6 --- /dev/null +++ b/WEB/View/src/JS/FirstFunction.js @@ -0,0 +1,29 @@ +//~ Function that test the user code + +async function submit(){ + var test = editor.getValue()+`\n +import random as r + +def multiVerif(a,b): + return a*b + +def multiTest(x): + multiplication(1,1) + for i in range(x): + a=r.randint(0,100) + b=r.randint(0,100) + if(multiplication(a,b) != multiVerif(a,b)): + return False + return True + +print(multiTest(5)) + + `; + exec("print('True')", "code"); + exec(test, "solution"); + result.innerHTML = "Test en cours..."; + await new Promise(r => setTimeout(r, 1500)); + check(); + } + + \ No newline at end of file diff --git a/WEB/View/src/JS/FirstTest.js b/WEB/View/src/JS/FirstTest.js new file mode 100644 index 00000000..0333f0ab --- /dev/null +++ b/WEB/View/src/JS/FirstTest.js @@ -0,0 +1,3 @@ +var secondTest1 = "Pour ce second test, nous allons voir comment déclarer une variable et le manipuler. Pour créer une variable en python il est inutile de déclarer son type, il suffit de faire : "; +var secondTest2 = "x = 1" +var secondTest3 = "Pour la manipuler"; \ No newline at end of file diff --git a/WEB/View/src/JS/Hanoi.js b/WEB/View/src/JS/Hanoi.js index 845484c5..54452ff3 100644 --- a/WEB/View/src/JS/Hanoi.js +++ b/WEB/View/src/JS/Hanoi.js @@ -17,6 +17,7 @@ def hanoiVerif(nb_disks,start, middle, end): return l def testhanoi(x): + hanoi(1,"A","B","C") if(hanoi(3,"A","B","C")!=[['A','C'],['A','B'],['C','B'],['A','C'],['B','A'],['B','C'],['A','C']]): return False for i in range(x): diff --git a/WEB/View/src/JS/If.js b/WEB/View/src/JS/If.js new file mode 100644 index 00000000..3b756a24 --- /dev/null +++ b/WEB/View/src/JS/If.js @@ -0,0 +1,41 @@ +//~ Function that test the user code + +async function submit(){ + var test = editor.getValue()+`\n +import random as r + +def conditionVerif(list,a): + for i in list: + if(i == 1): + a += 1 + elif(i != 2): + a -=1 + elif(i < 3): + a *= a + elif(i > 6): + a +=4 + else: + a +=5 + return a + +def conditionTest(x): + condition([],0) + list=[] + for i in range(x): + for i in range(r.randint(1,10)): + list.append(r.randint(1,10)) + a=r.randint(1,10) + if(condition(list,a)!=conditionVerif(list,a)): + return False + return True + +print(conditionTest(5)) + `; + exec("print('True')", "code"); + exec(test, "solution"); + result.innerHTML = "Test en cours..."; + await new Promise(r => setTimeout(r, 1500)); + check(); + } + + \ No newline at end of file diff --git a/WEB/View/src/JS/Presentation.js b/WEB/View/src/JS/Presentation.js index bd756c5a..f1c24436 100644 --- a/WEB/View/src/JS/Presentation.js +++ b/WEB/View/src/JS/Presentation.js @@ -19,5 +19,5 @@ const fox = document.querySelector(".moving-fox"); window.addEventListener("scroll", () => { const scrollValue = window.scrollY - 700; fox.style.top = `${scrollValue / 1}px`; - fox.style.opacity = `${window.scrollY / 700}`; + fox.style.opacity = `${window.scrollY / 800}`; }); diff --git a/WEB/View/src/JS/String.js b/WEB/View/src/JS/String.js new file mode 100644 index 00000000..e5a6de91 --- /dev/null +++ b/WEB/View/src/JS/String.js @@ -0,0 +1,34 @@ +//~ Function that test the user code + +async function submit(){ + var test = editor.getValue()+`\n +import random as r + +def triVerif(a,b): + s = "" + i = 0 + while len(s)i): + s += a[i] + if(len(b)>i): + s += b[i] + i += 1 + return s + +def triTest(x): + a = "Hlowrd" + b = "el ol" + if(triVerif(a,b)!=tri(a,b)): + return False + return True + +print(triTest(5)) + `; + exec("print('True')", "code"); + exec(test, "solution"); + result.innerHTML = "Test en cours..."; + await new Promise(r => setTimeout(r, 1500)); + check(); + } + + \ No newline at end of file diff --git a/WEB/View/src/JS/TrianglePascal.js b/WEB/View/src/JS/TrianglePascal.js index 73b9a44c..5225fb0d 100644 --- a/WEB/View/src/JS/TrianglePascal.js +++ b/WEB/View/src/JS/TrianglePascal.js @@ -18,11 +18,12 @@ def estTriangleDePascal(n): return triangle def testTriangleDePascal(n): + triangle_pascal(0) listTest=[0,1] for i in range(0,n): listTest.append(r.randint(5,140)) for i in listTest: - if(TriangleDePascal(i)!=estTriangleDePascal(i)): + if(triangle_pascal(i)!=estTriangleDePascal(i)): return False return True diff --git a/WEB/View/src/JS/base.js b/WEB/View/src/JS/base.js index 745a5be5..7a4b795b 100644 --- a/WEB/View/src/JS/base.js +++ b/WEB/View/src/JS/base.js @@ -110,12 +110,13 @@ function check() { } } + /** - * It gets all the elements with the class name "help" and sets their opacity to 1. + * It gets all the elements with the class name "help" and sets their display property to "block". */ function displayHelp() { var help = document.getElementsByClassName("help"); for (var i = 0; i < help.length; i++) { - help[i].style.opacity = 1; + help[i].style.display = "block"; } } diff --git a/WEB/View/src/JS/cesarDecrypt.js b/WEB/View/src/JS/cesarDecrypt.js index 19526772..61377bfa 100644 --- a/WEB/View/src/JS/cesarDecrypt.js +++ b/WEB/View/src/JS/cesarDecrypt.js @@ -3,6 +3,7 @@ async function submit(){ var test = editor.getValue()+`\n import random as r + def DecryptVerif(text, key): result = "" for i in range(len(text)): @@ -16,6 +17,7 @@ def DecryptVerif(text, key): return result def testDecrypte(x): + Decrypt("",1) if(Decrypt("Jgnnq yqtnf",2)!="Hello world"): return False if(Decrypt("Blarycnm",9)!="Scripted"): diff --git a/WEB/View/src/JS/cesarEncrypt.js b/WEB/View/src/JS/cesarEncrypt.js index d6e15a2a..8f83e954 100644 --- a/WEB/View/src/JS/cesarEncrypt.js +++ b/WEB/View/src/JS/cesarEncrypt.js @@ -3,6 +3,7 @@ async function submit(){ var test = editor.getValue()+`\n import random as r + def EncryptVerif(text, key): result = "" for i in range(len(text)): @@ -16,6 +17,7 @@ def EncryptVerif(text, key): return result def testEncrypte(x): + Encrypt("",1) if(Encrypt("Hello world",2)!="Jgnnq yqtnf"): return False if(Encrypt("Scripted",9)!="Blarycnm"): diff --git a/WEB/View/src/JS/chouette.js b/WEB/View/src/JS/chouette.js index c347ea58..a023c69f 100644 --- a/WEB/View/src/JS/chouette.js +++ b/WEB/View/src/JS/chouette.js @@ -4,22 +4,23 @@ async function submit(){ var test = editor.getValue()+`\n import random as r def chouetteVerif(valeur): - res=list() - for i in range(1, 7): - for j in range(i, 7): - for k in range(j, 7): - if (i+j+k) == valeur: - res.append([i, j, k]) - return res + res=list() + for i in range(1, 7): + for j in range(i, 7): + for k in range(j, 7): + if (i+j+k) == valeur: + res.append([i, j, k]) + return res def test_chouette(n): - listTest=[] - for i in range(0,n): + chouette(1) + listTest=[] + for i in range(0,n): listTest.append(r.randint(3,18)) - for i in listTest: - if(chouette(i)!=chouetteVerif(i)): - return False - return True + for i in listTest: + if(chouette(i)!=chouetteVerif(i)): + return False + return True print(test_chouette(5)) `; diff --git a/WEB/View/src/JS/chuckNorris.js b/WEB/View/src/JS/chuckNorris.js index 16e24af4..017c682b 100644 --- a/WEB/View/src/JS/chuckNorris.js +++ b/WEB/View/src/JS/chuckNorris.js @@ -30,6 +30,7 @@ def binaire2unitaireVerif(x): def testChuckNorris(x): l="0000000" + binaire2unitaire(l) if(binaire2unitaire(l)!="00 0000000"): return False l="1111111" diff --git a/WEB/View/src/pages/Enigme/CesarDecrypt.html b/WEB/View/src/pages/Enigme/CesarDecrypt.html index 8c3c3a13..4f9bc15e 100644 --- a/WEB/View/src/pages/Enigme/CesarDecrypt.html +++ b/WEB/View/src/pages/Enigme/CesarDecrypt.html @@ -1,100 +1,192 @@ - - - - - - Code César - - - - - - -
-
-
- home -
-
-

- c - es - a - r -

-

-
-

Consigne


-

- Écrire une fonction Decrypt qui prend en argument un essage crypté et une clé et qui retourne le message decrypté avec le code César.(les espace ne seront pas encodé.) -


-

Rappel


-

Le code César (ou chiffre de César ) est un chiffrement par substitution, où chaque lettre est remplacée par une autre lettre se situant un peu plus loin dans l'alphabet. Par exemple A avec une clé 2 devient C. -


-

Exemple


-

Entrée :      Sortie :

-

'fbehu',3       cyber


-

Aide


-

- La fonction ord(char) de python permet de retourner l’Unicode (standard d’encodage de caractères) d'un caractère. Par exemple, ord('a') retourné '97' et ord('b’) retourne 98. -

-
-
def Decrypt(text, key): - result = "" - for i in range(len(text)): - char = text[i] - if(char==" "): - result+=" " - elif (char.isupper()): - result += chr((ord(char) - key-65) % 26 + 65) - else: - result += chr((ord(char) - key - 97) % 26 + 97) - return result
-
- -
-
- - Run - - - Submit - + + + + + Code Cesar + + + + + + + +
+ +
+
+ home +
+
+ + + +
+ +
+

+ Code Cesar +

+

+ Écrire une fonction Decrypt qui prend en argument + un message et une clé + et qui retourne le message décrypté avec le code César.(les espace ne seront pas encodé.) +

+

Rappel

+

+ Le code César (ou chiffre de César ) est un chiffrement par substitution, +
où chaque lettre est remplacée par une autre lettre se situant un peu plus loin dans l'alphabet . +
Par exemple A avec une clé 2 devient C. +

+

Exemple

+

Entrée :      Sortie :

+

'fbehu',3      cyber

+ + +
+ + + +
+
def Decrypt(text, key):
-
+
+ -