pull/20/head
tomivt 6 months ago
parent 8eb7e76e9d
commit 5fccbca698

File diff suppressed because it is too large Load Diff

@ -1,2 +1,2 @@
#n:public #n:public
!<md> [676242, 0, null, null, -2147483648, -2147483648] !<md> [676280, 0, null, null, -2147483648, -2147483648]

@ -5,21 +5,12 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="afa12d51-331f-4dbc-a297-7289ad4e396d" name="Changes" comment=""> <list default="true" id="afa12d51-331f-4dbc-a297-7289ad4e396d" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/dataSources/351a7e7c-c4d1-4e89-bf03-667b32764270.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources/351a7e7c-c4d1-4e89-bf03-667b32764270.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/dataSources/351a7e7c-c4d1-4e89-bf03-667b32764270/storage_v2/_src_/database/dbwikifantasy.OCIa2Q/schema/public.abK9xQ.meta" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources/351a7e7c-c4d1-4e89-bf03-667b32764270/storage_v2/_src_/database/dbwikifantasy.OCIa2Q/schema/public.abK9xQ.meta" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/config.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/config.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/public/styles/styleLogin.css" beforeDir="false" afterPath="$PROJECT_DIR$/public/styles/styleLogin.css" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Controleur/FrontControler.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Controleur/FrontControler.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Controleur/QuizController.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Controleur/QuizController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Controleur/VisitorControler.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Controleur/VisitorControler.php" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Controleur/VisitorControler.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Controleur/VisitorControler.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Entity/userEntity.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Entity/userEntity.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Gateway/userGateway.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Gateway/userGateway.php" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Gateway/userGateway.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Gateway/userGateway.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Model/userModel.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Model/userModel.php" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Model/userModel.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Model/userModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/vue/login.html" beforeDir="false" afterPath="$PROJECT_DIR$/vue/templates/login.html.twig" afterDir="false" />
<change beforePath="$PROJECT_DIR$/vue/signin.html" beforeDir="false" afterPath="$PROJECT_DIR$/vue/templates/signin.html.twig" afterDir="false" />
<change beforePath="$PROJECT_DIR$/vue/templates/bandeau.html.twig" beforeDir="false" afterPath="$PROJECT_DIR$/vue/templates/bandeau.html.twig" afterDir="false" />
<change beforePath="$PROJECT_DIR$/vue/templates/profil.html" beforeDir="false" afterPath="$PROJECT_DIR$/vue/templates/profil.html.twig" afterDir="false" />
<change beforePath="$PROJECT_DIR$/vue/templates/quote.html" beforeDir="false" afterPath="$PROJECT_DIR$/vue/templates/quote.html.twig" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -128,6 +119,9 @@
<workItem from="1730794294713" duration="2741000" /> <workItem from="1730794294713" duration="2741000" />
<workItem from="1730797544484" duration="27887000" /> <workItem from="1730797544484" duration="27887000" />
<workItem from="1731254310060" duration="6803000" /> <workItem from="1731254310060" duration="6803000" />
<workItem from="1731266281659" duration="3339000" />
<workItem from="1731284706585" duration="215000" />
<workItem from="1731284930148" duration="2409000" />
</task> </task>
<servers /> <servers />
</component> </component>

