+
+
+";
+ yield from [];
+ }
+
+ /**
+ * @codeCoverageIgnore
+ */
+ public function getTemplateName(): string
+ {
+ return "signin.html.twig";
+ }
+
+ /**
+ * @codeCoverageIgnore
+ */
+ public function getDebugInfo(): array
+ {
+ return array ( 42 => 1,);
+ }
+
+ public function getSourceContext(): Source
+ {
+ return new Source("", "signin.html.twig", "/Users/kiem/Documents/WikiFantasy/WF-Website/vue/templates/signin.html.twig");
+ }
+}
diff --git a/config/config.php b/config/config.php
index cd389e1..078984c 100644
--- a/config/config.php
+++ b/config/config.php
@@ -17,7 +17,8 @@ $mdp = '';
$vues['erreur'] = 'vue/erreur.php';
$vues['accueil'] = 'vue/accueil.php';
$vues['quote'] = 'vue/quote.php';
-$vues['login'] = 'vue/login.html';
+$vues['login'] = 'vue/templates/login.html.twig';
+$vues['signin'] = 'vue/templates/signin.html.twig';
//Style css
$style['accueil'] = 'public/styles/styleAccueil.css';
diff --git a/public/styles/styleLogin.css b/public/styles/styleLogin.css
index 5f0d309..e0da447 100644
--- a/public/styles/styleLogin.css
+++ b/public/styles/styleLogin.css
@@ -98,7 +98,7 @@ body.light-mode .createAccount{
font-family: "Lemon", serif;
}
-body.light-mode .buttonSudmite{
+body.light-mode .buttonSubmit{
background: linear-gradient(180deg, rgba(187,211,249,1) 0%, rgba(199,246,196,1) 100%);
font-family: "Lemon", serif;
border: none;
@@ -123,7 +123,7 @@ body.light-mode .connexion{
/* ====== DEFAULT ====== */
-.buttonSudmiteDiv{
+.buttonSubmitDiv{
text-align: center;
}
diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php
index e82278a..de9831c 100644
--- a/src/Controleur/FrontControler.php
+++ b/src/Controleur/FrontControler.php
@@ -16,7 +16,7 @@ Class FrontControler{
$this->co=$co;
- $this->listAction = ['visitor' => array('accueil','search','quote','login','singin','quiz'),
+ $this->listAction = ['visitor' => array('accueil','search','quote','login','signin','quiz'),
'user' => array('quiz','commentary','favorite','logout'),
'admin' => array('null')];
@@ -37,6 +37,7 @@ Class FrontControler{
$router->map('GET|POST', '/quote/[i:idQuote]?', 'VisitorControler');
$router->map('GET|POST', '/login', 'VisitorControler');
+ $router->map('GET|POST', '/signin', 'VisitorControler');
$router->map('GET|POST', '/quiz/[i:id]?', 'QuizController');
$match = $router->match();
@@ -69,7 +70,7 @@ Class FrontControler{
$controller = '\\Controleur\\' . $controller;
- $controller = new $controller($this->co);
+ $controller = new $controller($this->co, $action);
if (is_callable(array($controller, $action))) {
call_user_func_array(array($controller, $action),
array($match['params']));
diff --git a/src/Controleur/QuizController.php b/src/Controleur/QuizController.php
index 3b81996..fc148ee 100644
--- a/src/Controleur/QuizController.php
+++ b/src/Controleur/QuizController.php
@@ -32,7 +32,7 @@ class QuizController
* @throws RuntimeError
* @throws LoaderError
*/
- public function __construct(Connection $co)
+ public function __construct(Connection $co, ?string $action = null)
{
$this -> co = $co;
$this -> gw = new QuestionGateway($this->co);
diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php
index 0c60b74..6411df1 100644
--- a/src/Controleur/VisitorControler.php
+++ b/src/Controleur/VisitorControler.php
@@ -1,7 +1,50 @@
co = $co;
+ $this->gw = new UserGateway($this->co);
+ $this->mdl = new UserModel($this->gw);
+ $this -> getAction($action);
+ }
+
+ /**
+ * @throws SyntaxError
+ * @throws RuntimeError
+ * @throws LoaderError
+ */
+ public function getAction(string $action): void
+ {
+ switch ($action) {
+ case "login":
+ $this -> visitorLogIn();
+ break;
+ case "signin":
+ $this -> visitorSignIn();
+ break;
+ default:
+ break;
+ }
+ }
public function accueil(){
global $vues;
@@ -12,14 +55,51 @@ Class VisitorControler{
global $vues;
$id=$arg['idQuote'] ?? 1;
- //echo "{$id}";
-
+ //echo "{$id}";
require_once $vues['quote'];
}
- public function login(){
+ /**
+ * @throws SyntaxError
+ * @throws RuntimeError
+ * @throws LoaderError
+ */
+ public function visitorLogIn(): void
+ {
global $vues;
- require_once $vues['login'];
+ global $twig;
+ echo $twig->render("login.html.twig");
+
+ $pseudo = $_POST['pseudo'] ?? null;
+ $mdp = $_POST['mdp'] ?? null;
+ }
+
+ /**
+ * @throws SyntaxError
+ * @throws RuntimeError
+ * @throws LoaderError
+ */
+ public function visitorSignIn(): void
+ {
+ global $vues;
+ global $twig;
+ echo $twig->render("signin.html.twig");
+
+ $pseudo = $_POST['pseudo'] ?? null;;
+ $email = $_POST['email'] ?? null;
+ $mdp = $_POST['mdp'] ?? null;
+ $cmdp = $_POST['cmdp'] ?? null;
+
+ if ($mdp != $cmdp) {
+ return;
+ }
+
+ $option = ['cost' => 12];
+ $hmdp = password_hash($mdp, PASSWORD_BCRYPT, $option);
+
+ $user = $this -> mdl -> getUsername($pseudo);
+
+ echo $this->mdl->insertUser($pseudo, $email, $hmdp);
}
}
diff --git a/src/Entity/userEntity.php b/src/Entity/userEntity.php
index f0546be..08abe35 100644
--- a/src/Entity/userEntity.php
+++ b/src/Entity/userEntity.php
@@ -1,124 +1,107 @@
id = $id;
- $this->username = $username;
- $this->passwd = $passwd;
- $this->hidenPasswd = hidenPasswd($passwd);
- $this->img = $img;
- $this->email = $email;
- }
-
- /**
- * @return string
- */
public function getId(): int
{
return $this->id;
}
- /**
- * @param string $id
- */
public function setId(int $id): void
{
$this->id = $id;
}
- /**
- * @return string
- */
- public function getUsername(): string
+ public function getPseudo(): string
{
- return $this->username;
+ return $this->pseudo;
}
- /**
- * @param string $username
- */
- public function setUsername(string $username): void
+ public function setPseudo(string $pseudo): void
{
- $this->username = $username;
+ $this->pseudo = $pseudo;
}
- /**
- * @return string
- */
- public function getImg(): int
+ public function getPassword(): string
{
- return $this->img;
+ return $this->password;
}
- /**
- * @param string $img
- */
- public function setImg(int $img): void
+ public function setPassword(string $password): void
{
- $this->img = $img;
+ $this->password = $password;
}
- /**
- * @return string
- */
public function getEmail(): string
{
return $this->email;
}
- /**
- * @param string $email
- */
public function setEmail(string $email): void
{
$this->email = $email;
}
- /**
- * @return string
- */
- public function getPasswd(): string
+ public function getDate(): string
{
- return $this->passwd;
+ return $this->date;
}
- /**
- * @return string
- */
- public function getHidenPasswd(): string
+ public function setDate(string $date): void
+ {
+ $this->date = $date;
+ }
+
+ public function isAdmin(): bool
+ {
+ return $this->isAdmin;
+ }
+
+ public function setIsAdmin(bool $isAdmin): void
{
- return $this->hidenPasswd;
+ $this->isAdmin = $isAdmin;
+ }
+
+ public function getImgPrfl(): int
+ {
+ return $this->imgPrfl;
+ }
+
+ public function setImgPrfl(int $imgPrfl): void
+ {
+ $this->imgPrfl = $imgPrfl;
}
/**
- * @param string $passwd
+ * @param int $id
+ * @param string $pseudo
+ * @param string $password
+ * @param string $email
+ * @param int $imgPrfl
+ * @param bool $isAdmin
+ * @param string $date
*/
- public function setPasswd(string $passwd): void
+ public function __construct(int $id, string $pseudo, string $password, string $email, int $imgPrfl, bool $isAdmin, string $date)
{
- $this->passwd = $passwd;
- $this->hidenPassWd = hidenPassWd($passwd);
+ $this->id = $id;
+ $this->pseudo = $pseudo;
+ $this->password = $password;
+ $this->email = $email;
+ $this->imgPrfl = $imgPrfl;
+ $this->isAdmin = $isAdmin;
+ $this->date = $date;
}
-
}
// ============================================ En attente du Model ============================================
/*$dsn = "pgsql:host=londres;dbname=dblebeaulato";
diff --git a/src/Gateway/userGateway.php b/src/Gateway/userGateway.php
index 4760260..f46eb1a 100644
--- a/src/Gateway/userGateway.php
+++ b/src/Gateway/userGateway.php
@@ -1,32 +1,42 @@
con=$con;
}
- public function insert(string $username,string $email,string $passwd):string{
+ public function getNumberOfUsers() : array
+ {
+ $query = "SELECT Count(*) FROM Users";
- // récupération id
- $query='SELECT id_user FROM Users WHERE id_user >= ALL (SELECT id_user FROM Users);';
- $this->con->executeQuery($query);
- $result=$this->con->getResults();
- foreach($result as $row){
- $id=$row['id_user'] + 1;
- }
- // insertion user
- $query='INSERT INTO Users VALUES (:id,:username,:email,:passwd,CURRENT_DATE,false);';
- $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR),':username' => array($u->username,PDO::PARAM_STR),':email' => array($u->email,PDO::PARAM_STR),':passwd' => array($u->passwd,PDO::PARAM_STR)));
- return $id;
+ $this -> con -> executeQuery($query);
+
+ return $this -> con -> getResults();
}
-
+
+ public function insertUser(int $id, string $pseudo, string $email, string $password, bool $isAdmin, int $imgPrfl) : bool {
+ $query = "
+ INSERT INTO Users
+ VALUES (:id, :pseudo, :email, :password, CURRENT_DATE, :isAdmin, :imgPrfl)
+ ";
+ return $this -> con -> executeQuery($query, [
+ ":id" => [$id, PDO::PARAM_INT],
+ ":pseudo" => [$pseudo, PDO::PARAM_STR],
+ ":email" => [$email, PDO::PARAM_STR],
+ ":password" => [$password, PDO::PARAM_STR],
+ ":isAdmin" => [$isAdmin, PDO::PARAM_INT],
+ ":imgPrfl" => [$imgPrfl, PDO::PARAM_STR]
+ ]);
+ }
+
public function delete(string $id) : bool{
- // supretion user
+ // supretion user
$query='DELETE FROM Users WHERE id_user = :id;';
return $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR)));
}
@@ -34,7 +44,7 @@ Class UserGateway{
public function getFavorite(string $id):array{
//obtention favoris d'un user
- $query='SELECT * FROM Quote WHERE id_quote IN (SELECT id_quote IN Favorite f JOIN User u ON u.id_user = f.user WHERE id_user = :id);';
+ $query='SELECT * FROM Quote WHERE id_quote IN (SELECT id_quote FROM Favorite f JOIN users u ON u.id_user = f.user_f WHERE u.id_user = :id);';
$this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR)));
$result=$this->con->getResults();
return $result;
@@ -44,62 +54,64 @@ Class UserGateway{
//obtenir les information d'un user
public function findDataUser(int $id):array{
$query = 'SELECT * FROM Users WHERE id_user=:idUser';
- $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR)));
- $result = $con->getResults();
+ $this->con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR)));
+ $result = $this->con->getResults();
return $result;
}
+ // obtenir les informations d'un user selon son pseudo
+ public function findUsername(string $username):array{
+ $query = 'SELECT * FROM Users WHERE username= :username';
+ $this->con->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR)));
+ return $this->con->getResults();
+ }
// ===================== UPDATE FUNCTION =====================
- public function updateUsername(int $id, string $newUsername):array{
+ public function updateUsername(int $id, string $newUsername):bool{
//Update le nom du user passé en paramètre
$queryUpdate = 'UPDATE Users SET username=:newUsername WHERE id_user=:idUser';
- $con->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newUsername'=> array($newUsername, PDO::PARAM_STR)));
+ $this->con->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newUsername'=> array($newUsername, PDO::PARAM_STR)));
//Renvoie le nouveau nom du user
$queryReponse = 'SELECT username FROM Users WHERE id_user=:idUser';
- $con->executeQuery($queryReponse, array($id=>array($newUsername, PDO::PARAM_STR)));
- return $result;
+
+ return $this->con->executeQuery($queryReponse, array($id=>array($newUsername, PDO::PARAM_STR)));
}
- public function updateEmail(int $id, string $newEmail):array{
+ public function updateEmail(int $id, string $newEmail):bool{
//Update le email du user passé en paramètre
$queryUpdate = 'UPDATE Users SET email=:newEmail WHERE id_user=:idUser';
- $con->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newEmail'=> array($newEmail, PDO::PARAM_STR)));
+ $this->con->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newEmail'=> array($newEmail, PDO::PARAM_STR)));
//Renvoie le nouveau email du user
- $queryReponse = 'SELECT email FROM Users WHERE id_user=:idUser';
- $con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR)));
- $result = $con->getResults();
- return $result;
+ $queryReponse = 'SELECT email FROM Users WHERE id_user=:idUser';
+ return $this->con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR)));
}
public function updateImg(int $id, int $newImg):array{
//Update l'image du user passé en paramètre
- $query = 'UPDATE Users SET img=:newImg WHERE id_user=:idUser';
- $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newImg'=> array($newImg, PDO::PARAM_STR)));
+ $query = 'UPDATE Users SET img_prfl=:newImg WHERE id_user=:idUser';
+ $this->con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newImg'=> array($newImg, PDO::PARAM_STR)));
//Renvoie la nouvelle image du user
- $queryReponse = 'SELECT img FROM Users WHERE id_user=:idUser';
- $con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR)));
- $result = $con->getResults();
+ $queryReponse = 'SELECT img_prfl FROM Users WHERE id_user=:idUser';
+ $this->con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR)));
+ $result = $this->con->getResults();
return $result;
}
public function updatePasswd(int $id, string $newPassWd):array{
//Update le passwd du user passé en paramètre
$query = 'UPDATE Users SET pssword=:newPassWd WHERE id_user=:idUser';
- $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newPassWd'=> array($newPassWd, PDO::PARAM_STR)));
+ $this->con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newPassWd'=> array($newPassWd, PDO::PARAM_STR)));
//Renvoie le nouveau passwd du user
$queryReponse = 'SELECT pssword FROM Users WHERE id_user=:idUser';
- $con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR)));
- $result = $con->getResults();
+ $this->con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR)));
+ $result = $this->con->getResults();
return $result;
}
}
-$uG = new UserGateway(new Connection("pgsql:host=londres;dbname=dblebeaulato","lebeaulato",""));
-
?>
diff --git a/src/Model/userModel.php b/src/Model/userModel.php
index adc7012..720efc8 100644
--- a/src/Model/userModel.php
+++ b/src/Model/userModel.php
@@ -11,13 +11,18 @@
$this->gateway = $gate;
}
- public function insertUser(string $username,string $email,string $passwd) : User{
- global $rep,$image;
- $id = $this->gateway->insert($username,$email,$passwd);
- $u = new User($id,$usename,$passwd,$rep.$image['default'],$email);
+ public function insertUser(string $username,string $email,string $passwd) : bool{
+ /*global $rep,$image;*/
+ return $this->gateway->insertUser($this->getNumberOfUsers() + 1, $username, $email, $passwd, false, 0);
}
- public function deletUser(string $id) : bool{
+ public function getNumberOfUsers() : int
+ {
+
+ return $this->gateway->getNumberOfUsers()[0]['count'] ?? 0;
+ }
+
+ public function deleteUser(string $id) : bool{
return $this->gateway->delete($id);
}
@@ -30,20 +35,32 @@
// }
// }
- public function getDataUser(int $id){
+ public function getDataUser(int $id) : ?User {
$res = $this->gateway->findDataUser($id);
- foreach($res as $sources){
- $src[] = new User(
- $sources['id_user'],
- $sources['username'],
- $sources['pssword'],
- $sources['img'],
- $sources['email']
+ if ($res)
+ return new User(
+ $res['id_user'],
+ $res['username'],
+ $res['pssword'],
+ $res['img'],
+ $res['email']
);
- }
- return $src;
+ return null;
}
+ public function getUsername(string $username) : ?User
+ {
+ $res = $this->gateway->findUsername($username);
+ if ($res)
+ return new User(
+ $res['id_user'],
+ $res['username'],
+ $res['pssword'],
+ $res['img'],
+ $res['email']
+ );
+ return null;
+ }
public function setUsername(int $id, string $newUsername){
$res = $this->gateway->updateUsername($id,$newUsername);
diff --git a/vue/templates/bandeau.html.twig b/vue/templates/bandeau.html.twig
index aa84323..fd8e5af 100644
--- a/vue/templates/bandeau.html.twig
+++ b/vue/templates/bandeau.html.twig
@@ -8,6 +8,6 @@
-
+
\ No newline at end of file
diff --git a/vue/login.html b/vue/templates/login.html.twig
similarity index 81%
rename from vue/login.html
rename to vue/templates/login.html.twig
index 47002d3..d292540 100644
--- a/vue/login.html
+++ b/vue/templates/login.html.twig
@@ -27,23 +27,23 @@