From 4a4f204cb3e17994f1eba4ec0340be00339b1b87 Mon Sep 17 00:00:00 2001 From: brongniart Date: Mon, 2 Dec 2024 11:38:44 +0100 Subject: [PATCH 01/13] debut verification var session --- src/Controleur/VisitorControler.php | 5 +++-- src/Verification/Verification.php | 18 ------------------ src/Verification/VerificationChar.php | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 20 deletions(-) delete mode 100644 src/Verification/Verification.php create mode 100644 src/Verification/VerificationChar.php diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php index 20bd6a1..5273afe 100644 --- a/src/Controleur/VisitorControler.php +++ b/src/Controleur/VisitorControler.php @@ -13,6 +13,7 @@ use Twig\Error\LoaderError; use Twig\Error\RuntimeError; use Twig\Error\SyntaxError; +use Verification\VerificationChar; Class VisitorControler { @@ -69,7 +70,7 @@ Class VisitorControler { global $vues; $type = ($_POST['type'] ?? ""); - $search = ( $_POST['search'] ?? NULL); + $search = ( VerificationChar::verifChar( $_POST['search'] ) ?? NULL); $filtre = ($arg['filtre'] ?? []); @@ -126,7 +127,7 @@ Class VisitorControler { { $_SESSION['user'] = $pseudo; $_SESSION['role'] = 'user'; - header("Location: ". $racine); ///~kekentin/WF/WF-Website/ + header("Location: ". $racine); exit(); }else { diff --git a/src/Verification/Verification.php b/src/Verification/Verification.php deleted file mode 100644 index a607afa..0000000 --- a/src/Verification/Verification.php +++ /dev/null @@ -1,18 +0,0 @@ - \ No newline at end of file diff --git a/src/Verification/VerificationChar.php b/src/Verification/VerificationChar.php new file mode 100644 index 0000000..44d46bd --- /dev/null +++ b/src/Verification/VerificationChar.php @@ -0,0 +1,19 @@ + \ No newline at end of file From 44a9cff4780351b1c556ceb814f0b6415cdfb251 Mon Sep 17 00:00:00 2001 From: brongniart Date: Mon, 2 Dec 2024 14:34:30 +0100 Subject: [PATCH 02/13] aplicationn de la verification --- composer.json | 3 +- config/config.php | 2 +- src/Controleur/UserControler.php | 27 +- src/Controleur/VisitorControler.php | 25 +- src/Verification/Verification.php | 44 + src/Verification/VerificationChar.php | 19 - vendor/autoload.php | 50 +- vendor/composer/ClassLoader.php | 1158 +++++++++++------------ vendor/composer/LICENSE | 42 +- vendor/composer/autoload_classmap.php | 26 +- vendor/composer/autoload_files.php | 34 +- vendor/composer/autoload_namespaces.php | 18 +- vendor/composer/autoload_psr4.php | 35 +- vendor/composer/autoload_real.php | 100 +- vendor/composer/autoload_static.php | 208 ++-- vendor/composer/platform_check.php | 52 +- 16 files changed, 941 insertions(+), 902 deletions(-) create mode 100644 src/Verification/Verification.php delete mode 100644 src/Verification/VerificationChar.php diff --git a/composer.json b/composer.json index 5174d0b..bfdad6b 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "Controleur\\": "src/Controleur/", "Model\\": "src/Model/", "Gateway\\": "src/Gateway/", - "Entity\\": "src/Entity/" + "Entity\\": "src/Entity/", + "Verification\\": "src/Verification/" } } } diff --git a/config/config.php b/config/config.php index aedf257..a351f18 100644 --- a/config/config.php +++ b/config/config.php @@ -12,7 +12,7 @@ $base = ''; $login = ''; $mdp = ''; -$racine='/~marocher8/WF-Website'; +$racine='/~kekentin/WF/WF-Website'; //Vues diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 6e8f688..6f2fdf9 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -21,6 +21,7 @@ use Twig\Error\RuntimeError; use Twig\Error\SyntaxError; use Twig\Loader\FilesystemLoader; +use Verification\Verification; class UserControler { @@ -40,7 +41,7 @@ class UserControler { public function profil() { global $vues; - $p = $this->uMod->getUsername($_SESSION["user"]); + $p = $this->uMod->getUsername(Verification::verifChar($_SESSION["user"])); require_once $vues['profil']; } @@ -49,7 +50,9 @@ class UserControler { public function addComment(){ global $racine; $id = $_POST['idQuote']; - $this->cMod->createComment($_POST['content'],$_POST['idQuote'],$this->uMod->getIdByUsername($_SESSION['user'])); + $this->cMod->createComment(Verification::verifChar($_POST['content']), + Verification::verifChar($_POST['idQuote']), + $this->uMod->getIdByUsername(Verification::verifChar($_SESSION['user']))); header("Location:".$racine."/quote/$id"); } @@ -81,7 +84,7 @@ class UserControler { switch ($action) { case 'canswer': if ($this->CorrectAnswer()) - $_SESSION['score'] = isset($_SESSION['score']) ? ($_SESSION['score'] + 1) : 1; + $_SESSION['score'] = Verification::verifChar( isset( $_SESSION['score']) ? ($_SESSION['score'] + 1) : 1 ) ; $this->continueQuiz($id, $nb_questions); break; default: @@ -91,8 +94,8 @@ class UserControler { // page erreur break; default: - $_SESSION['score'] = $_SESSION['score'] ?? 0; - $this->showQuestion($id, $_SESSION['no_question'] ?? 0); + $_SESSION['score'] = Verification::verifChar($_SESSION['score'] ?? 0); + $this->showQuestion($id, Verification::verifChar($_SESSION['no_question'] ?? 0)); break; } } @@ -107,7 +110,7 @@ class UserControler { { global $racine; $score = $_SESSION['score']; - $_SESSION['no_question'] = isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1; + $_SESSION['no_question'] = Verification::verifChar( isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1); if ($_SESSION['no_question'] >= $total_questions) { session_destroy(); $this->endQuiz($id_quiz, $score); @@ -136,10 +139,10 @@ class UserControler { public function CorrectAnswer() : bool { - $answera = $_POST['answera'] ?? null; - $answerb = $_POST['answerb'] ?? null; - $answerc = $_POST['answerc'] ?? null; - $answerd = $_POST['answerd'] ?? null; + $answera = Verification::verifChar($_POST['answera'] ?? null); + $answerb = Verification::verifChar($_POST['answerb'] ?? null); + $answerc = Verification::verifChar($_POST['answerc'] ?? null); + $answerd = Verification::verifChar($_POST['answerd'] ?? null); $id= null; $answer = null; @@ -198,7 +201,7 @@ class UserControler { public function addFav(array $arg){ global $racine; $id= $arg['id'] ?? 1; - $this->uMod->addFavorite($_SESSION["user"],$id); + $this->uMod->addFavorite(Verification::verifChar($_SESSION["user"]),$id); header("Location:" . $racine . "/quote/$id"); } @@ -206,7 +209,7 @@ class UserControler { public function supFav(array $arg){ global $racine; $id= $arg['id'] ?? 1; - $this->uMod->supFavorite($_SESSION["user"],$id); + $this->uMod->supFavorite(Verification::verifChar($_SESSION["user"]),$id); header("Location:". $racine ."/quote/$id"); } } diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php index ccbc7f3..f8ab8ff 100644 --- a/src/Controleur/VisitorControler.php +++ b/src/Controleur/VisitorControler.php @@ -13,7 +13,7 @@ use Twig\Error\LoaderError; use Twig\Error\RuntimeError; use Twig\Error\SyntaxError; -use Verification\VerificationChar; +use Verification\Verification; Class VisitorControler { @@ -28,6 +28,7 @@ Class VisitorControler { private array $errors; + /** * @throws SyntaxError * @throws RuntimeError @@ -69,9 +70,9 @@ Class VisitorControler { public function search(array $arg){ global $vues; - $type = ($_POST['type'] ?? ""); - $search = ( VerificationChar::verifChar( $_POST['search'] ) ?? NULL); - $filtre = ($arg['filtre'] ?? []); + $type = ( Verification::verifChar( $_POST['type'] ?? "")); + $search = ( Verification::verifChar( $_POST['search'] ?? NULL)); + $filtre = ( Verification::verifArrayChar( $arg['filtre'] ?? [])); $tq=$this->sMod->searchQuote($type,$search,$filtre); @@ -116,8 +117,8 @@ Class VisitorControler { global $vues,$racine; if ($_POST) { - $pseudo = $_POST['pseudo'] ?? null; - $mdp = $_POST['mdp'] ?? null; + $pseudo = Verification::verifChar($_POST['pseudo'] ?? null); + $mdp = Verification::verifChar($_POST['mdp'] ?? null); $user = $this -> uMod -> getUsername($pseudo); @@ -157,10 +158,10 @@ Class VisitorControler { global $vues,$racine; if ($_POST) { - $pseudo = $_POST['pseudo'] ?? null; - $email = $_POST['email'] ?? null; - $mdp = $_POST['mdp'] ?? null; - $cmdp = $_POST['cmdp'] ?? null; + $pseudo = Verification::verifChar($_POST['pseudo'] ?? null); + $email = Verification::verifChar($_POST['email'] ?? null); + $mdp = Verification::verifChar($_POST['mdp'] ?? null); + $cmdp = Verification::verifChar($_POST['cmdp'] ?? null); if ($mdp != $cmdp) { $errors[2] = "Mots de passe incorrects"; @@ -192,8 +193,8 @@ Class VisitorControler { } else echo $this->uMod->insertUser($pseudo, $email, $hmdp); - $_SESSION["role"] = 'user'; - $_SESSION["user"] = $pseudo; + $_SESSION["role"] = Verification::verifChar('user'); + $_SESSION["user"] = Verification::verifChar($pseudo); header("Location: ". $racine); } diff --git a/src/Verification/Verification.php b/src/Verification/Verification.php new file mode 100644 index 0000000..a849265 --- /dev/null +++ b/src/Verification/Verification.php @@ -0,0 +1,44 @@ +','(',')']; + $chaineInterdi=["AND","OR","WHERE","FROM","SELECT"]; + $textVerif=""; + + foreach( str_split($text,1) as $char){ + if( !in_array($char,$charInterdi) ){ + $textVerif=$textVerif.$char; + } + } + + $text=$textVerif; + $textVerif=""; + $tabText=explode(" ",$text); + for( $i=0 ; $iverifChar($tabText[$i]); + } + return $tabText; + } + + } + +?> \ No newline at end of file diff --git a/src/Verification/VerificationChar.php b/src/Verification/VerificationChar.php deleted file mode 100644 index 44d46bd..0000000 --- a/src/Verification/VerificationChar.php +++ /dev/null @@ -1,19 +0,0 @@ - \ No newline at end of file diff --git a/vendor/autoload.php b/vendor/autoload.php index d1915e7..8890569 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -1,25 +1,25 @@ - - * Jordi Boggiano - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Composer\Autoload; - -/** - * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. - * - * $loader = new \Composer\Autoload\ClassLoader(); - * - * // register classes with namespaces - * $loader->add('Symfony\Component', __DIR__.'/component'); - * $loader->add('Symfony', __DIR__.'/framework'); - * - * // activate the autoloader - * $loader->register(); - * - * // to enable searching the include path (eg. for PEAR packages) - * $loader->setUseIncludePath(true); - * - * In this example, if you try to use a class in the Symfony\Component - * namespace or one of its children (Symfony\Component\Console for instance), - * the autoloader will first look for the class under the component/ - * directory, and it will then fallback to the framework/ directory if not - * found before giving up. - * - * This class is loosely based on the Symfony UniversalClassLoader. - * - * @author Fabien Potencier - * @author Jordi Boggiano - * @see https://www.php-fig.org/psr/psr-0/ - * @see https://www.php-fig.org/psr/psr-4/ - */ -class ClassLoader -{ - /** @var \Closure(string):void */ - private static $includeFile; - - /** @var string|null */ - private $vendorDir; - - // PSR-4 - /** - * @var array> - */ - private $prefixLengthsPsr4 = array(); - /** - * @var array> - */ - private $prefixDirsPsr4 = array(); - /** - * @var list - */ - private $fallbackDirsPsr4 = array(); - - // PSR-0 - /** - * List of PSR-0 prefixes - * - * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2'))) - * - * @var array>> - */ - private $prefixesPsr0 = array(); - /** - * @var list - */ - private $fallbackDirsPsr0 = array(); - - /** @var bool */ - private $useIncludePath = false; - - /** - * @var array - */ - private $classMap = array(); - - /** @var bool */ - private $classMapAuthoritative = false; - - /** - * @var array - */ - private $missingClasses = array(); - - /** @var string|null */ - private $apcuPrefix; - - /** - * @var array - */ - private static $registeredLoaders = array(); - - /** - * @param string|null $vendorDir - */ - public function __construct($vendorDir = null) - { - $this->vendorDir = $vendorDir; - self::initializeIncludeClosure(); - } - - /** - * @return array> - */ - public function getPrefixes() - { - if (!empty($this->prefixesPsr0)) { - return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); - } - - return array(); - } - - /** - * @return array> - */ - public function getPrefixesPsr4() - { - return $this->prefixDirsPsr4; - } - - /** - * @return list - */ - public function getFallbackDirs() - { - return $this->fallbackDirsPsr0; - } - - /** - * @return list - */ - public function getFallbackDirsPsr4() - { - return $this->fallbackDirsPsr4; - } - - /** - * @return array Array of classname => path - */ - public function getClassMap() - { - return $this->classMap; - } - - /** - * @param array $classMap Class to filename map - * - * @return void - */ - public function addClassMap(array $classMap) - { - if ($this->classMap) { - $this->classMap = array_merge($this->classMap, $classMap); - } else { - $this->classMap = $classMap; - } - } - - /** - * Registers a set of PSR-0 directories for a given prefix, either - * appending or prepending to the ones previously set for this prefix. - * - * @param string $prefix The prefix - * @param list|string $paths The PSR-0 root directories - * @param bool $prepend Whether to prepend the directories - * - * @return void - */ - public function add($prefix, $paths, $prepend = false) - { - $paths = (array) $paths; - if (!$prefix) { - if ($prepend) { - $this->fallbackDirsPsr0 = array_merge( - $paths, - $this->fallbackDirsPsr0 - ); - } else { - $this->fallbackDirsPsr0 = array_merge( - $this->fallbackDirsPsr0, - $paths - ); - } - - return; - } - - $first = $prefix[0]; - if (!isset($this->prefixesPsr0[$first][$prefix])) { - $this->prefixesPsr0[$first][$prefix] = $paths; - - return; - } - if ($prepend) { - $this->prefixesPsr0[$first][$prefix] = array_merge( - $paths, - $this->prefixesPsr0[$first][$prefix] - ); - } else { - $this->prefixesPsr0[$first][$prefix] = array_merge( - $this->prefixesPsr0[$first][$prefix], - $paths - ); - } - } - - /** - * Registers a set of PSR-4 directories for a given namespace, either - * appending or prepending to the ones previously set for this namespace. - * - * @param string $prefix The prefix/namespace, with trailing '\\' - * @param list|string $paths The PSR-4 base directories - * @param bool $prepend Whether to prepend the directories - * - * @throws \InvalidArgumentException - * - * @return void - */ - public function addPsr4($prefix, $paths, $prepend = false) - { - $paths = (array) $paths; - if (!$prefix) { - // Register directories for the root namespace. - if ($prepend) { - $this->fallbackDirsPsr4 = array_merge( - $paths, - $this->fallbackDirsPsr4 - ); - } else { - $this->fallbackDirsPsr4 = array_merge( - $this->fallbackDirsPsr4, - $paths - ); - } - } elseif (!isset($this->prefixDirsPsr4[$prefix])) { - // Register directories for a new namespace. - $length = strlen($prefix); - if ('\\' !== $prefix[$length - 1]) { - throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); - } - $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; - $this->prefixDirsPsr4[$prefix] = $paths; - } elseif ($prepend) { - // Prepend directories for an already registered namespace. - $this->prefixDirsPsr4[$prefix] = array_merge( - $paths, - $this->prefixDirsPsr4[$prefix] - ); - } else { - // Append directories for an already registered namespace. - $this->prefixDirsPsr4[$prefix] = array_merge( - $this->prefixDirsPsr4[$prefix], - $paths - ); - } - } - - /** - * Registers a set of PSR-0 directories for a given prefix, - * replacing any others previously set for this prefix. - * - * @param string $prefix The prefix - * @param list|string $paths The PSR-0 base directories - * - * @return void - */ - public function set($prefix, $paths) - { - if (!$prefix) { - $this->fallbackDirsPsr0 = (array) $paths; - } else { - $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; - } - } - - /** - * Registers a set of PSR-4 directories for a given namespace, - * replacing any others previously set for this namespace. - * - * @param string $prefix The prefix/namespace, with trailing '\\' - * @param list|string $paths The PSR-4 base directories - * - * @throws \InvalidArgumentException - * - * @return void - */ - public function setPsr4($prefix, $paths) - { - if (!$prefix) { - $this->fallbackDirsPsr4 = (array) $paths; - } else { - $length = strlen($prefix); - if ('\\' !== $prefix[$length - 1]) { - throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); - } - $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; - $this->prefixDirsPsr4[$prefix] = (array) $paths; - } - } - - /** - * Turns on searching the include path for class files. - * - * @param bool $useIncludePath - * - * @return void - */ - public function setUseIncludePath($useIncludePath) - { - $this->useIncludePath = $useIncludePath; - } - - /** - * Can be used to check if the autoloader uses the include path to check - * for classes. - * - * @return bool - */ - public function getUseIncludePath() - { - return $this->useIncludePath; - } - - /** - * Turns off searching the prefix and fallback directories for classes - * that have not been registered with the class map. - * - * @param bool $classMapAuthoritative - * - * @return void - */ - public function setClassMapAuthoritative($classMapAuthoritative) - { - $this->classMapAuthoritative = $classMapAuthoritative; - } - - /** - * Should class lookup fail if not found in the current class map? - * - * @return bool - */ - public function isClassMapAuthoritative() - { - return $this->classMapAuthoritative; - } - - /** - * APCu prefix to use to cache found/not-found classes, if the extension is enabled. - * - * @param string|null $apcuPrefix - * - * @return void - */ - public function setApcuPrefix($apcuPrefix) - { - $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; - } - - /** - * The APCu prefix in use, or null if APCu caching is not enabled. - * - * @return string|null - */ - public function getApcuPrefix() - { - return $this->apcuPrefix; - } - - /** - * Registers this instance as an autoloader. - * - * @param bool $prepend Whether to prepend the autoloader or not - * - * @return void - */ - public function register($prepend = false) - { - spl_autoload_register(array($this, 'loadClass'), true, $prepend); - - if (null === $this->vendorDir) { - return; - } - - if ($prepend) { - self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders; - } else { - unset(self::$registeredLoaders[$this->vendorDir]); - self::$registeredLoaders[$this->vendorDir] = $this; - } - } - - /** - * Unregisters this instance as an autoloader. - * - * @return void - */ - public function unregister() - { - spl_autoload_unregister(array($this, 'loadClass')); - - if (null !== $this->vendorDir) { - unset(self::$registeredLoaders[$this->vendorDir]); - } - } - - /** - * Loads the given class or interface. - * - * @param string $class The name of the class - * @return true|null True if loaded, null otherwise - */ - public function loadClass($class) - { - if ($file = $this->findFile($class)) { - $includeFile = self::$includeFile; - $includeFile($file); - - return true; - } - - return null; - } - - /** - * Finds the path to the file where the class is defined. - * - * @param string $class The name of the class - * - * @return string|false The path if found, false otherwise - */ - public function findFile($class) - { - // class map lookup - if (isset($this->classMap[$class])) { - return $this->classMap[$class]; - } - if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { - return false; - } - if (null !== $this->apcuPrefix) { - $file = apcu_fetch($this->apcuPrefix.$class, $hit); - if ($hit) { - return $file; - } - } - - $file = $this->findFileWithExtension($class, '.php'); - - // Search for Hack files if we are running on HHVM - if (false === $file && defined('HHVM_VERSION')) { - $file = $this->findFileWithExtension($class, '.hh'); - } - - if (null !== $this->apcuPrefix) { - apcu_add($this->apcuPrefix.$class, $file); - } - - if (false === $file) { - // Remember that this class does not exist. - $this->missingClasses[$class] = true; - } - - return $file; - } - - /** - * Returns the currently registered loaders keyed by their corresponding vendor directories. - * - * @return array - */ - public static function getRegisteredLoaders() - { - return self::$registeredLoaders; - } - - /** - * @param string $class - * @param string $ext - * @return string|false - */ - private function findFileWithExtension($class, $ext) - { - // PSR-4 lookup - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; - - $first = $class[0]; - if (isset($this->prefixLengthsPsr4[$first])) { - $subPath = $class; - while (false !== $lastPos = strrpos($subPath, '\\')) { - $subPath = substr($subPath, 0, $lastPos); - $search = $subPath . '\\'; - if (isset($this->prefixDirsPsr4[$search])) { - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); - foreach ($this->prefixDirsPsr4[$search] as $dir) { - if (file_exists($file = $dir . $pathEnd)) { - return $file; - } - } - } - } - } - - // PSR-4 fallback dirs - foreach ($this->fallbackDirsPsr4 as $dir) { - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { - return $file; - } - } - - // PSR-0 lookup - if (false !== $pos = strrpos($class, '\\')) { - // namespaced class name - $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) - . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); - } else { - // PEAR-like class name - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; - } - - if (isset($this->prefixesPsr0[$first])) { - foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { - if (0 === strpos($class, $prefix)) { - foreach ($dirs as $dir) { - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { - return $file; - } - } - } - } - } - - // PSR-0 fallback dirs - foreach ($this->fallbackDirsPsr0 as $dir) { - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { - return $file; - } - } - - // PSR-0 include paths. - if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { - return $file; - } - - return false; - } - - /** - * @return void - */ - private static function initializeIncludeClosure() - { - if (self::$includeFile !== null) { - return; - } - - /** - * Scope isolated include. - * - * Prevents access to $this/self from included files. - * - * @param string $file - * @return void - */ - self::$includeFile = \Closure::bind(static function($file) { - include $file; - }, null, null); - } -} + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + * @see https://www.php-fig.org/psr/psr-0/ + * @see https://www.php-fig.org/psr/psr-4/ + */ +class ClassLoader +{ + /** @var \Closure(string):void */ + private static $includeFile; + + /** @var string|null */ + private $vendorDir; + + // PSR-4 + /** + * @var array> + */ + private $prefixLengthsPsr4 = array(); + /** + * @var array> + */ + private $prefixDirsPsr4 = array(); + /** + * @var list + */ + private $fallbackDirsPsr4 = array(); + + // PSR-0 + /** + * List of PSR-0 prefixes + * + * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2'))) + * + * @var array>> + */ + private $prefixesPsr0 = array(); + /** + * @var list + */ + private $fallbackDirsPsr0 = array(); + + /** @var bool */ + private $useIncludePath = false; + + /** + * @var array + */ + private $classMap = array(); + + /** @var bool */ + private $classMapAuthoritative = false; + + /** + * @var array + */ + private $missingClasses = array(); + + /** @var string|null */ + private $apcuPrefix; + + /** + * @var array + */ + private static $registeredLoaders = array(); + + /** + * @param string|null $vendorDir + */ + public function __construct($vendorDir = null) + { + $this->vendorDir = $vendorDir; + self::initializeIncludeClosure(); + } + + /** + * @return array> + */ + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); + } + + return array(); + } + + /** + * @return array> + */ + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + /** + * @return list + */ + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + /** + * @return list + */ + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + /** + * @return array Array of classname => path + */ + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + * + * @return void + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param list|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + * + * @return void + */ + public function add($prefix, $paths, $prepend = false) + { + $paths = (array) $paths; + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param list|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + * + * @return void + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + $paths = (array) $paths; + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param list|string $paths The PSR-0 base directories + * + * @return void + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param list|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + * + * @return void + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + * + * @return void + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + * + * @return void + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + * + * @return void + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + * + * @return void + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + + if (null === $this->vendorDir) { + return; + } + + if ($prepend) { + self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders; + } else { + unset(self::$registeredLoaders[$this->vendorDir]); + self::$registeredLoaders[$this->vendorDir] = $this; + } + } + + /** + * Unregisters this instance as an autoloader. + * + * @return void + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + + if (null !== $this->vendorDir) { + unset(self::$registeredLoaders[$this->vendorDir]); + } + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return true|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + $includeFile = self::$includeFile; + $includeFile($file); + + return true; + } + + return null; + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { + return false; + } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if (false === $file && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { + // Remember that this class does not exist. + $this->missingClasses[$class] = true; + } + + return $file; + } + + /** + * Returns the currently registered loaders keyed by their corresponding vendor directories. + * + * @return array + */ + public static function getRegisteredLoaders() + { + return self::$registeredLoaders; + } + + /** + * @param string $class + * @param string $ext + * @return string|false + */ + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath . '\\'; + if (isset($this->prefixDirsPsr4[$search])) { + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); + foreach ($this->prefixDirsPsr4[$search] as $dir) { + if (file_exists($file = $dir . $pathEnd)) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + + return false; + } + + /** + * @return void + */ + private static function initializeIncludeClosure() + { + if (self::$includeFile !== null) { + return; + } + + /** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + * + * @param string $file + * @return void + */ + self::$includeFile = \Closure::bind(static function($file) { + include $file; + }, null, null); + } +} diff --git a/vendor/composer/LICENSE b/vendor/composer/LICENSE index 6256709..f27399a 100644 --- a/vendor/composer/LICENSE +++ b/vendor/composer/LICENSE @@ -1,21 +1,21 @@ - -Copyright (c) Nils Adermann, Jordi Boggiano - -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. - + +Copyright (c) Nils Adermann, Jordi Boggiano + +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. + diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 18f62d5..f135834 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -1,13 +1,13 @@ - $vendorDir . '/altorouter/altorouter/AltoRouter.php', - 'CURLStringFile' => $vendorDir . '/symfony/polyfill-php81/Resources/stubs/CURLStringFile.php', - 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', - 'ReturnTypeWillChange' => $vendorDir . '/symfony/polyfill-php81/Resources/stubs/ReturnTypeWillChange.php', -); + $vendorDir . '/altorouter/altorouter/AltoRouter.php', + 'CURLStringFile' => $vendorDir . '/symfony/polyfill-php81/Resources/stubs/CURLStringFile.php', + 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', + 'ReturnTypeWillChange' => $vendorDir . '/symfony/polyfill-php81/Resources/stubs/ReturnTypeWillChange.php', +); diff --git a/vendor/composer/autoload_files.php b/vendor/composer/autoload_files.php index 57f11ef..7498c74 100644 --- a/vendor/composer/autoload_files.php +++ b/vendor/composer/autoload_files.php @@ -1,17 +1,17 @@ - $vendorDir . '/symfony/deprecation-contracts/function.php', - '320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php', - '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php', - '23c18046f52bef3eea034657bafda50f' => $vendorDir . '/symfony/polyfill-php81/bootstrap.php', - '89efb1254ef2d1c5d80096acd12c4098' => $vendorDir . '/twig/twig/src/Resources/core.php', - 'ffecb95d45175fd40f75be8a23b34f90' => $vendorDir . '/twig/twig/src/Resources/debug.php', - 'c7baa00073ee9c61edf148c51917cfb4' => $vendorDir . '/twig/twig/src/Resources/escaper.php', - 'f844ccf1d25df8663951193c3fc307c8' => $vendorDir . '/twig/twig/src/Resources/string_loader.php', -); + $vendorDir . '/symfony/deprecation-contracts/function.php', + '320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php', + '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php', + '23c18046f52bef3eea034657bafda50f' => $vendorDir . '/symfony/polyfill-php81/bootstrap.php', + '89efb1254ef2d1c5d80096acd12c4098' => $vendorDir . '/twig/twig/src/Resources/core.php', + 'ffecb95d45175fd40f75be8a23b34f90' => $vendorDir . '/twig/twig/src/Resources/debug.php', + 'c7baa00073ee9c61edf148c51917cfb4' => $vendorDir . '/twig/twig/src/Resources/escaper.php', + 'f844ccf1d25df8663951193c3fc307c8' => $vendorDir . '/twig/twig/src/Resources/string_loader.php', +); diff --git a/vendor/composer/autoload_namespaces.php b/vendor/composer/autoload_namespaces.php index ff5488f..15a2ff3 100644 --- a/vendor/composer/autoload_namespaces.php +++ b/vendor/composer/autoload_namespaces.php @@ -1,9 +1,9 @@ - array($vendorDir . '/twig/twig/src'), - 'Symfony\\Polyfill\\Php81\\' => array($vendorDir . '/symfony/polyfill-php81'), - 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), - 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'), - 'Model\\' => array($baseDir . '/src/Model'), - 'Gateway\\' => array($baseDir . '/src/Gateway'), - 'Entity\\' => array($baseDir . '/src/Entity'), - 'Controleur\\' => array($baseDir . '/src/Controleur'), -); + array($baseDir . '/src/Verification'), + 'Twig\\' => array($vendorDir . '/twig/twig/src'), + 'Symfony\\Polyfill\\Php81\\' => array($vendorDir . '/symfony/polyfill-php81'), + 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), + 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'), + 'Model\\' => array($baseDir . '/src/Model'), + 'Gateway\\' => array($baseDir . '/src/Gateway'), + 'Entity\\' => array($baseDir . '/src/Entity'), + 'Controleur\\' => array($baseDir . '/src/Controleur'), +); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 605d150..fd08c64 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -1,50 +1,50 @@ -register(true); - - $filesToLoad = \Composer\Autoload\ComposerStaticInit68804b2111cb6b8bf6edf66cb2b4669c::$files; - $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { - if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { - $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; - - require $file; - } - }, null, null); - foreach ($filesToLoad as $fileIdentifier => $file) { - $requireFile($fileIdentifier, $file); - } - - return $loader; - } -} +register(true); + + $filesToLoad = \Composer\Autoload\ComposerStaticInit68804b2111cb6b8bf6edf66cb2b4669c::$files; + $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { + if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { + $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; + + require $file; + } + }, null, null); + foreach ($filesToLoad as $fileIdentifier => $file) { + $requireFile($fileIdentifier, $file); + } + + return $loader; + } +} diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index c1bdb2a..07f7271 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -1,100 +1,108 @@ - __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php', - '320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php', - '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', - '23c18046f52bef3eea034657bafda50f' => __DIR__ . '/..' . '/symfony/polyfill-php81/bootstrap.php', - '89efb1254ef2d1c5d80096acd12c4098' => __DIR__ . '/..' . '/twig/twig/src/Resources/core.php', - 'ffecb95d45175fd40f75be8a23b34f90' => __DIR__ . '/..' . '/twig/twig/src/Resources/debug.php', - 'c7baa00073ee9c61edf148c51917cfb4' => __DIR__ . '/..' . '/twig/twig/src/Resources/escaper.php', - 'f844ccf1d25df8663951193c3fc307c8' => __DIR__ . '/..' . '/twig/twig/src/Resources/string_loader.php', - ); - - public static $prefixLengthsPsr4 = array ( - 'T' => - array ( - 'Twig\\' => 5, - ), - 'S' => - array ( - 'Symfony\\Polyfill\\Php81\\' => 23, - 'Symfony\\Polyfill\\Mbstring\\' => 26, - 'Symfony\\Polyfill\\Ctype\\' => 23, - ), - 'M' => - array ( - 'Model\\' => 6, - ), - 'G' => - array ( - 'Gateway\\' => 8, - ), - 'E' => - array ( - 'Entity\\' => 7, - ), - 'C' => - array ( - 'Controleur\\' => 11, - ), - ); - - public static $prefixDirsPsr4 = array ( - 'Twig\\' => - array ( - 0 => __DIR__ . '/..' . '/twig/twig/src', - ), - 'Symfony\\Polyfill\\Php81\\' => - array ( - 0 => __DIR__ . '/..' . '/symfony/polyfill-php81', - ), - 'Symfony\\Polyfill\\Mbstring\\' => - array ( - 0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring', - ), - 'Symfony\\Polyfill\\Ctype\\' => - array ( - 0 => __DIR__ . '/..' . '/symfony/polyfill-ctype', - ), - 'Model\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/Model', - ), - 'Gateway\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/Gateway', - ), - 'Entity\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/Entity', - ), - 'Controleur\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/Controleur', - ), - ); - - public static $classMap = array ( - 'AltoRouter' => __DIR__ . '/..' . '/altorouter/altorouter/AltoRouter.php', - 'CURLStringFile' => __DIR__ . '/..' . '/symfony/polyfill-php81/Resources/stubs/CURLStringFile.php', - 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', - 'ReturnTypeWillChange' => __DIR__ . '/..' . '/symfony/polyfill-php81/Resources/stubs/ReturnTypeWillChange.php', - ); - - public static function getInitializer(ClassLoader $loader) - { - return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit68804b2111cb6b8bf6edf66cb2b4669c::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit68804b2111cb6b8bf6edf66cb2b4669c::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit68804b2111cb6b8bf6edf66cb2b4669c::$classMap; - - }, null, ClassLoader::class); - } -} + __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php', + '320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php', + '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', + '23c18046f52bef3eea034657bafda50f' => __DIR__ . '/..' . '/symfony/polyfill-php81/bootstrap.php', + '89efb1254ef2d1c5d80096acd12c4098' => __DIR__ . '/..' . '/twig/twig/src/Resources/core.php', + 'ffecb95d45175fd40f75be8a23b34f90' => __DIR__ . '/..' . '/twig/twig/src/Resources/debug.php', + 'c7baa00073ee9c61edf148c51917cfb4' => __DIR__ . '/..' . '/twig/twig/src/Resources/escaper.php', + 'f844ccf1d25df8663951193c3fc307c8' => __DIR__ . '/..' . '/twig/twig/src/Resources/string_loader.php', + ); + + public static $prefixLengthsPsr4 = array ( + 'V' => + array ( + 'Verification\\' => 13, + ), + 'T' => + array ( + 'Twig\\' => 5, + ), + 'S' => + array ( + 'Symfony\\Polyfill\\Php81\\' => 23, + 'Symfony\\Polyfill\\Mbstring\\' => 26, + 'Symfony\\Polyfill\\Ctype\\' => 23, + ), + 'M' => + array ( + 'Model\\' => 6, + ), + 'G' => + array ( + 'Gateway\\' => 8, + ), + 'E' => + array ( + 'Entity\\' => 7, + ), + 'C' => + array ( + 'Controleur\\' => 11, + ), + ); + + public static $prefixDirsPsr4 = array ( + 'Verification\\' => + array ( + 0 => __DIR__ . '/../..' . '/src/Verification', + ), + 'Twig\\' => + array ( + 0 => __DIR__ . '/..' . '/twig/twig/src', + ), + 'Symfony\\Polyfill\\Php81\\' => + array ( + 0 => __DIR__ . '/..' . '/symfony/polyfill-php81', + ), + 'Symfony\\Polyfill\\Mbstring\\' => + array ( + 0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring', + ), + 'Symfony\\Polyfill\\Ctype\\' => + array ( + 0 => __DIR__ . '/..' . '/symfony/polyfill-ctype', + ), + 'Model\\' => + array ( + 0 => __DIR__ . '/../..' . '/src/Model', + ), + 'Gateway\\' => + array ( + 0 => __DIR__ . '/../..' . '/src/Gateway', + ), + 'Entity\\' => + array ( + 0 => __DIR__ . '/../..' . '/src/Entity', + ), + 'Controleur\\' => + array ( + 0 => __DIR__ . '/../..' . '/src/Controleur', + ), + ); + + public static $classMap = array ( + 'AltoRouter' => __DIR__ . '/..' . '/altorouter/altorouter/AltoRouter.php', + 'CURLStringFile' => __DIR__ . '/..' . '/symfony/polyfill-php81/Resources/stubs/CURLStringFile.php', + 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', + 'ReturnTypeWillChange' => __DIR__ . '/..' . '/symfony/polyfill-php81/Resources/stubs/ReturnTypeWillChange.php', + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->prefixLengthsPsr4 = ComposerStaticInit68804b2111cb6b8bf6edf66cb2b4669c::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit68804b2111cb6b8bf6edf66cb2b4669c::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit68804b2111cb6b8bf6edf66cb2b4669c::$classMap; + + }, null, ClassLoader::class); + } +} diff --git a/vendor/composer/platform_check.php b/vendor/composer/platform_check.php index 5ffde28..4c3a5d6 100644 --- a/vendor/composer/platform_check.php +++ b/vendor/composer/platform_check.php @@ -1,26 +1,26 @@ -= 80100)) { - $issues[] = 'Your Composer dependencies require a PHP version ">= 8.1.0". You are running ' . PHP_VERSION . '.'; -} - -if ($issues) { - if (!headers_sent()) { - header('HTTP/1.1 500 Internal Server Error'); - } - if (!ini_get('display_errors')) { - if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { - fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL); - } elseif (!headers_sent()) { - echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL; - } - } - trigger_error( - 'Composer detected issues in your platform: ' . implode(' ', $issues), - E_USER_ERROR - ); -} += 80100)) { + $issues[] = 'Your Composer dependencies require a PHP version ">= 8.1.0". You are running ' . PHP_VERSION . '.'; +} + +if ($issues) { + if (!headers_sent()) { + header('HTTP/1.1 500 Internal Server Error'); + } + if (!ini_get('display_errors')) { + if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { + fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL); + } elseif (!headers_sent()) { + echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL; + } + } + trigger_error( + 'Composer detected issues in your platform: ' . implode(' ', $issues), + E_USER_ERROR + ); +} From 9ffb2a0636a7de287a20b185be5698a52dfc15ed Mon Sep 17 00:00:00 2001 From: beaulaton Date: Tue, 3 Dec 2024 09:17:35 +0100 Subject: [PATCH 03/13] Modif info user sur page profil --- src/Controleur/FrontControler.php | 5 ++- src/Controleur/UserControler.php | 45 ++++++++++++++++++++- src/Gateway/UserGateway.php | 61 ++++++++++++++++++++-------- src/Model/UserModel.php | 67 ++++++++++++++++++++++--------- 4 files changed, 141 insertions(+), 37 deletions(-) diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php index 42fae8d..cfd061a 100644 --- a/src/Controleur/FrontControler.php +++ b/src/Controleur/FrontControler.php @@ -13,7 +13,7 @@ Class FrontControler{ global $twig,$racine; $this->listAction = ['visitor' => array('accueil','search','quote','login','signin','validlogin','validsignin'), - 'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav'), + 'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata'), 'admin' => array('null')]; $dVueEreur = []; @@ -44,9 +44,10 @@ Class FrontControler{ $router->map('GET|POST', '/unlog', 'UserControler','unlog'); $router->map('GET|POST', '/signin', 'VisitorControler','signin'); $router->map('GET|POST', '/validlogin', 'VisitorControler','validlogin'); - $router->map('GET|POST', '/validsignin', 'VisitorControler','validsignin'); + $router->map('GET|POST', '/validsignin', 'VisitorControler','validsignin'); $router->map('GET|POST', '/addFav/[i:id]', 'UserControler','addFav'); $router->map('GET|POST', '/supFav/[i:id]', 'UserControler','supFav'); + $router->map('GET|POST', '/changedata', 'UserControler','changedata'); $match = $router->match(); diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 6f2fdf9..53269f6 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -41,7 +41,7 @@ class UserControler { public function profil() { global $vues; - $p = $this->uMod->getUsername(Verification::verifChar($_SESSION["user"])); + $p = $this->uMod->getUsername($_SESSION["user"]); require_once $vues['profil']; } @@ -212,4 +212,47 @@ class UserControler { $this->uMod->supFavorite(Verification::verifChar($_SESSION["user"]),$id); header("Location:". $racine ."/quote/$id"); } + + public function changedata() : void + { + global $vues; + if ($_POST) + { + $newPseudo = $_POST['pseudo'] ?? null; + $newEmail = $_POST['email'] ?? null; + $newMdpFirst = $_POST['passwdFirst'] ?? null; + $newMdpSecond = $_POST['passwdSecond'] ?? null; + + + + //Modif le pseudo + if($newPseudo){ + $user = $this-> uMod->setUsername($_SESSION['user'], $newPseudo); + if($user == $newPseudo){ //Si le pseudo existe déjà + $_SESSION['user'] = $newPseudo; + } + + } + + + + else if($newEmail){ + $user = $this-> uMod->setEmail($_SESSION['user'], $newEmail); + } + + + else if($newMdpFirst && $newMdpSecond){ + + if($newMdpFirst == $newMdpSecond){ + + $option = ['cost' => 12]; + $newPassWd = password_hash($newMdpFirst, PASSWORD_BCRYPT, $option); + $user = $this-> uMod->setPassWd($_SESSION['user'], $newPassWd); + } + } + + } + header("Location: /~lebeaulato/WF-Website/profil"); + + } } diff --git a/src/Gateway/UserGateway.php b/src/Gateway/UserGateway.php index a211518..38d55c1 100644 --- a/src/Gateway/UserGateway.php +++ b/src/Gateway/UserGateway.php @@ -89,33 +89,57 @@ Class UserGateway extends Gateway{ return $this->co->getResults(); } + public function IsExisteUsername(string $username): bool { + $query = 'SELECT COUNT(*) as count FROM Users WHERE username = :username'; + $this->co->executeQuery($query, array(':username' => array($username, PDO::PARAM_STR))); + $results = $this->co->getResults(); + + return $results[0]['count'] > 0; // retourne true si "count" > 0) + } + + public function IsExisteEmail(string $email): bool { + $query = 'SELECT COUNT(*) as count FROM Users WHERE email = :email'; + $this->co->executeQuery($query, array(':email' => array($email, PDO::PARAM_STR))); + $results = $this->co->getResults(); + + return $results[0]['count'] > 0; // retourne true si "count" > 0) + } + // ===================== UPDATE FUNCTION ===================== - public function updateUsername(int $id, string $newUsername):bool{ + //Update Username + public function updateUsername(string $username, string $newUsername):array{ //Update le nom du user passé en paramètre - $queryUpdate = 'UPDATE Users SET username=:newUsername WHERE id_user=:idUser'; - $this->co->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newUsername'=> array($newUsername, PDO::PARAM_STR))); + $queryUpdate = 'UPDATE Users SET username=:newUsername WHERE username=:username'; + $this->co->executeQuery($queryUpdate, array(':username'=>array($username, PDO::PARAM_STR), ':newUsername'=> array($newUsername, PDO::PARAM_STR))); //Renvoie le nouveau nom du user - $queryReponse = 'SELECT username FROM Users WHERE id_user=:idUser'; + $queryReponse = 'SELECT username FROM Users WHERE username=:idUser'; - return $this->co->executeQuery($queryReponse, array($id=>array($newUsername, PDO::PARAM_STR))); + $this->co->executeQuery($queryReponse, array(':idUser'=>array($newUsername, PDO::PARAM_STR))); + return $this->co->getResults(); } - public function updateEmail(int $id, string $newEmail):bool{ + + //Update Email + public function updateEmail(string $username, string $newEmail):array{ //Update le email du user passé en paramètre - $queryUpdate = 'UPDATE Users SET email=:newEmail WHERE id_user=:idUser'; - $this->co->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newEmail'=> array($newEmail, PDO::PARAM_STR))); + $queryUpdate = 'UPDATE Users SET email=:newEmail WHERE username=:username'; + $this->co->executeQuery($queryUpdate, array(':username'=>array($username, PDO::PARAM_STR), ':newEmail'=> array($newEmail, PDO::PARAM_STR))); //Renvoie le nouveau email du user - $queryReponse = 'SELECT email FROM Users WHERE id_user=:idUser'; - return $this->co->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR))); + $queryReponse = 'SELECT email FROM Users WHERE username=:username'; + + $this->co->executeQuery($queryReponse, array(':username'=>array($username, PDO::PARAM_STR))); + return $this->co->getResults(); } - public function updateImg(int $id, int $newImg):array{ + + + public function updateImg(string $username, int $newImg):array{ //Update l'image du user passé en paramètre - $query = 'UPDATE Users SET img_prfl=:newImg WHERE id_user=:idUser'; - $this->co->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newImg'=> array($newImg, PDO::PARAM_STR))); + $query = 'UPDATE Users SET img_prfl=:newImg WHERE username=:username'; + $this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR), ':newImg'=> array($newImg, PDO::PARAM_STR))); //Renvoie la nouvelle image du user $queryReponse = 'SELECT img_prfl FROM Users WHERE id_user=:idUser'; @@ -124,12 +148,17 @@ Class UserGateway extends Gateway{ return $result; } - public function updatePasswd(int $id, string $newPassWd):array{ + + public function updatePasswd(string $username, string $newPassWd):void{ //Update le passwd du user passé en paramètre - $query = 'UPDATE Users SET pssword=:newPassWd WHERE id_user=:idUser'; - $this->co->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newPassWd'=> array($newPassWd, PDO::PARAM_STR))); + $query = 'UPDATE Users SET password=:newPassWd WHERE username=:username'; + $this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR), ':newPassWd'=> array($newPassWd, PDO::PARAM_STR))); } + + + + public function getIdUser(string $username):array{ $query = 'SELECT id_user FROM Users WHERE username=:username'; $this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR))); diff --git a/src/Model/UserModel.php b/src/Model/UserModel.php index 41cffc0..6e79cd4 100644 --- a/src/Model/UserModel.php +++ b/src/Model/UserModel.php @@ -76,39 +76,64 @@ return null; } - public function setUsername(int $id, string $newUsername){ - $res = $this->gateway->updateUsername($id,$newUsername); - $src[] = $res[0]['username']; + public function IsExisteUsername(string $username):bool{ + return $this->gateway->IsExisteUsername($username); + } - return $src; + public function IsExisteEmail(string $email):bool{ + return $this->gateway->IsExisteEmail($email); } - public function setEmail(int $id, string $newEmail){ - $res = $this->gateway->updateEmail($id,$newEmail); - $src[] = $res[0]['email']; - return $src; + public function setUsername(string $username, string $newUsername): string { + + if ($this->IsExisteUsername($newUsername)) {// Vérifier si le nouveau nom d'utilisateur existe déjà + return $username;// Retourne l'ancien nom d'utilisateur sans modification + } + + $res = $this->gateway->updateUsername($username, $newUsername);// Sinon, mettre à jour le nom d'utilisateur + + // Retourner le nouveau nom d'utilisateur après modification + if (!empty($res) && isset($res[0]['username'])) { + return $res[0]['username']; + } + + // En cas d'échec, retourne l'ancien nom d'utilisateur + return $username; } + - public function setImg(int $id, int $newImg){ - $res = $this->gateway->updateImg($id,$newImg); - $src[] = $res[0]['img']; - return $src; + + public function setEmail(string $username, string $newEmail){ + if ($this->IsExisteEmail($newEmail)) { + return $email; + } + + $res = $this->gateway->updateEmail($username,$newEmail); + + if (!empty($res) && isset($res[0]['email'])) { + return $res[0]['email']; + } + + return $username;// En cas d'échec, retourne l'ancien email } - public function setPassWd(int $id, string $newPassWd){ - $res = $this->gateway->updatePasswd($id,$newPassWd); - $src[] = $res[0]['pssword']; + + + public function setImg(string $username, int $newImg){ + $res = $this->gateway->updateImg($id,$newImg); + $src[] = $res[0]['img']; return $src; } - public function getIdByUsername(string $username){ - $res = $this->gateway->getIdUser($username); - return $res[0]['id_user']; + public function setPassWd(string $username, string $newPassWd):void{ + $res = $this->gateway->updatePasswd($username,$newPassWd); } + + public function isFavorite(?string $username, int $idq): bool { if($_SESSION["user"] == NULL){ return false; @@ -119,6 +144,7 @@ } } + public function addFavorite(string $username, int $id){ $this->gateway->addFavorite($username,$id); } @@ -126,6 +152,11 @@ public function supFavorite(string $username, int $id){ $this->gateway->supFavorite($username,$id); } + + public function getIdByUsername(string $username){ + $res = $this->gateway->getIdUser($username); + return $res[0]['id_user']; + } } ?> From 7c48695319d1716343e84e8debe6019916800b4d Mon Sep 17 00:00:00 2001 From: beaulaton Date: Tue, 3 Dec 2024 09:32:29 +0100 Subject: [PATCH 04/13] Correction modif info user --- config/config.php | 2 +- public/script/changeData.js | 118 ++++++++++++++----------------- src/Controleur/UserControler.php | 2 - vue/templates/profil.html.twig | 38 +++++----- 4 files changed, 73 insertions(+), 87 deletions(-) diff --git a/config/config.php b/config/config.php index a351f18..4754cc4 100644 --- a/config/config.php +++ b/config/config.php @@ -12,7 +12,7 @@ $base = ''; $login = ''; $mdp = ''; -$racine='/~kekentin/WF/WF-Website'; +$racine='/~lebeaulato/WF-Website'; //Vues diff --git a/public/script/changeData.js b/public/script/changeData.js index e76bb9f..1b07955 100644 --- a/public/script/changeData.js +++ b/public/script/changeData.js @@ -1,78 +1,65 @@ +var racine = '/~lebeaulato/WF-Website'; + +//=============================== USERNAME =============================== function editFieldUsername(id) { - var pElement = document.getElementById(id);// Récupérer l'élément

via son identifiant - - var currentValue = pElement.textContent.trim();// Obtenir le texte actuel du

+ var pElement = document.getElementById(id); // Récupérer l'élément

via son identifiant + var currentValue = pElement.textContent.trim(); // Obtenir le texte actuel du

// Créer un champ de saisie avec la valeur actuelle var input = document.createElement('input'); input.type = 'text'; - input.value = currentValue - input.class = 'changeValue'; - - input.setAttribute('onblur', 'saveFieldUsername("' + id + '", this.value)'); // Sauvegarde lors de la perte de focus + input.value = currentValue; + input.class ='changeValue'; + input.name='pseudo'; + - // Remplacer le

par le champ + // Créer un bouton de validation + var button = document.createElement('button'); + button.textContent = 'Valider'; + button.classList.add('saveButtonPasswd'); + button.type ="submit"; + + // Remplacer le contenu du

par le champ et le bouton pElement.innerHTML = ''; pElement.appendChild(input); - + pElement.appendChild(button); + input.focus(); // Mettre le focus sur le champ de saisie } -//Sauvegarder les changements sur la vue pour le username -function saveFieldUsername(id, newValue) { - if (id === 'username') { - if (newValue.trim() === "") { - alert('Le nom d\'utilisateur ne peut pas être vide.'); - document.getElementById(id).querySelector('input').focus(); - return; // Ne pas sauvegarder si le nom d'utilisateur est vide - } - } - - var pElement = document.getElementById(id);// Récupérer l'élément

via son identifiant - - // Mettre à jour la valeur avec la nouvelle saisie - pElement.innerHTML = '' + newValue + ' '; -} +//=============================== EMAIL =============================== function editFieldEmail(id) { - var pElement = document.getElementById(id);// Récupérer l'élément

via son identifiant - var currentValue = pElement.textContent.trim();// Obtenir le texte actuel du

+ var pElement = document.getElementById(id); // Récupérer l'élément

via son identifiant + var currentValue = pElement.textContent.trim(); // Obtenir le texte actuel du

// Créer un champ de saisie avec la valeur actuelle var input = document.createElement('input'); input.type = 'email'; - input.value = currentValue - input.class = 'changeValue'; - - input.setAttribute('onblur', 'saveFieldEmail("' + id + '", this.value)'); // Sauvegarde lors de la perte de focus - - // Remplacer le

par le champ + input.value = currentValue; + input.class= 'changeValue'; // Correction de l'attribut 'class' + input.name='email'; + + + // Créer un bouton de validation + var button = document.createElement('button'); + button.textContent = 'Valider'; + button.classList.add('saveButtonPasswd'); + button.type ="submit"; + + + // Remplacer le contenu du

par le champ et le bouton pElement.innerHTML = ''; pElement.appendChild(input); - + pElement.appendChild(button); + input.focus(); // Mettre le focus sur le champ de saisie } -//Sauvegarder les changements sur la vue pour l'email -function saveFieldEmail(id, newValue) { - if (id === 'email') { - if (!validateEmail(newValue)) { - alert('Adresse email invalide. Veuillez entrer un email valide.'); - document.getElementById(id).querySelector('input').focus(); - return; // Ne pas sauvegarder si l'email n'est pas valide - } - } - - - var pElement = document.getElementById(id); // Récupérer l'élément

via son identifiant - - // Mettre à jour la valeur avec la nouvelle saisie - pElement.innerHTML = '' + newValue + ' '; -} @@ -86,7 +73,7 @@ function validateEmail(email) { - +//=============================== PASSWORD =============================== function editFieldPassWd(id) { @@ -101,7 +88,8 @@ function editFieldPassWd(id) { inputNewPass.classList.add('changeValue'); // Ajouter une classe CSS pour styliser l'input inputNewPass.setAttribute('id', 'newPassword'); // Ajouter un ID pour la gestion inputNewPass.classList.add('inputPasswd'); // Ajouter une classe au input - + inputNewPass.name='passwdFirst'; + // Créer le champ de saisie pour la confirmation du mot de passe var inputConfirmPass = document.createElement('input'); @@ -110,16 +98,19 @@ function editFieldPassWd(id) { inputConfirmPass.classList.add('changeValue'); // Ajouter une classe CSS pour styliser l'input inputConfirmPass.setAttribute('id', 'confirmPassword'); // Ajouter un ID pour la gestion inputConfirmPass.classList.add('inputPasswd'); // Ajouter une classe au input - + inputConfirmPass.name='passwdSecond'; + // Ajouter un bouton de sauvegarde var saveButton = document.createElement('button'); saveButton.textContent = 'Sauvegarder le mot de passe'; saveButton.classList.add('saveButtonPasswd'); // Ajouter une classe au bouton + saveButton.type="submit"; - saveButton.onclick = function() { + + /*saveButton.onclick = function() { savePasswordFields(id, inputNewPass.value, inputConfirmPass.value); - }; + };*/ // Ajouter les deux champs de saisie et le bouton dans l'élément

pElement.appendChild(inputNewPass); @@ -133,7 +124,8 @@ function editFieldPassWd(id) { -function savePasswordFields(id, newPassword, confirmPassword) { +/*function savePasswordFields(id, newPassword, confirmPassword) { + // Vérification si les champs sont vides if (newPassword.trim() === "" || confirmPassword.trim() === ""){ alert("Le mot de passe n'a pas changé"); @@ -141,18 +133,12 @@ function savePasswordFields(id, newPassword, confirmPassword) { // Vérification de la correspondance des deux mots de passe if (newPassword === confirmPassword) { - var pElement = document.getElementById(id);// Récupérer l'élément

via son identifiant - - - // Remplacer les champs input par le texte masqué - pElement.innerHTML ='Votre mot de passe'; - alert('Mot de passe mis à jour avec succès'); - - // fonction pour envoyer les nouveaux mots de passe au serveur - } else { alert('Les mots de passe ne correspondent pas.'); - } -} + } + + // Remplacer les champs input par le texte masqué + pElement.innerHTML ='Votre mot de passe'; +}*/ \ No newline at end of file diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 53269f6..7ee6375 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -234,8 +234,6 @@ class UserControler { } - - else if($newEmail){ $user = $this-> uMod->setEmail($_SESSION['user'], $newEmail); } diff --git a/vue/templates/profil.html.twig b/vue/templates/profil.html.twig index 26dc88b..2ed7129 100644 --- a/vue/templates/profil.html.twig +++ b/vue/templates/profil.html.twig @@ -2,32 +2,34 @@

From ad0aad0b1c1326457bcdef43475ae94176b5f864 Mon Sep 17 00:00:00 2001 From: tomivt Date: Tue, 19 Nov 2024 09:39:26 +0100 Subject: [PATCH 05/13] Ignorer les fichiers de configuration IDE --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ From be424fe0109a422e36af23e3af3cc9e96f0131fb Mon Sep 17 00:00:00 2001 From: beaulaton Date: Tue, 3 Dec 2024 14:11:20 +0100 Subject: [PATCH 06/13] Modif info psudo --- public/script/changeData.js | 45 ++------------------------------ src/Controleur/UserControler.php | 14 +++------- 2 files changed, 6 insertions(+), 53 deletions(-) diff --git a/public/script/changeData.js b/public/script/changeData.js index 1b07955..b270748 100644 --- a/public/script/changeData.js +++ b/public/script/changeData.js @@ -1,4 +1,4 @@ -var racine = '/~lebeaulato/WF-Website'; +var racine = '/~lebeaulato/WF-Website'; //Mettre votre chemin à vous //=============================== USERNAME =============================== @@ -32,7 +32,6 @@ function editFieldUsername(id) { //=============================== EMAIL =============================== - function editFieldEmail(id) { var pElement = document.getElementById(id); // Récupérer l'élément

via son identifiant var currentValue = pElement.textContent.trim(); // Obtenir le texte actuel du

@@ -61,24 +60,11 @@ function editFieldEmail(id) { } - - - -//Email valide -function validateEmail(email) { - var re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;// Regex pour vérifier le format de l'email - return re.test(String(email).toLowerCase()); -} - - - - //=============================== PASSWORD =============================== function editFieldPassWd(id) { var pElement = document.getElementById(id);// Récupérer l'élément

via son identifiant - pElement.innerHTML = '';// Effacer le contenu actuel de

pour insérer les inputs // Créer le champ de saisie pour le nouveau mot de passe @@ -106,12 +92,6 @@ function editFieldPassWd(id) { saveButton.classList.add('saveButtonPasswd'); // Ajouter une classe au bouton saveButton.type="submit"; - - /*saveButton.onclick = function() { - savePasswordFields(id, inputNewPass.value, inputConfirmPass.value); - - };*/ - // Ajouter les deux champs de saisie et le bouton dans l'élément

pElement.appendChild(inputNewPass); pElement.appendChild(document.createElement('br')); // Saut de ligne pour espacer les champs @@ -120,25 +100,4 @@ function editFieldPassWd(id) { pElement.appendChild(saveButton); inputNewPass.focus();// Mettre le focus sur le premier champ de saisie -} - - - -/*function savePasswordFields(id, newPassword, confirmPassword) { - - // Vérification si les champs sont vides - if (newPassword.trim() === "" || confirmPassword.trim() === ""){ - alert("Le mot de passe n'a pas changé"); - } - - // Vérification de la correspondance des deux mots de passe - if (newPassword === confirmPassword) { - var pElement = document.getElementById(id);// Récupérer l'élément

via son identifiant - - } else { - alert('Les mots de passe ne correspondent pas.'); - } - - // Remplacer les champs input par le texte masqué - pElement.innerHTML ='Votre mot de passe'; -}*/ \ No newline at end of file +} \ No newline at end of file diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 7ee6375..08d1bd7 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -223,22 +223,18 @@ class UserControler { $newMdpFirst = $_POST['passwdFirst'] ?? null; $newMdpSecond = $_POST['passwdSecond'] ?? null; - - //Modif le pseudo if($newPseudo){ $user = $this-> uMod->setUsername($_SESSION['user'], $newPseudo); - if($user == $newPseudo){ //Si le pseudo existe déjà - $_SESSION['user'] = $newPseudo; + + if($user == $_SESSION['user']){ //Si le pseudo existe déjà + $_SESSION['user'] = $user; + // echo ""; } - } - else if($newEmail){ $user = $this-> uMod->setEmail($_SESSION['user'], $newEmail); } - - else if($newMdpFirst && $newMdpSecond){ if($newMdpFirst == $newMdpSecond){ @@ -248,9 +244,7 @@ class UserControler { $user = $this-> uMod->setPassWd($_SESSION['user'], $newPassWd); } } - } header("Location: /~lebeaulato/WF-Website/profil"); - } } From dcdf95517d3084b8b395eb2763dd362fb838d8b2 Mon Sep 17 00:00:00 2001 From: beaulaton Date: Tue, 3 Dec 2024 14:45:41 +0100 Subject: [PATCH 07/13] pseudo --- src/Controleur/UserControler.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 08d1bd7..dfd0771 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -226,10 +226,9 @@ class UserControler { //Modif le pseudo if($newPseudo){ $user = $this-> uMod->setUsername($_SESSION['user'], $newPseudo); - - if($user == $_SESSION['user']){ //Si le pseudo existe déjà - $_SESSION['user'] = $user; - // echo ""; + + if($user == $newPseudo){ //Si le pseudo existe déjà + $_SESSION['user'] = $newPseudo; } } else if($newEmail){ From bcb2413cbd59f5bb5233a562db6fa39672181c3f Mon Sep 17 00:00:00 2001 From: beaulaton Date: Tue, 3 Dec 2024 15:02:34 +0100 Subject: [PATCH 08/13] =?UTF-8?q?Possibilit=C3=A9=20de=20changer=20l'image?= =?UTF-8?q?=20de=20profil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controleur/UserControler.php | 6 +++++- src/Gateway/UserGateway.php | 14 +++++++------- src/Model/UserModel.php | 12 ++++-------- vue/templates/profil.html.twig | 5 ++++- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index dfd0771..8a4b5b3 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -218,6 +218,7 @@ class UserControler { global $vues; if ($_POST) { + $newImage = $_POST['image'] ?? null; $newPseudo = $_POST['pseudo'] ?? null; $newEmail = $_POST['email'] ?? null; $newMdpFirst = $_POST['passwdFirst'] ?? null; @@ -226,7 +227,7 @@ class UserControler { //Modif le pseudo if($newPseudo){ $user = $this-> uMod->setUsername($_SESSION['user'], $newPseudo); - + if($user == $newPseudo){ //Si le pseudo existe déjà $_SESSION['user'] = $newPseudo; } @@ -243,6 +244,9 @@ class UserControler { $user = $this-> uMod->setPassWd($_SESSION['user'], $newPassWd); } } + else if($newImage){ + $user = $this->uMod->setImage($_SESSION['user']); + } } header("Location: /~lebeaulato/WF-Website/profil"); } diff --git a/src/Gateway/UserGateway.php b/src/Gateway/UserGateway.php index 38d55c1..9c13a25 100644 --- a/src/Gateway/UserGateway.php +++ b/src/Gateway/UserGateway.php @@ -136,16 +136,16 @@ Class UserGateway extends Gateway{ - public function updateImg(string $username, int $newImg):array{ + public function updateImg(string $username):array{ + $id_image = $this->randomImg(); //Update l'image du user passé en paramètre - $query = 'UPDATE Users SET img_prfl=:newImg WHERE username=:username'; - $this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR), ':newImg'=> array($newImg, PDO::PARAM_STR))); + $query = 'UPDATE Users SET img=:id_image WHERE username=:username'; + $this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR), ':id_image'=> array($id_image, PDO::PARAM_INT))); //Renvoie la nouvelle image du user - $queryReponse = 'SELECT img_prfl FROM Users WHERE id_user=:idUser'; - $this->co->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR))); - $result = $this->co->getResults(); - return $result; + $queryReponse = 'SELECT img FROM Users WHERE username=:username'; + $this->co->executeQuery($queryReponse, array(':username'=>array($username, PDO::PARAM_STR))); + return $this->co->getResults(); } diff --git a/src/Model/UserModel.php b/src/Model/UserModel.php index 6e79cd4..5f2a99d 100644 --- a/src/Model/UserModel.php +++ b/src/Model/UserModel.php @@ -103,8 +103,6 @@ } - - public function setEmail(string $username, string $newEmail){ if ($this->IsExisteEmail($newEmail)) { return $email; @@ -120,15 +118,13 @@ } - - - public function setImg(string $username, int $newImg){ - $res = $this->gateway->updateImg($id,$newImg); + public function setImage(string $username){ + $res = $this->gateway->updateImg($username); $src[] = $res[0]['img']; return $src; } - public function setPassWd(string $username, string $newPassWd):void{ + public function setPassWd(string $username, string $newPassWd):void{ $res = $this->gateway->updatePasswd($username,$newPassWd); } @@ -153,7 +149,7 @@ $this->gateway->supFavorite($username,$id); } - public function getIdByUsername(string $username){ + public function getIdByUsername(string $username){ $res = $this->gateway->getIdUser($username); return $res[0]['id_user']; } diff --git a/vue/templates/profil.html.twig b/vue/templates/profil.html.twig index 2ed7129..645a20d 100644 --- a/vue/templates/profil.html.twig +++ b/vue/templates/profil.html.twig @@ -3,7 +3,10 @@

▶ Profil ◀

- + + + +

{{ srcUsername }}

{{ srcEmail }}

From 06b17c2b1f7b7b82fbcfb86518c36d3ca9d0a58c Mon Sep 17 00:00:00 2001 From: tomivt Date: Tue, 3 Dec 2024 15:24:04 +0100 Subject: [PATCH 09/13] Add SubmitQuote branch content --- .DS_Store | Bin 8196 -> 8196 bytes composer.json | 3 +- config/config.php | 2 +- index.php | 3 +- public/styles/styleSubmitQuote.css | 76 ++++++++++++ src/Controleur/FrontControler.php | 11 +- src/Controleur/UserControler.php | 117 ++++++++++++++++-- src/Controleur/VisitorControler.php | 19 +-- .../{sourceEntity.php => SourceEntity.php} | 17 ++- src/Enum/TypeSourceEnum.php | 9 ++ src/Gateway/CharacterGateway.php | 26 ++-- src/Gateway/QuoteGateway.php | 111 ++++++++++------- .../{sourceGateway.php => SourceGateway.php} | 39 +++--- src/Gateway/UserGateway.php | 2 +- src/Model/CharacterModel.php | 18 +-- src/Model/QuoteModel.php | 6 + src/Model/UserModel.php | 8 +- src/Model/sourceModel.php | 65 +++++++--- vendor/composer/autoload_psr4.php | 1 + vendor/composer/autoload_static.php | 5 + vue/templates/recapSubmitQuote.html.twig | 51 ++++++++ vue/templates/submitQuote.html.twig | 63 ++++++++++ vue/test.php | 0 23 files changed, 511 insertions(+), 141 deletions(-) create mode 100644 public/styles/styleSubmitQuote.css rename src/Entity/{sourceEntity.php => SourceEntity.php} (75%) create mode 100644 src/Enum/TypeSourceEnum.php rename src/Gateway/{sourceGateway.php => SourceGateway.php} (67%) create mode 100644 vue/templates/recapSubmitQuote.html.twig create mode 100644 vue/templates/submitQuote.html.twig create mode 100644 vue/test.php diff --git a/.DS_Store b/.DS_Store index 754d5605686d90b2327bb0b20fc9190cc6f017b0..91512b42e1c19d7cd052cd733d37a9bff37b54af 100644 GIT binary patch delta 101 zcmZp1XmQxEU(lV4L60GwA(Np5h|?MJ81fm47*aiR@{^Nt@{<@C7zBWLJrL{t2Lm9B sfq@gKCj+P>ks%ofQyGdGiYMy`$xq%ds5N=NkjUnEAuXoOy&~n@0DaFJ{Qv*} delta 75 zcmZp1XmQxEUvRRjkQO&9Lo!1m5N9x?PBsvdm*fGmGZ{*NVkJO2pCOMy56G%uD4EPA ZB){2T$c}0AB$*=Si48oP*(Lt60|2-N66yc| diff --git a/composer.json b/composer.json index bfdad6b..40799b2 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "Model\\": "src/Model/", "Gateway\\": "src/Gateway/", "Entity\\": "src/Entity/", - "Verification\\": "src/Verification/" + "Verification\\": "src/Verification/", + "Enum\\": "src/Enum" } } } diff --git a/config/config.php b/config/config.php index 4754cc4..eb05e94 100644 --- a/config/config.php +++ b/config/config.php @@ -12,7 +12,7 @@ $base = ''; $login = ''; $mdp = ''; -$racine='/~lebeaulato/WF-Website'; +$racine=''; //Vues diff --git a/index.php b/index.php index a0bc58c..6b39b55 100644 --- a/index.php +++ b/index.php @@ -13,10 +13,9 @@ if(!isset($_SESSION['theme'])){ //chargement config require_once __DIR__ . '/config/config.php'; - require __DIR__ . '/vendor/autoload.php'; -$co = new \Gateway\Connection('pgsql:host=localhost;dbname=dbkekentin;', 'kekentin', 'passwd'); +$co = new \Gateway\Connection('pgsql:host=localhost;dbname=dbwikifantasy;', 'kiem', ''); //twig $loader = new \Twig\Loader\FilesystemLoader('vue/templates'); diff --git a/public/styles/styleSubmitQuote.css b/public/styles/styleSubmitQuote.css new file mode 100644 index 0000000..db65891 --- /dev/null +++ b/public/styles/styleSubmitQuote.css @@ -0,0 +1,76 @@ +@import url(./style.css); + +@import url('https://fonts.googleapis.com/css2?family=Lemon&display=swap'); + +body, html { + height: 100%; + overflow: hidden; +} + +/* ====== DARK MODE ====== */ +body.dark-mode h1, body.dark-mode h2, body.dark-mode p { + color: white; + font-family: "Lemon", serif; + text-align: center; +} + + +/* ====== LIGHT MODE ====== */ +body.light-mode h1, body.light-mode h2, body.light-mode p { + color: black; + font-family: "Lemon", serif; + text-align: center; +} + + +/* ====== OTHER ====== */ + +.header { + display: flex; + width: 100%; + height: 17%; + justify-content: space-between; + align-items: center; +} + +.nav img { + margin-right: 10px; +} + +.logo img { + display: block; + margin: 0 auto; +} + +.user img { + margin-left: 10px; +} + + +#form { + width: 80%; + height: 83%; + display: flex; + justify-content: center; + align-items: center; +} + +body.dark-mode #box { + background-color: #1b0048; + padding: 20px; + width: 50%; + margin: auto; + border-radius: 15px; + border: 1px solid #6100ff; +} + + +/* ====== DIVERS ====== */ +#contentField, #characterField, #sourceField, #imageField { +} + +#contentField p, #characterField p, #sourceField p, #imageField p { +} + +#confirm { +} \ No newline at end of file diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php index cfd061a..983bf49 100644 --- a/src/Controleur/FrontControler.php +++ b/src/Controleur/FrontControler.php @@ -5,15 +5,18 @@ use Gateway\Connection; Class FrontControler{ - private $listAction; + private array $listAction; private Connection $co; + /** + * @throws \Exception + */ public function __construct($co){ global $twig,$racine; $this->listAction = ['visitor' => array('accueil','search','quote','login','signin','validlogin','validsignin'), - 'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata'), + 'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata', 'submit', 'validsubmit'), 'admin' => array('null')]; $dVueEreur = []; @@ -44,10 +47,12 @@ Class FrontControler{ $router->map('GET|POST', '/unlog', 'UserControler','unlog'); $router->map('GET|POST', '/signin', 'VisitorControler','signin'); $router->map('GET|POST', '/validlogin', 'VisitorControler','validlogin'); - $router->map('GET|POST', '/validsignin', 'VisitorControler','validsignin'); + $router->map('GET|POST', '/validsignin', 'VisitorControler','validsignin'); $router->map('GET|POST', '/addFav/[i:id]', 'UserControler','addFav'); $router->map('GET|POST', '/supFav/[i:id]', 'UserControler','supFav'); $router->map('GET|POST', '/changedata', 'UserControler','changedata'); + $router->map('GET|POST', '/submit', 'UserControler', 'submit'); + $router->map('GET|POST', '/validsubmit', 'UserControler', 'validsubmit'); $match = $router->match(); diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 7ee6375..10b1606 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -1,27 +1,26 @@ = $total_questions) { - session_destroy(); + $_SESSION['no_question'] = 0; $this->endQuiz($id_quiz, $score); } else header("Location: ".$racine."/quiz/$id_quiz"); ///~kekentin/WF/WF-Website @@ -181,6 +180,7 @@ class UserControler { public function showQuestion(int $id, int $num) : void { global $vues; + global $twig; $q = $this->GetQuestion($id); $question = $q[$num] ?? $q[0]; $idquestion = $question->getIdQuestion(); @@ -223,22 +223,18 @@ class UserControler { $newMdpFirst = $_POST['passwdFirst'] ?? null; $newMdpSecond = $_POST['passwdSecond'] ?? null; - - //Modif le pseudo if($newPseudo){ $user = $this-> uMod->setUsername($_SESSION['user'], $newPseudo); if($user == $newPseudo){ //Si le pseudo existe déjà $_SESSION['user'] = $newPseudo; } - } else if($newEmail){ $user = $this-> uMod->setEmail($_SESSION['user'], $newEmail); } - else if($newMdpFirst && $newMdpSecond){ if($newMdpFirst == $newMdpSecond){ @@ -250,7 +246,104 @@ class UserControler { } } - header("Location: /~lebeaulato/WF-Website/profil"); + header("Location: /"); } + + /** + * @throws SyntaxError + * @throws RuntimeError + * @throws LoaderError + */ + public function submit() : void + { + global $twig; + echo $twig -> render("submitQuote.html.twig"); + } + + /** + * @throws SyntaxError + * @throws RuntimeError + * @throws LoaderError + */ + public function toSubmit() : ?array + { + global $co; + if ($_POST) + { + $content = $_POST['content'] ?? null; + $character = $_POST['character'] ?? null; + $source = $_POST['source'] ?? null; + //$img = $_POST['img'] ?? null; + + $errors = [null, null]; + + $gw = new CharacterGateway($co); + $mdl = new CharacterModel($gw); + + $character = $mdl -> getCharacterByName($character); + + $gw = new SourceGateway($co); + $mdl = new SourceModel($gw); + + $source = $mdl -> getSourceByTitle($source); + + if (!$character) + $errors[0] = "Personnage inexistant"; + if (!$source) + $errors[1] = "Source inexistante"; + if ($errors[0] || $errors[1]) + { + global $twig; + echo $twig->render("submitQuote.html.twig", ['errors' => $errors]); + exit(); + } + + $gw = new QuoteGateway($co); + $mdl = new QuoteModel($gw); + + $mdl -> insert4User($content, '/imgPath', 'fr', $this -> getIdOfUser(), $source->getIdSource(), $character->getIdCharacter()); + + return [$content, $_POST['character'], $_POST['source']]; + } + return null; + } + + /** + * @throws SyntaxError + * @throws RuntimeError + * @throws LoaderError + */ + public function validsubmit() : void + { + $recap = $this -> toSubmit(); + if ($recap) + { + $this -> recapSubmitQuote($recap); + } + } + + /** + * @throws RuntimeError + * @throws SyntaxError + * @throws LoaderError + */ + public function recapSubmitQuote(?array $recap) : void + { + global $twig; + echo $twig -> render("recapSubmitQuote.html.twig", ['content' => $recap[0], 'character' => $recap[1], 'source' => $recap[2]]); + } + + public function getIdOfUser() : ?int + { + if (isset($_SESSION['user'])) + { + global $co; + $gw = new UserGateway($co); + $mdl = new UserModel($gw); + + return $mdl -> getUsername($_SESSION['user']) -> getId(); + } + return null; + } } diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php index f8ab8ff..6c5481e 100644 --- a/src/Controleur/VisitorControler.php +++ b/src/Controleur/VisitorControler.php @@ -87,14 +87,14 @@ Class VisitorControler { */ public function login() { - global $vues; - require_once $vues['login']; + //global $vues; + //require_once $vues['login']; - // global $twig; + global $twig; - // echo $twig->render("login.html.twig"); + echo $twig->render("login.html.twig"); - //$this -> toLogIn(); + $this -> toLogIn(); } /** @@ -104,12 +104,15 @@ Class VisitorControler { */ public function signin(): void { - global $vues; - require_once $vues['signin']; - } + //global $vues; + //require_once $vues['signin']; + global $twig; + echo $twig->render("login.html.twig"); + $this -> signin(); + } public function validlogin() : void diff --git a/src/Entity/sourceEntity.php b/src/Entity/SourceEntity.php similarity index 75% rename from src/Entity/sourceEntity.php rename to src/Entity/SourceEntity.php index 8a41c86..358d8a1 100644 --- a/src/Entity/sourceEntity.php +++ b/src/Entity/SourceEntity.php @@ -1,6 +1,8 @@ id_source = $id_source; $this->title = $title; $this->date = $date; + $this->type = $type; } /** @@ -69,9 +74,15 @@ class SourceEntity $this->date = $date; } + public function getType(): TypeSourceEnum + { + return $this->type; + } - - + public function setType(TypeSourceEnum $type): void + { + $this->type = $type; + } } diff --git a/src/Enum/TypeSourceEnum.php b/src/Enum/TypeSourceEnum.php new file mode 100644 index 0000000..dbc5bfa --- /dev/null +++ b/src/Enum/TypeSourceEnum.php @@ -0,0 +1,9 @@ + co -> executeQuery($query, [ - 'id_char' => array($id_character, PDO::PARAM_INT), - 'name' => array($name, PDO::PARAM_STR), - 'img_char' => array($img_char, PDO::PARAM_STR) + 'id_caracter' => array($id_character, PDO::PARAM_INT), + 'caracter' => array($name, PDO::PARAM_STR), + 'id_img' => array($img_char, PDO::PARAM_STR) ]); } public function findById(int $id) : array { - $query = "SELECT * FROM Characters WHERE id_char = :id_c"; + $query = "SELECT * FROM caracter WHERE id_caracter = :id_c"; $this -> co -> executeQuery($query, ["id_c" => array($id, PDO::PARAM_INT)]); return $this -> co -> getResults(); } public function findByName(string $name) : array { - $query = "SELECT * FROM Characters WHERE name = :n"; + $query = "SELECT * FROM caracter WHERE caracter = :n"; $this -> co -> executeQuery($query, ["n" => array($name, PDO::PARAM_STR)]); return $this -> co -> getResults(); } public function findAll() : array { - $query = "SELECT * FROM Characters"; + $query = "SELECT * FROM caracter"; $this -> co -> executeQuery($query); return $this -> co -> getResults(); } public function delete(int $id) : bool { - $query = "DELETE FROM Characters WHERE id_char = :id_c"; + $query = "DELETE FROM caracter WHERE id_caracter = :id_c"; return $this -> co -> executeQuery($query, ["id_c" => array($id, PDO::PARAM_INT)]); } public function update(int $id_char, string $name, string $img_char) : bool { $query = " - UPDATE Characters - SET name = :n, img_char = :i - WHERE id_char = :id_c + UPDATE caracter + SET caracter = :n, id_img = :i + WHERE id_caracter = :id_c "; return $this -> co -> executeQuery($query, [ "id_c" => array($id_char, PDO::PARAM_INT), - "name" => array($name, PDO::PARAM_STR), + "caracter" => array($name, PDO::PARAM_STR), "i" => array($img_char, PDO::PARAM_STR) ]); } diff --git a/src/Gateway/QuoteGateway.php b/src/Gateway/QuoteGateway.php index c6bdc91..db88697 100644 --- a/src/Gateway/QuoteGateway.php +++ b/src/Gateway/QuoteGateway.php @@ -1,22 +1,21 @@ co->executeQuery($query,array(':quote' => array($quote,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR))); - $result=$this->co->getResults(); - return $result; + $query="SELECT q.id_quote, q.content, c.id_char, c.img_char, s.title, s.date, q.likes, q.langue FROM Quote q JOIN Characters c ON c.id_char = q.character JOIN Source s ON s.id_source = q.id_source WHERE content LIKE '%:quote%' AND is_valid = true AND langue = :langue LIMIT 20 OFFSET :page*20;"; + $this->co->executeQuery($query,array(':quote' => array($quote,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':langue' => array($language,PDO::PARAM_STR))); + return $this->co->getResults(); } public function searchSource(string $source,int $numpage,string $language):array{ //recherche par source - $query="SELECT q.id_quote, q.content, c.caracter, c.img_path, s.title, s.date, q.like, q.language FROM Quote q JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source WHERE s.title LIKE '%:source%' AND q.isValid = true AND language = :language LIMIT 20 OFFSET :page*20;"; - $this->co->executeQuery($query,array(':source' => array($source,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR))); + $query="SELECT q.id_quote, q.content, c.character, c.img_path, s.title, s.date, q.likes, q.langue FROM Quote q JOIN Characters c ON c.id_char = q.character JOIN Source s ON s.id_source = q.id_source WHERE s.title LIKE '%:source%' AND q.is_valid = true AND langue = :langue LIMIT 20 OFFSET :page*20;"; + $this->co->executeQuery($query,array(':source' => array($source,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':langue' => array($language,PDO::PARAM_STR))); $result=$this->co->getResults(); return $result; } @@ -24,8 +23,8 @@ Class QuoteGateway extends Gateway{ public function searchPers(string $Carac,int $numpage,string $language):array{ //recherche par personnage - $query="SELECT q.id_quote, q.content, c.caracter, c.img_path, s.title, s.date, q.like, q.language FROM Quote q JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source WHERE c.caracter LIKE '%:pers%' AND q.isValid = true AND language = :language LIMIT 20 OFFSET :page*20;"; - $this->co->executeQuery($query,array(':pers' => array($Pers,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR))); + $query="SELECT q.id_quote, q.content, c.character, c.img_path, s.title, s.date, q.likes, q.langue FROM Quote q JOIN Characters c ON c.id_char = q.character JOIN Source s ON s.id_source = q.id_source WHERE c.character LIKE '%:pers%' AND q.is_valid = true AND langue = :langue LIMIT 20 OFFSET :page*20;"; + $this->co->executeQuery($query,array(':pers' => array($Pers,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':langue' => array($language,PDO::PARAM_STR))); $result=$this->co->getResults(); return $result; } @@ -33,7 +32,7 @@ Class QuoteGateway extends Gateway{ public function searchId(string $id):array{ //recherche par id - $query="SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dates, q.likes, q.langue FROM Quote q JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source JOIN Image i ON c.id_img = i.id_img WHERE q.id_quote = :id AND q.isvalide = true;"; + $query="SELECT q.id_quote, q.content, c.character, i.imgPath, s.title, s.dates, q.likes, q.langue FROM Quote q JOIN Characters c ON c.id_char = q.character JOIN Source s ON s.id_source = q.id_source JOIN Image i ON c.id_img = i.id_img WHERE q.id_quote = :id AND q.isvalide = true;"; $this->co->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR))); $result=$this->co->getResults(); return $result; @@ -42,11 +41,11 @@ Class QuoteGateway extends Gateway{ public function search(?string $type,?string $search,array $filtre):array{ $query="SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dates, q.likes, q.langue FROM Quote q - JOIN Caracter c ON c.id_caracter = q.id_caracter + JOIN Characters c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source JOIN Image i ON c.id_img = i.id_img WHERE lower("; - + if($type=='personnage'){ $query = $query . "c.caracter) LIKE lower('%" . $search . "%')"; } @@ -62,7 +61,7 @@ Class QuoteGateway extends Gateway{ }*/ $this->co->executeQuery($query,array()); - + $result=$this->co->getResults(); return $result; } @@ -71,7 +70,7 @@ Class QuoteGateway extends Gateway{ $query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue FROM DailyQuote dq JOIN Quote q ON dq.citation_id = q.id_quote - JOIN Caracter c ON c.id_caracter = q.id_caracter + JOIN Characters c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source JOIN Image i ON c.id_img = i.id_img WHERE q.isValide = true AND q.langue = :language @@ -85,14 +84,14 @@ Class QuoteGateway extends Gateway{ echo "Erreur dans getQuoteOfTheDay: " . $e->getMessage(); return []; } - } + } + - public function getSuggestions(int $numpage, string $language): array { $query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue FROM Quote q - JOIN Caracter c ON c.id_caracter = q.id_caracter + JOIN Characters c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source JOIN Image i ON c.id_img = i.id_img WHERE q.isValide = true AND q.langue = :language @@ -110,7 +109,7 @@ Class QuoteGateway extends Gateway{ $query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue FROM Favorite f JOIN Quote q ON f.quote = q.id_quote - JOIN Caracter c ON c.id_caracter = q.id_caracter + JOIN Characters c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source JOIN Image i ON c.id_img = i.id_img WHERE f.users = :userId"; @@ -126,6 +125,32 @@ Class QuoteGateway extends Gateway{ } } + public function autoincrement() : int + { + $query = "SELECT Max(id_quote) + 1 as id FROM Quote;"; + $this->co->executeQuery($query); + return ($this -> co ->getResults())[0]['id']; + } + + public function insert4User(string $content, string $img_path, string $langage, int $user, int $source, int $character) : bool + { + $query = " + INSERT INTO Quote (id_quote, content, langue, reason, id_source, id_caracter, id_user_verif, img_path) + VALUES (:id, :content, :langage, :reason, :source, :character, :user, :img_path) + "; + + return $this->co->executeQuery($query, [ + ':id' => array($this->autoincrement(), PDO::PARAM_INT), + ':content' => array($content, PDO::PARAM_STR), + ':img_path' => array($img_path, PDO::PARAM_STR), + ':langage' => array($langage, PDO::PARAM_STR), + ':user' => array($user, PDO::PARAM_INT), + ':reason' => array('À vérifier', PDO::PARAM_STR), + ':source' => array($source, PDO::PARAM_STR), + ':character' => array($character, PDO::PARAM_STR) + ]); + } + //======================== PARTI ADMIN ======================== //Probablement à déplacer dans un autre fichier @@ -133,8 +158,7 @@ Class QuoteGateway extends Gateway{ //obtenir les quotes en attentes de validation par l'admin $query = 'SELECT * FROM Quote WHERE isValid=:bool'; $this->co->executeQuery($query,array(':bool' => array(false, PDO::PARAM_BOOL))); - $result=$this->co->getResults(); - return $result; + return $this->co->getResults(); } public function validQuote(int $id){ @@ -152,61 +176,56 @@ Class QuoteGateway extends Gateway{ public function updateContent(int $id, string $newContent):array{ //Update le contexte de quote passé en paramètre $queryUpdate = 'UPDATE Quote SET content=:newContent WHERE id_quote=:idQuote'; - $con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newContent'=> array($newContent, PDO::PARAM_STR))); + $this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newContent'=> array($newContent, PDO::PARAM_STR))); //Renvoie le nouveau contexte de quote - $queryReponse = 'SELECT content FROM Quote WHERE id_quote=:idQuote'; - $con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR))); - $result = $con->getResults(); - return $result; + $queryReponse = 'SELECT content FROM Quote WHERE id_quote=:idQuote'; + $this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR))); + return $this->co->getResults(); } public function updateTimeCode(int $id, string $newTimeCode):array{ //Update le time code de quote passé en paramètre $queryUpdate = 'UPDATE Quote SET timecode=:newTimeCode WHERE id_quote=:idQuote'; - $con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newTimeCode'=> array($newTimeCode, PDO::PARAM_STR))); + $this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newTimeCode'=> array($newTimeCode, PDO::PARAM_STR))); //Renvoie le nouveau contexte de quote - $queryReponse = 'SELECT timecode FROM Quote WHERE id_quote=:idQuote'; - $con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR))); - $result = $con->getResults(); - return $result; + $queryReponse = 'SELECT timecode FROM Quote WHERE id_quote=:idQuote'; + $this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR))); + return $this->co->getResults(); } public function updateDate(int $id, int $newDate):array{ //Update la date de quote passé en paramètre $queryUpdate = 'UPDATE Source SET dateSource =:newdate WHERE idSource = (SELECT idSource FROM Quote WHERE idQuote =:idQuote)'; - $con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newDate'=> array($newDate, PDO::PARAM_INT))); + $this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newDate'=> array($newDate, PDO::PARAM_INT))); //Renvoie la nouvelle date de quote - $queryReponse = 'SELECT s.dateSource FROM Source s, Quote q WHERE id_quote=:idQuote AND s.idSource = q.idSource'; - $con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR))); - $result = $con->getResults(); - return $result; + $queryReponse = 'SELECT s.dateSource FROM Source s, Quote q WHERE id_quote=:idQuote AND s.idSource = q.idSource'; + $this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR))); + return $this->co->getResults(); } public function updateTitle(int $id, string $newTitle):array{ //Update le titre de l'oeuvre de quote passé en paramètre $queryUpdate = 'UPDATE Source SET title =:newTitle WHERE idSource = (SELECT idSource FROM Quote WHERE idQuote =:idQuote)'; - $con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newTitle'=> array($newTitle, PDO::PARAM_STR))); + $this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newTitle'=> array($newTitle, PDO::PARAM_STR))); //Renvoie le nouveau titre de quote - $queryReponse = 'SELECT s.title FROM Source s, Quote q WHERE id_quote=:idQuote AND s.idSource = q.idSource'; - $con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR))); - $result = $con->getResults(); - return $result; + $queryReponse = 'SELECT s.title FROM Source s, Quote q WHERE id_quote=:idQuote AND s.idSource = q.idSource'; + $this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR))); + return $this->co->getResults(); } public function updateNameCharacter(int $id, string $newNameCharacter):array{ //Update le personnage de l'oeuvre de quote passé en paramètre $queryUpdate = 'UPDATE Character SET name =:newNameCharacter WHERE idCharacter = (SELECT idCharacter FROM Quote WHERE idQuote =:idQuote)'; - $con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newNameCharacter'=> array($newNameCharacter, PDO::PARAM_STR))); + $this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newNameCharacter'=> array($newNameCharacter, PDO::PARAM_STR))); //Renvoie le nouveau personnage de quote - $queryReponse = 'SELECT c.title FROM Character c, Quote q WHERE id_quote=:idQuote AND c.idCharacter = q.idCharacter'; - $con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR))); - $result = $con->getResults(); - return $result; + $queryReponse = 'SELECT c.title FROM Character c, Quote q WHERE id_quote=:idQuote AND c.idCharacter = q.idCharacter'; + $this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR))); + return $this->co->getResults(); } } diff --git a/src/Gateway/sourceGateway.php b/src/Gateway/SourceGateway.php similarity index 67% rename from src/Gateway/sourceGateway.php rename to src/Gateway/SourceGateway.php index a746ec8..c361a1b 100644 --- a/src/Gateway/sourceGateway.php +++ b/src/Gateway/SourceGateway.php @@ -1,20 +1,22 @@ co -> executeQuery($query, [ - "id_source" => array($s->getIdSource(), PDO::PARAM_INT), - "title" => array($s->getTitle(), PDO::PARAM_STR), - "date" => array($s->getDate(), PDO::PARAM_STR) + "title" => array($title, PDO::PARAM_STR), + "date" => array($date, PDO::PARAM_STR), + "type" => array($type, PDO::PARAM_STR) ]); } @@ -30,7 +32,7 @@ class SourceGateway extends Gateway{ { $query = "SELECT * FROM Source WHERE title = :t"; - $this -> co -> executeQuery($query, ["title" => array($t, PDO::PARAM_STR)]); + $this -> co -> executeQuery($query, ["t" => array($t, PDO::PARAM_STR)]); return $res = $this -> co -> getResults(); // if ($res) @@ -44,18 +46,18 @@ class SourceGateway extends Gateway{ public function findByDate(string $d) : array { - $query = "SELECT * FROM Source WHERE date = :d"; + $query = "SELECT * FROM Source WHERE dates = :d"; $this -> co -> executeQuery($query, ["date" => array($d, PDO::PARAM_STR)]); - $res = $this -> co -> getResults(); + return $this -> co -> getResults(); + } - if ($res) - return new sourceEntity( - $res["id_source"], - $res["title"], - $res["date"] - ); - return null; + public function findByType(TypeSourceEnum $type) : array + { + $query = "SELECT * FROM Source WHERE type = :t"; + + $this -> co -> executeQuery($query, ["t" => array($type, PDO::PARAM_STR)]); + return $this -> co -> getResults(); } public function findAll() : array @@ -71,7 +73,8 @@ class SourceGateway extends Gateway{ $sources[] = new sourceEntity( $source["id_source"], $source["title"], - $source["date"] + $source["date"], + $res["source"] ); } return $sources; diff --git a/src/Gateway/UserGateway.php b/src/Gateway/UserGateway.php index 38d55c1..cdbb328 100644 --- a/src/Gateway/UserGateway.php +++ b/src/Gateway/UserGateway.php @@ -78,7 +78,7 @@ Class UserGateway extends Gateway{ // obtenir les informations d'un user selon son pseudo public function findUsername(string $username):array{ - $query = 'SELECT u.id_user , u.username , u.email , u.password , i.imgPath , u.creation FROM Users u Join Image i on i.id_img=u.img WHERE username= :username'; + $query = 'SELECT * FROM Users u Join Image i on i.id_img=u.img WHERE username= :username'; $this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR))); return $this->co->getResults(); } diff --git a/src/Model/CharacterModel.php b/src/Model/CharacterModel.php index 53eb21c..fa1e074 100644 --- a/src/Model/CharacterModel.php +++ b/src/Model/CharacterModel.php @@ -19,9 +19,9 @@ class CharacterModel extends Model $c = $this -> gateway -> findById($id_character); if ($c) return new CharacterEntity( - $c['id_character'], - $c['name'], - $c['img_path'] + $c['id_caracter'], + $c['caracter'], + $c['id_img'] ); return null; } @@ -31,9 +31,9 @@ class CharacterModel extends Model $c = $this -> gateway -> findByName($name); if ($c) return new CharacterEntity( - $c[0]['id_character'], - $c[0]['name'], - $c[0]['img_path'] + $c[0]['id_caracter'], + $c[0]['caracter'], + $c[0]['id_img'] ); return null; } @@ -47,9 +47,9 @@ class CharacterModel extends Model foreach ($c as $character) { $characters[] = new CharacterEntity( - $character['id_character'], - $character['name'], - $character['img_path'] + $character['id_caracter'], + $character['caracter'], + $character['id_img'] ); } return $characters; diff --git a/src/Model/QuoteModel.php b/src/Model/QuoteModel.php index 38f336f..9c09b28 100644 --- a/src/Model/QuoteModel.php +++ b/src/Model/QuoteModel.php @@ -42,6 +42,12 @@ } return $tabQ; } + + public function insert4User(string $content, string $img_path, string $langage, int $user, int $source, int $character) : bool + { + return $this->gateway->insert4User($content, $img_path, $langage, $user, $source, $character); + } + } ?> diff --git a/src/Model/UserModel.php b/src/Model/UserModel.php index 6e79cd4..348ad86 100644 --- a/src/Model/UserModel.php +++ b/src/Model/UserModel.php @@ -38,8 +38,8 @@ return new UserEntity( $res[0]['id_user'], $res[0]['username'], - $res[0]['password'], $res[0]['email'], + $res[0]['password'], $res[0]['img'], $res[0]['creation'] ); @@ -53,9 +53,9 @@ return new UserEntity( $res[0]['id_user'], $res[0]['username'], - $res[0]['password'], $res[0]['email'], - $res[0]['imgpath'], + $res[0]['password'], + $res[0]['img'], $res[0]['creation'] ); return null; @@ -68,8 +68,8 @@ return new UserEntity( $res[0]['id_user'], $res[0]['username'], - $res[0]['password'], $res[0]['email'], + $res[0]['password'], $res[0]['img'], $res[0]['creation'] ); diff --git a/src/Model/sourceModel.php b/src/Model/sourceModel.php index 9430baa..9c54006 100644 --- a/src/Model/sourceModel.php +++ b/src/Model/sourceModel.php @@ -1,17 +1,14 @@ gateway -> create($q); + return $this -> gateway -> create($title, $date, $type); } public function getSourceById(int $id_source) : ?SourceEntity @@ -22,40 +19,68 @@ class SourceModel extends Model return new sourceEntity( $res[0]["id_source"], $res[0]["title"], - $res[0]["date"] + $res[0]["dates"], + TypeSourceEnum::from($res[0]["type"]) ); return null; } - public function getSourceByTitle(string $title) : array + public function getSourceByTitle(string $title) : ?SourceEntity { $res = $this->gateway->findByTitle($title); + if ($res) + return new sourceEntity( + $res[0]["id_source"], + $res[0]["title"], + $res[0]["dates"], + TypeSourceEnum::from($res[0]["type"]) + ); + return null; + } + + public function getSourceByDate(string $date) : array + { + $res = $this->gateway->findByDate($date); + $src = []; foreach ($res as $sources) { $src[] = new sourceEntity( - $sources["id_source"], - $sources["title"], - $sources["date"] - ); + $sources["id_source"], + $sources["title"], + $sources["dates"], + TypeSourceEnum::from($sources["type"]) + ); } return $src; } - public function getSourceByDate(string $date) : array + public function getSourceByType(TypeSourceEnum $type) : array { - $res = $this->gateway->findByDate($date); + $res = $this->gateway->findByType($type); + $src = []; foreach ($res as $sources) { $src[] = new sourceEntity( - $sources["id_source"], - $sources["title"], - $sources["date"] - ); + $sources["id_source"], + $sources["title"], + $sources["dates"], + TypeSourceEnum::from($sources["type"]) + ); } return $src; } - public function getSources() : array + public function getAllSources() : array { - return $this -> gateway -> findAll(); + $res = $this -> gateway -> findAll(); + $src = []; + foreach ($res as $sources) { + $src[] = new sourceEntity( + $sources["id_source"], + $sources["title"], + $sources["dates"], + TypeSourceEnum::from($sources["type"]) + ); + } + return $src; } public function deleteSource(int $id_source) : bool diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index fa6d277..219932c 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -13,6 +13,7 @@ return array( 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'), 'Model\\' => array($baseDir . '/src/Model'), 'Gateway\\' => array($baseDir . '/src/Gateway'), + 'Enum\\' => array($baseDir . '/src/Enum'), 'Entity\\' => array($baseDir . '/src/Entity'), 'Controleur\\' => array($baseDir . '/src/Controleur'), ); diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 07f7271..f4ba755 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -42,6 +42,7 @@ class ComposerStaticInit68804b2111cb6b8bf6edf66cb2b4669c ), 'E' => array ( + 'Enum\\' => 5, 'Entity\\' => 7, ), 'C' => @@ -79,6 +80,10 @@ class ComposerStaticInit68804b2111cb6b8bf6edf66cb2b4669c array ( 0 => __DIR__ . '/../..' . '/src/Gateway', ), + 'Enum\\' => + array ( + 0 => __DIR__ . '/../..' . '/src/Enum', + ), 'Entity\\' => array ( 0 => __DIR__ . '/../..' . '/src/Entity', diff --git a/vue/templates/recapSubmitQuote.html.twig b/vue/templates/recapSubmitQuote.html.twig new file mode 100644 index 0000000..d542dd3 --- /dev/null +++ b/vue/templates/recapSubmitQuote.html.twig @@ -0,0 +1,51 @@ + + + + + + Wiki Fantasy : Submit Quote + + + + + + + +{% include "bandeau.html.twig" %} + +

▶ Your quote has been submitted successfully ◀

+ +
+ +
+ +
+ +

Contenu *

+

{{ content }}

+ +
+ +
+ +

Personnage *

+

{{ character }}

+ +
+ +
+ +

Source *

+

{{ source }}

+ +
+ +
+ +
+
+ +
+ + + \ No newline at end of file diff --git a/vue/templates/submitQuote.html.twig b/vue/templates/submitQuote.html.twig new file mode 100644 index 0000000..c403bba --- /dev/null +++ b/vue/templates/submitQuote.html.twig @@ -0,0 +1,63 @@ + + + + + + Wiki Fantasy : Submit Quote + + + + + + + +{% include "bandeau.html.twig" %} + +

▶ Submit a Quote ◀

+ + + +
+ +
+ +

Contenu *

+ +
+ +
+ +

Personnage *

+ + {% if errors[0] is defined and errors[0] is not empty %} +

{{ errors[0] }}

+ {% endif %} + +
+ +
+ +

Source *

+ + {% if errors[1] is defined and errors[1] is not empty %} +

{{ errors[1] }}

+ {% endif %} + +
+ +
+ +

Image *

+ +
+ +
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/vue/test.php b/vue/test.php new file mode 100644 index 0000000..e69de29 From 050363800eac1339ce364507932ad57dffb22be7 Mon Sep 17 00:00:00 2001 From: tomivt Date: Tue, 19 Nov 2024 09:39:26 +0100 Subject: [PATCH 10/13] Ignorer les fichiers de configuration IDE --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ From 84ded532a336706a3a9f4e14309db36eed5eca23 Mon Sep 17 00:00:00 2001 From: brongniart Date: Wed, 4 Dec 2024 13:17:03 +0100 Subject: [PATCH 11/13] =?UTF-8?q?resolution=20des=20probl=C3=A9me=20de=20m?= =?UTF-8?q?erge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.php | 2 +- index.php | 2 +- src/Controleur/FrontControler.php | 2 +- src/Controleur/UserControler.php | 12 ++++--- src/Controleur/VisitorControler.php | 22 ++++++------- src/Entity/SourceEntity.php | 4 ++- src/Gateway/QuoteGateway.php | 49 ++++++++++++++++++++--------- src/Gateway/SourceGateway.php | 18 ++++++----- src/Gateway/UserGateway.php | 2 +- src/Model/UserModel.php | 8 ++--- src/Model/sourceModel.php | 9 ++++-- 11 files changed, 79 insertions(+), 51 deletions(-) diff --git a/config/config.php b/config/config.php index eb05e94..a351f18 100644 --- a/config/config.php +++ b/config/config.php @@ -12,7 +12,7 @@ $base = ''; $login = ''; $mdp = ''; -$racine=''; +$racine='/~kekentin/WF/WF-Website'; //Vues diff --git a/index.php b/index.php index 6b39b55..cdbd6fb 100644 --- a/index.php +++ b/index.php @@ -15,7 +15,7 @@ if(!isset($_SESSION['theme'])){ require_once __DIR__ . '/config/config.php'; require __DIR__ . '/vendor/autoload.php'; -$co = new \Gateway\Connection('pgsql:host=localhost;dbname=dbwikifantasy;', 'kiem', ''); +$co = new \Gateway\Connection('pgsql:host=localhost;dbname=dbkekentin;', 'kekentin', 'passwd');// ('pgsql:host=localhost;dbname=dbkekentin;', 'kekentin', 'passwd') //twig $loader = new \Twig\Loader\FilesystemLoader('vue/templates'); diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php index 983bf49..ab3cb62 100644 --- a/src/Controleur/FrontControler.php +++ b/src/Controleur/FrontControler.php @@ -5,7 +5,7 @@ use Gateway\Connection; Class FrontControler{ - private array $listAction; + private $listAction; private Connection $co; diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 10b1606..47d8412 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -179,8 +179,7 @@ class UserControler { */ public function showQuestion(int $id, int $num) : void { - global $vues; - global $twig; + global $vues,$twig; $q = $this->GetQuestion($id); $question = $q[$num] ?? $q[0]; $idquestion = $question->getIdQuestion(); @@ -218,6 +217,7 @@ class UserControler { global $vues; if ($_POST) { + $newImage = $_POST['image'] ?? null; $newPseudo = $_POST['pseudo'] ?? null; $newEmail = $_POST['email'] ?? null; $newMdpFirst = $_POST['passwdFirst'] ?? null; @@ -242,11 +242,13 @@ class UserControler { $option = ['cost' => 12]; $newPassWd = password_hash($newMdpFirst, PASSWORD_BCRYPT, $option); $user = $this-> uMod->setPassWd($_SESSION['user'], $newPassWd); - } + } + } + else if($newImage){ + $user = $this->uMod->setImage($_SESSION['user']); } - } - header("Location: /"); + header("Location: ". $racine."/profil"); } diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php index 6c5481e..99589af 100644 --- a/src/Controleur/VisitorControler.php +++ b/src/Controleur/VisitorControler.php @@ -87,14 +87,14 @@ Class VisitorControler { */ public function login() { - //global $vues; - //require_once $vues['login']; + global $vues; + require_once $vues['login']; - global $twig; + //global $twig; - echo $twig->render("login.html.twig"); + //echo $twig->render("login.html.twig"); - $this -> toLogIn(); + //$this -> toLogIn(); } /** @@ -104,14 +104,14 @@ Class VisitorControler { */ public function signin(): void { - //global $vues; - //require_once $vues['signin']; + global $vues; + require_once $vues['signin']; - global $twig; + //global $twig; - echo $twig->render("login.html.twig"); + //echo $twig->render("login.html.twig"); - $this -> signin(); + //$this -> signin(); } @@ -129,7 +129,7 @@ Class VisitorControler { { if (password_verify($mdp, $user->getPassword())) { - $_SESSION['user'] = $pseudo; + $_SESSION['user'] = Verification::verifChar($pseudo); $_SESSION['role'] = 'user'; header("Location: ". $racine); exit(); diff --git a/src/Entity/SourceEntity.php b/src/Entity/SourceEntity.php index 358d8a1..48f6ea0 100644 --- a/src/Entity/SourceEntity.php +++ b/src/Entity/SourceEntity.php @@ -23,7 +23,7 @@ class SourceEntity $this->id_source = $id_source; $this->title = $title; $this->date = $date; - $this->type = $type; + //$this->type = $type; } /** @@ -74,6 +74,7 @@ class SourceEntity $this->date = $date; } + public function getType(): TypeSourceEnum { return $this->type; @@ -84,5 +85,6 @@ class SourceEntity { $this->type = $type; } + } diff --git a/src/Gateway/QuoteGateway.php b/src/Gateway/QuoteGateway.php index db88697..d5ace1f 100644 --- a/src/Gateway/QuoteGateway.php +++ b/src/Gateway/QuoteGateway.php @@ -6,7 +6,11 @@ use PDOException; Class QuoteGateway extends Gateway{ public function searchQuote(string $quote,int $numpage,string $language):array{ - $query="SELECT q.id_quote, q.content, c.id_char, c.img_char, s.title, s.date, q.likes, q.langue FROM Quote q JOIN Characters c ON c.id_char = q.character JOIN Source s ON s.id_source = q.id_source WHERE content LIKE '%:quote%' AND is_valid = true AND langue = :langue LIMIT 20 OFFSET :page*20;"; + $query="SELECT q.id_quote, q.content, q.id_caracter, c.img_char, s.title, s.date, q.likes, q.langue + FROM Quote q + JOIN Source s ON s.id_source = q.id_source + WHERE content LIKE '%:quote%' AND is_valid = true AND langue = :langue + LIMIT 20 OFFSET :page*20;"; $this->co->executeQuery($query,array(':quote' => array($quote,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':langue' => array($language,PDO::PARAM_STR))); return $this->co->getResults(); } @@ -14,7 +18,12 @@ Class QuoteGateway extends Gateway{ public function searchSource(string $source,int $numpage,string $language):array{ //recherche par source - $query="SELECT q.id_quote, q.content, c.character, c.img_path, s.title, s.date, q.likes, q.langue FROM Quote q JOIN Characters c ON c.id_char = q.character JOIN Source s ON s.id_source = q.id_source WHERE s.title LIKE '%:source%' AND q.is_valid = true AND langue = :langue LIMIT 20 OFFSET :page*20;"; + $query="SELECT q.id_quote, q.content, c.character, c.img_path, s.title, s.date, q.likes, q.langue + FROM Quote q + JOIN Caracter c ON c.id_caracter = q.character + JOIN Source s ON s.id_source = q.id_source + WHERE s.title LIKE '%:source%' AND q.is_valid = true AND langue = :langue + LIMIT 20 OFFSET :page*20;"; $this->co->executeQuery($query,array(':source' => array($source,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':langue' => array($language,PDO::PARAM_STR))); $result=$this->co->getResults(); return $result; @@ -23,7 +32,12 @@ Class QuoteGateway extends Gateway{ public function searchPers(string $Carac,int $numpage,string $language):array{ //recherche par personnage - $query="SELECT q.id_quote, q.content, c.character, c.img_path, s.title, s.date, q.likes, q.langue FROM Quote q JOIN Characters c ON c.id_char = q.character JOIN Source s ON s.id_source = q.id_source WHERE c.character LIKE '%:pers%' AND q.is_valid = true AND langue = :langue LIMIT 20 OFFSET :page*20;"; + $query="SELECT q.id_quote, q.content, c.character, c.img_path, s.title, s.date, q.likes, q.langue + FROM Quote q + JOIN Caracter c ON c.id_caracter = q.character + JOIN Source s ON s.id_source = q.id_source + WHERE c.character LIKE '%:pers%' AND q.is_valid = true AND langue = :langue + LIMIT 20 OFFSET :page*20;"; $this->co->executeQuery($query,array(':pers' => array($Pers,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':langue' => array($language,PDO::PARAM_STR))); $result=$this->co->getResults(); return $result; @@ -32,7 +46,12 @@ Class QuoteGateway extends Gateway{ public function searchId(string $id):array{ //recherche par id - $query="SELECT q.id_quote, q.content, c.character, i.imgPath, s.title, s.dates, q.likes, q.langue FROM Quote q JOIN Characters c ON c.id_char = q.character JOIN Source s ON s.id_source = q.id_source JOIN Image i ON c.id_img = i.id_img WHERE q.id_quote = :id AND q.isvalide = true;"; + $query="SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dates, q.likes, q.langue + FROM Quote q + JOIN Caracter c ON c.id_caracter = q.id_caracter + JOIN Source s ON s.id_source = q.id_source + JOIN Image i ON c.id_img = i.id_img + WHERE q.id_quote = :id AND q.isvalide = true;"; $this->co->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR))); $result=$this->co->getResults(); return $result; @@ -41,7 +60,7 @@ Class QuoteGateway extends Gateway{ public function search(?string $type,?string $search,array $filtre):array{ $query="SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dates, q.likes, q.langue FROM Quote q - JOIN Characters c ON c.id_caracter = q.id_caracter + JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source JOIN Image i ON c.id_img = i.id_img WHERE lower("; @@ -68,14 +87,14 @@ Class QuoteGateway extends Gateway{ public function getQuoteOfTheDay(string $language): array { $query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue - FROM DailyQuote dq - JOIN Quote q ON dq.citation_id = q.id_quote - JOIN Characters c ON c.id_caracter = q.id_caracter - JOIN Source s ON s.id_source = q.id_source - JOIN Image i ON c.id_img = i.id_img - WHERE q.isValide = true AND q.langue = :language - ORDER BY q.id_quote DESC - LIMIT 1;"; + FROM DailyQuote dq + JOIN Quote q ON dq.citation_id = q.id_quote + JOIN Caracter c ON c.id_caracter = q.id_caracter + JOIN Source s ON s.id_source = q.id_source + JOIN Image i ON c.id_img = i.id_img + WHERE q.isValide = true AND q.langue = :language + ORDER BY q.id_quote DESC + LIMIT 1;"; try { $this->co->executeQuery($query, [':language' => [$language, PDO::PARAM_STR]]); $result = $this->co->getResults(); @@ -91,7 +110,7 @@ Class QuoteGateway extends Gateway{ public function getSuggestions(int $numpage, string $language): array { $query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue FROM Quote q - JOIN Characters c ON c.id_caracter = q.id_caracter + JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source JOIN Image i ON c.id_img = i.id_img WHERE q.isValide = true AND q.langue = :language @@ -109,7 +128,7 @@ Class QuoteGateway extends Gateway{ $query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue FROM Favorite f JOIN Quote q ON f.quote = q.id_quote - JOIN Characters c ON c.id_caracter = q.id_caracter + JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source JOIN Image i ON c.id_img = i.id_img WHERE f.users = :userId"; diff --git a/src/Gateway/SourceGateway.php b/src/Gateway/SourceGateway.php index c361a1b..ed540b3 100644 --- a/src/Gateway/SourceGateway.php +++ b/src/Gateway/SourceGateway.php @@ -6,17 +6,17 @@ use PDO; class SourceGateway extends Gateway{ - public function create(string $title, string $date, TypeSourceEnum $type) : bool + public function create(sourceEntity $s) : bool { $query = " INSERT INTO Source - VALUES (:title, :type, :date) + VALUES( :title, :date) "; return $this -> co -> executeQuery($query, [ - "title" => array($title, PDO::PARAM_STR), - "date" => array($date, PDO::PARAM_STR), - "type" => array($type, PDO::PARAM_STR) + "title" => array($s->getTitle(), PDO::PARAM_STR), + "date" => array($s->getDate(), PDO::PARAM_STR), + "type" => array($s->getType(), PDO::PARAM_STR) ]); } @@ -48,10 +48,11 @@ class SourceGateway extends Gateway{ { $query = "SELECT * FROM Source WHERE dates = :d"; - $this -> co -> executeQuery($query, ["date" => array($d, PDO::PARAM_STR)]); + $this -> co -> executeQuery($query, ["d" => array($d, PDO::PARAM_STR)]); return $this -> co -> getResults(); } - + + /* public function findByType(TypeSourceEnum $type) : array { $query = "SELECT * FROM Source WHERE type = :t"; @@ -59,6 +60,7 @@ class SourceGateway extends Gateway{ $this -> co -> executeQuery($query, ["t" => array($type, PDO::PARAM_STR)]); return $this -> co -> getResults(); } + */ public function findAll() : array { @@ -74,7 +76,7 @@ class SourceGateway extends Gateway{ $source["id_source"], $source["title"], $source["date"], - $res["source"] + TypeSourceEnum::Movie//$res["source"] ); } return $sources; diff --git a/src/Gateway/UserGateway.php b/src/Gateway/UserGateway.php index 8cbd91f..450feb0 100644 --- a/src/Gateway/UserGateway.php +++ b/src/Gateway/UserGateway.php @@ -70,7 +70,7 @@ Class UserGateway extends Gateway{ //obtenir les information d'un user public function findDataUser(int $id):array{ - $query = 'SELECT * FROM Users WHERE id_user=:idUser'; + $query = 'SELECT u.id_user , u.username , u.email , u.password , i.imgPath , u.creation FROM Users WHERE id_user=:idUser'; $this->co->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR))); $result = $this->co->getResults(); return $result; diff --git a/src/Model/UserModel.php b/src/Model/UserModel.php index 891650f..5f2a99d 100644 --- a/src/Model/UserModel.php +++ b/src/Model/UserModel.php @@ -38,8 +38,8 @@ return new UserEntity( $res[0]['id_user'], $res[0]['username'], - $res[0]['email'], $res[0]['password'], + $res[0]['email'], $res[0]['img'], $res[0]['creation'] ); @@ -53,9 +53,9 @@ return new UserEntity( $res[0]['id_user'], $res[0]['username'], - $res[0]['email'], $res[0]['password'], - $res[0]['img'], + $res[0]['email'], + $res[0]['imgpath'], $res[0]['creation'] ); return null; @@ -68,8 +68,8 @@ return new UserEntity( $res[0]['id_user'], $res[0]['username'], - $res[0]['email'], $res[0]['password'], + $res[0]['email'], $res[0]['img'], $res[0]['creation'] ); diff --git a/src/Model/sourceModel.php b/src/Model/sourceModel.php index 9c54006..baf1c37 100644 --- a/src/Model/sourceModel.php +++ b/src/Model/sourceModel.php @@ -8,7 +8,10 @@ class SourceModel extends Model public function createSource(string $title, string $date, TypeSourceEnum $type) : bool { - return $this -> gateway -> create($title, $date, $type); + $q = new SourceEntity(-1,$title, $date, TypeSourceEnum::Movie/*$type*/); + + return $this -> gateway -> create($q); + } public function getSourceById(int $id_source) : ?SourceEntity @@ -20,7 +23,7 @@ class SourceModel extends Model $res[0]["id_source"], $res[0]["title"], $res[0]["dates"], - TypeSourceEnum::from($res[0]["type"]) + TypeSourceEnum::Movie//from($res[0]["type"]) ); return null; } @@ -33,7 +36,7 @@ class SourceModel extends Model $res[0]["id_source"], $res[0]["title"], $res[0]["dates"], - TypeSourceEnum::from($res[0]["type"]) + TypeSourceEnum::Movie//from($res[0]["type"]) ); return null; } From 844fb568830fc64cd8232c39ad4dead6de4fe86c Mon Sep 17 00:00:00 2001 From: beaulaton Date: Thu, 5 Dec 2024 14:24:56 +0100 Subject: [PATCH 12/13] Correction image changeante --- src/Controleur/UserControler.php | 114 +++++++++++++++++++++++++++++-- vue/templates/profil.html.twig | 5 +- 2 files changed, 112 insertions(+), 7 deletions(-) diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 8a4b5b3..19afef1 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -1,7 +1,11 @@ = $total_questions) { - session_destroy(); + $_SESSION['no_question'] = 0; $this->endQuiz($id_quiz, $score); } else header("Location: ".$racine."/quiz/$id_quiz"); ///~kekentin/WF/WF-Website @@ -180,7 +185,7 @@ class UserControler { */ public function showQuestion(int $id, int $num) : void { - global $vues; + global $vues,$twig; $q = $this->GetQuestion($id); $question = $q[$num] ?? $q[0]; $idquestion = $question->getIdQuestion(); @@ -232,9 +237,11 @@ class UserControler { $_SESSION['user'] = $newPseudo; } } + else if($newEmail){ $user = $this-> uMod->setEmail($_SESSION['user'], $newEmail); } + else if($newMdpFirst && $newMdpSecond){ if($newMdpFirst == $newMdpSecond){ @@ -242,12 +249,111 @@ class UserControler { $option = ['cost' => 12]; $newPassWd = password_hash($newMdpFirst, PASSWORD_BCRYPT, $option); $user = $this-> uMod->setPassWd($_SESSION['user'], $newPassWd); - } + } } + else if($newImage){ $user = $this->uMod->setImage($_SESSION['user']); } } - header("Location: /~lebeaulato/WF-Website/profil"); + header("Location: ". $racine."/profil"); + + } + + /** + * @throws SyntaxError + * @throws RuntimeError + * @throws LoaderError + */ + public function submit() : void + { + global $twig; + echo $twig -> render("submitQuote.html.twig"); + } + + /** + * @throws SyntaxError + * @throws RuntimeError + * @throws LoaderError + */ + public function toSubmit() : ?array + { + global $co; + if ($_POST) + { + $content = $_POST['content'] ?? null; + $character = $_POST['character'] ?? null; + $source = $_POST['source'] ?? null; + //$img = $_POST['img'] ?? null; + + $errors = [null, null]; + + $gw = new CharacterGateway($co); + $mdl = new CharacterModel($gw); + + $character = $mdl -> getCharacterByName($character); + + $gw = new SourceGateway($co); + $mdl = new SourceModel($gw); + + $source = $mdl -> getSourceByTitle($source); + + if (!$character) + $errors[0] = "Personnage inexistant"; + if (!$source) + $errors[1] = "Source inexistante"; + if ($errors[0] || $errors[1]) + { + global $twig; + echo $twig->render("submitQuote.html.twig", ['errors' => $errors]); + exit(); + } + + $gw = new QuoteGateway($co); + $mdl = new QuoteModel($gw); + + $mdl -> insert4User($content, '/imgPath', 'fr', $this -> getIdOfUser(), $source->getIdSource(), $character->getIdCharacter()); + + return [$content, $_POST['character'], $_POST['source']]; + } + return null; + } + + /** + * @throws SyntaxError + * @throws RuntimeError + * @throws LoaderError + */ + public function validsubmit() : void + { + $recap = $this -> toSubmit(); + if ($recap) + { + $this -> recapSubmitQuote($recap); + } + } + + /** + * @throws RuntimeError + * @throws SyntaxError + * @throws LoaderError + */ + public function recapSubmitQuote(?array $recap) : void + { + global $twig; + echo $twig -> render("recapSubmitQuote.html.twig", ['content' => $recap[0], 'character' => $recap[1], 'source' => $recap[2]]); + } + + public function getIdOfUser() : ?int + { + if (isset($_SESSION['user'])) + { + global $co; + $gw = new UserGateway($co); + $mdl = new UserModel($gw); + + return $mdl -> getUsername($_SESSION['user']) -> getId(); + } + return null; } } diff --git a/vue/templates/profil.html.twig b/vue/templates/profil.html.twig index 645a20d..d9ac021 100644 --- a/vue/templates/profil.html.twig +++ b/vue/templates/profil.html.twig @@ -3,9 +3,8 @@

▶ Profil ◀

- - - + +

{{ srcUsername }}

From 39aea33814d6a4caf95eced00d373c513465792f Mon Sep 17 00:00:00 2001 From: beaulaton Date: Thu, 5 Dec 2024 14:48:13 +0100 Subject: [PATCH 13/13] Lien et correction de la page submitQuote --- config/config.php | 3 ++- public/styles/styleSubmitQuote.css | 19 ------------------- src/Controleur/UserControler.php | 6 +++--- vue/submitQuote.php | 18 ++++++++++++++++++ vue/templates/profil.html.twig | 2 +- vue/templates/submitQuote.html.twig | 15 --------------- 6 files changed, 24 insertions(+), 39 deletions(-) create mode 100644 vue/submitQuote.php diff --git a/config/config.php b/config/config.php index a351f18..322a129 100644 --- a/config/config.php +++ b/config/config.php @@ -12,7 +12,7 @@ $base = ''; $login = ''; $mdp = ''; -$racine='/~kekentin/WF/WF-Website'; +$racine='/~lebeaulato/WF-Website'; // /~kekentin/WF/WF-Website //Vues @@ -27,6 +27,7 @@ $vues['favorite'] = 'vue/favorits.php'; $vues['quiz'] = 'vue/quiz.php'; $vues['endQuiz'] = 'vue/endQuiz.php'; +$vues['submitQuote'] = 'vue/submitQuote.php'; //Style css diff --git a/public/styles/styleSubmitQuote.css b/public/styles/styleSubmitQuote.css index db65891..98ee5cd 100644 --- a/public/styles/styleSubmitQuote.css +++ b/public/styles/styleSubmitQuote.css @@ -25,26 +25,7 @@ body.light-mode h1, body.light-mode h2, body.light-mode p { /* ====== OTHER ====== */ -.header { - display: flex; - width: 100%; - height: 17%; - justify-content: space-between; - align-items: center; -} - -.nav img { - margin-right: 10px; -} - -.logo img { - display: block; - margin: 0 auto; -} -.user img { - margin-left: 10px; -} #form { diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 98907b3..9a1ad92 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -214,7 +214,7 @@ class UserControler { public function changedata() : void { - global $vues; + global $vues, $racine; if ($_POST) { $newImage = $_POST['image'] ?? null; @@ -260,8 +260,8 @@ class UserControler { */ public function submit() : void { - global $twig; - echo $twig -> render("submitQuote.html.twig"); + global $vues; + require_once $vues['submitQuote']; } /** diff --git a/vue/submitQuote.php b/vue/submitQuote.php new file mode 100644 index 0000000..f36cb2c --- /dev/null +++ b/vue/submitQuote.php @@ -0,0 +1,18 @@ +render('head.html.twig', [ + 'title' => "Submit Quote", + 'style' => "public/styles/styleSubmitQuote.css", + 'scripts' => array("public/script/theme-toggle.js") +]); + + +// Rendu du bandeau +echo $twig->render('bandeau.html.twig'); + +echo $twig -> render("submitQuote.html.twig"); +?> + + diff --git a/vue/templates/profil.html.twig b/vue/templates/profil.html.twig index d9ac021..b46eaa7 100644 --- a/vue/templates/profil.html.twig +++ b/vue/templates/profil.html.twig @@ -23,7 +23,7 @@ diff --git a/vue/templates/submitQuote.html.twig b/vue/templates/submitQuote.html.twig index c403bba..e0df0c2 100644 --- a/vue/templates/submitQuote.html.twig +++ b/vue/templates/submitQuote.html.twig @@ -1,18 +1,3 @@ - - - - - - Wiki Fantasy : Submit Quote - - - - - - - -{% include "bandeau.html.twig" %} -

▶ Submit a Quote ◀