@ -71,8 +71,31 @@ Class VisitorControler {
global $twig; global $twig;
echo $twig->render("login.html.twig"); echo $twig->render("login.html.twig");
$this -> toLogIn();
}
public function toLogIn() : void
{
if ($_POST)
{
$pseudo = $_POST['pseudo'] ?? null; $pseudo = $_POST['pseudo'] ?? null;
$mdp = $_POST['mdp'] ?? null; $mdp = $_POST['mdp'] ?? null;
$user = $this -> mdl -> getUsername($pseudo);
if ($user)
{
if (password_verify($mdp, $user->getPassword()))
{
$_SESSION['pseudo'] = $pseudo;
$_SESSION['email'] = $user->getEmail();
header("Location: /");
}
else die(); /* Afficher Erreur Mot de passe */
}
else die(); /* Afficher Utilisateur non trouvé */
}
} }
/** /**
@ -86,20 +109,38 @@ Class VisitorControler {
global $twig; global $twig;
echo $twig->render("signin.html.twig"); echo $twig->render("signin.html.twig");
$pseudo = $_POST['pseudo'] ?? null;; $this -> toSignIn();
}
public function toSignIn() : void
{
if ($_POST) {
$pseudo = $_POST['pseudo'] ?? null;
$email = $_POST['email'] ?? null; $email = $_POST['email'] ?? null;
$mdp = $_POST['mdp'] ?? null; $mdp = $_POST['mdp'] ?? null;
$cmdp = $_POST['cmdp'] ?? null; $cmdp = $_POST['cmdp'] ?? null;
if ($mdp != $cmdp) { if ($mdp != $cmdp) {
return; die(); /* Afficher Erreur Mot de passe */
} }
$option = ['cost' => 12]; $option = ['cost' => 12];
$hmdp = password_hash($mdp, PASSWORD_BCRYPT, $option); $hmdp = password_hash($mdp, PASSWORD_BCRYPT, $option);
$user = $this -> mdl -> getUsername($pseudo); $isUserAlreadyUsed = $this -> mdl -> getUsername($pseudo);
$isEmailAlreadyUsed = $this -> mdl -> getEmail($email);
if ($isUserAlreadyUsed || $isEmailAlreadyUsed)
die(); /* Afficher Message Erreur */
else echo $this->mdl->insertUser($pseudo, $email, $hmdp);
$_SESSION["pseudo"] = $pseudo;
$_SESSION["email"] = $email;
echo $this->mdl->insertUser($pseudo, $email, $hmdp); header("Location: /");
}
} }
} }

@ -65,6 +65,13 @@ Class UserGateway{
$this->con->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR))); $this->con->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR)));
return $this->con->getResults(); return $this->con->getResults();
} }
public function findEmail(string $email):array{
$query = 'SELECT * FROM Users WHERE email= :email';
$this->con->executeQuery($query, array(':username'=>array($email, PDO::PARAM_STR)));
return $this->con->getResults();
}
// ===================== UPDATE FUNCTION ===================== // ===================== UPDATE FUNCTION =====================
public function updateUsername(int $id, string $newUsername):bool{ public function updateUsername(int $id, string $newUsername):bool{

@ -1,7 +1,8 @@
<?php <?php
namespace Model; namespace Model;
use Entity\User; use Entity\User;
use Gateway\UserGateway; use Entity\UserEntity;
use Gateway\UserGateway;
class UserModel class UserModel
{ {
@ -28,36 +29,56 @@
// public function getFavoriteUser(string $id) : array{ // public function getFavoriteUser(string $id) : array{
// $res = array(); // $res[0] = array();
// $data = $this->gateway->getFavorite($id); // $data = $this->gateway->getFavorite($id);
// foreach ($data as $favoris) { // foreach ($data as $favoris) {
// $res[] = new Quote(); // $res[0][] = new Quote();
// } // }
// } // }
public function getDataUser(int $id) : ?User { public function getDataUser(int $id) : ?UserEntity {
$res = $this->gateway->findDataUser($id); $res = $this->gateway->findDataUser($id);
if ($res) if ($res)
return new User( return new UserEntity(
$res['id_user'], $res[0]['id_user'],
$res['username'], $res[0]['username'],
$res['pssword'], $res[0]['pssword'],
$res['img'], $res[0]['email'],
$res['email'] $res[0]['img_prfl'],
$res[0]['is_admin'],
$res[0]['creation']
); );
return null; return null;
} }
public function getUsername(string $username) : ?User public function getUsername(string $username) : ?UserEntity
{ {
$res = $this->gateway->findUsername($username); $res = $this->gateway->findUsername($username);
if ($res) if ($res)
return new User( return new UserEntity(
$res['id_user'], $res[0]['id_user'],
$res['username'], $res[0]['username'],
$res['pssword'], $res[0]['pssword'],
$res['img'], $res[0]['email'],
$res['email'] $res[0]['img_prfl'],
$res[0]['is_admin'],
$res[0]['creation']
);
return null;
}
public function getEmail(string $email) : ?UserEntity
{
$res = $this->gateway->findUsername($email);
if ($res)
return new UserEntity(
$res[0]['id_user'],
$res[0]['username'],
$res[0]['pssword'],
$res[0]['email'],
$res[0]['imgPrfl'],
$res[0]['isAdmin'],
$res[0]['date']
); );
return null; return null;
} }

Loading…
Cancel
Save