reparation master

pull/21/head
brongniart 5 months ago
parent aa39b5db37
commit bf3ecbd32f

@ -16,13 +16,12 @@ $mdp = '';
$vues['erreur'] = 'vue/erreur.php';
$vues['accueil'] = 'vue/accueil.php';
$vues['quote'] = 'vue/quote.php';
$vues['profil'] = 'vue/profil.php';
$vues['login'] = 'vue/login.php';
$vues['signin'] = 'vue/signin.php';
$vues['quiz'] = 'vue/quiz.html';
$vues['search'] = 'vue/search.php';
$vues['favorite'] = 'vue/favorits.php';
$vues['profil'] = 'vue/profil.php';
//Style css

@ -1,10 +1,15 @@
<?php
session_start();
$_SESSION['role']='user';
$_SESSION['user']='bob_brown';
$_SESSION['theme']='dark';
if(!isset($_SESSION['role'])){
$_SESSION['role']='visitor';
}
if(!isset($_SESSION['user'])){
$_SESSION['user']=NULL;
}
if(!isset($_SESSION['theme'])){
$_SESSION['theme']='dark';
}
//chargement config
require_once __DIR__ . '/config/config.php';

@ -33,7 +33,6 @@
height: 150px;
}
.quote {
background: linear-gradient(180deg, rgba(187,211,249,1) 0%, rgba(199,246,196,1) 100%);
padding: 0;
overflow: hidden;
}

@ -7,14 +7,12 @@ Class FrontControler{
private $listAction;
private string $role = 'visitor'; //Mettre en admin le temps de créer les comptes
private Connection $co;
public function __construct($co){
global $twig;
$this->listAction = ['visitor' => array('accueil','search','quote','login','signin'),
$this->listAction = ['visitor' => array('accueil','search','quote','login','signin','validlogin','validsignin'),
'user' => array('quiz','commentary','logout','addComment','favorite','profil'),
'admin' => array('null')];
@ -43,6 +41,8 @@ Class FrontControler{
$router->map('GET|POST', '/profil', 'UserControler','profil');
$router->map('GET|POST', '/login', 'VisitorControler','login');
$router->map('GET|POST', '/signin', 'VisitorControler','signin');
$router->map('GET|POST', '/validlogin', 'VisitorControler','validlogin');
$router->map('GET|POST', '/validsignin', 'VisitorControler','validsignin');
$match = $router->match();
@ -92,9 +92,9 @@ Class FrontControler{
}
private function verifDroit(string $action):bool {
if( in_array($action , $this->listAction['admin']) && $this->role == 'admin') return true;
elseif( in_array($action , $this->listAction['user']) && ($this->role == 'admin' || $this->role == 'user') ) return true;
elseif(in_array($action , $this->listAction['visitor']) && ($this->role == 'admin'|| $this->role == 'user'|| $this->role == 'visitor')) return true;
if( in_array($action , $this->listAction['admin']) && $_SESSION["role"] == 'admin') return true;
elseif( in_array($action , $this->listAction['user']) && ($_SESSION["role"] == 'admin' || $_SESSION["role"] == 'user') ) return true;
elseif(in_array($action , $this->listAction['visitor']) && ($_SESSION["role"] == 'admin'|| $_SESSION["role"] == 'user'|| $_SESSION["role"] == 'visitor')) return true;
return false;
}

@ -37,14 +37,14 @@ class UserControler {
public function addComment(){
$id = $_POST['idQuote'];
$this->cMod->createComment($_POST['content'],$_POST['idQuote'],$this->uMod->getIdByUsername($_SESSION['user']));
header("Location: /~kemondejar/WF-Website/quote/$id");
header("Location: /~kekentin/WF/WF-Website/quote/$id");
}
public function favorite(array $args) {
global $vues;
$userId = 1;
$userId = $this->uMod->getIdByUsername($_SESSION["user"]);
$favorites = $this->quoteGateway->getFavorites($userId);

@ -81,30 +81,21 @@ Class VisitorControler {
require_once $vues['search'];
}
/**
* @throws SyntaxError
* @throws RuntimeError
* @throws LoaderError
*/
public function getAction(string $action): void
public function login()
{
switch ($action) {
case "login":
$this -> visitorLogIn();
break;
case "signin":
$this -> visitorSignIn();
break;
case "validsignin":
$this -> toSignIn();
break;
case "validlogin":
$this -> toLogIn();
break;
default:
break;
}
global $vues;
require_once $vues['login'];
// global $twig;
// echo $twig->render("login.html.twig");
//$this -> toLogIn();
}
/**
@ -112,20 +103,19 @@ Class VisitorControler {
* @throws RuntimeError
* @throws LoaderError
*/
public function login()
public function signin(): void
{
global $vues;
require_once $vues['login'];
require_once $vues['signin'];
}
// global $twig;
// echo $twig->render("login.html.twig");
$this -> toLogIn();
}
public function toLogIn() : void
public function validlogin() : void
{
global $vues;
if ($_POST)
{
$pseudo = $_POST['pseudo'] ?? null;
@ -139,49 +129,34 @@ Class VisitorControler {
{
$_SESSION['user'] = $pseudo;
$_SESSION['role'] = 'user';
header("Location: /");
header("Location: /~kekentin/WF/WF-Website/");
exit();
}else
{
global $twig;
$this -> errors = ["Identifiant ou mot de passe incorrect"];
echo $twig -> render("login.html.twig", ['error' => $this -> errors[0]]);
$errors = "Identifiant ou mot de passe incorrect";
require_once $vues['login'];
exit();
}
}
else
{
global $twig;
$this -> errors = ["Identifiant ou mot de passe incorrect"];
echo $twig -> render("login.html.twig", ['error' => $this -> errors[0]]);
$errors = "Identifiant ou mot de passe incorrect";
require_once $vues['login'];
exit();
}
}
}
/**
* @throws SyntaxError
* @throws RuntimeError
* @throws LoaderError
*/
public function signin(): void
{
global $twig;
echo $twig->render("signin.html.twig");
}
/**
* @throws RuntimeError
* @throws SyntaxError
* @throws LoaderError
*/
public function toSignIn() : void
public function validsignin() : void
{
global $twig;
$this -> errors = [null, null, null];
global $vues;
if ($_POST) {
$pseudo = $_POST['pseudo'] ?? null;
@ -190,9 +165,9 @@ Class VisitorControler {
$cmdp = $_POST['cmdp'] ?? null;
if ($mdp != $cmdp) {
$this->errors[2] = "Mots de passe incorrects";
//$this->visitorSignIn();
echo $twig->render("signin.html.twig", ['error' => $this->errors]);
$errors[2] = "Mots de passe incorrects";
require_once $vues['signin'];
exit();
}
$option = ['cost' => 12];
@ -202,20 +177,27 @@ Class VisitorControler {
$isEmailAlreadyUsed = $this -> mdl -> getEmail($email);
if ($isUserAlreadyUsed and !$isEmailAlreadyUsed) {
$this->errors[0] = "Pseudo déjà utilisé";
echo $twig->render("signin.html.twig", ['error' => $this->errors]);
$errors[0] = "Pseudo déjà utilisé";
require_once $vues['signin'];
exit();
}
else if ($isEmailAlreadyUsed and !$isUserAlreadyUsed) {
$this->errors[1] = "Email déjà utilisé";
echo $twig->render("signin.html.twig", ['error' => $this->errors]);
$errors[1] = "Email déjà utilisé";
require_once $vues['signin'];
exit();
}
else if ($isEmailAlreadyUsed and $isUserAlreadyUsed) {
$errors[0] = "Pseudo déjà utilisé";
$errors[1] = "Email déjà utilisé";
require_once $vues['signin'];
exit();
}
else echo $this->mdl->insertUser($pseudo, $email, $hmdp);
$_SESSION["pseudo"] = $pseudo;
$_SESSION["role"] = 'user';
$_SESSION["user"] = $pseudo;
header("Location: /");
header("Location: /~kekentin/WF/WF-Website/profil");
}
}
}

@ -1,158 +0,0 @@
<?php
namespace Entity;
class UserEntity {
private int $id;
private string $pseudo;
private string $password;
private string $email;
private string $date;
private bool $isAdmin;
private int $imgPrfl;
public function getId(): int
{
return $this->id;
}
public function setId(int $id): void
{
$this->id = $id;
}
public function getPseudo(): string
{
return $this->pseudo;
}
public function setPseudo(string $pseudo): void
{
$this->pseudo = $pseudo;
}
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): void
{
$this->password = $password;
}
public function getEmail(): string
{
return $this->email;
}
public function setEmail(string $email): void
{
$this->email = $email;
}
public function getDate(): string
{
return $this->date;
}
public function setDate(string $date): void
{
$this->date = $date;
}
public function isAdmin(): bool
{
return $this->isAdmin;
}
public function setIsAdmin(bool $isAdmin): void
{
$this->isAdmin = $isAdmin;
}
public function getImgPrfl(): int
{
return $this->imgPrfl;
}
public function setImgPrfl(int $imgPrfl): void
{
$this->imgPrfl = $imgPrfl;
}
/**
* @param int $id
* @param string $pseudo
* @param string $password
* @param string $email
* @param int $imgPrfl
* @param bool $isAdmin
* @param string $date
*/
public function __construct(int $id, string $pseudo, string $password, string $email, int $imgPrfl, bool $isAdmin, string $date)
{
$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";
$username = "lebeaulato";
$password = "";
$con = new Connection($dsn,$username,$password);
$query = 'SELECT * FROM Users WHERE id_user=:idUser';
$con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR)));
$result = $con->getResults();
$u = new User($result[0]['id_user'],$result[0]['username'], $result[0]['pssword'], '../images/imageProfil.png', $result[0]['email']);
//UPDATE username User
$query = 'UPDATE Users SET username=:newUsername WHERE id_user=:idUser';
$con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR), ':newUsername'=> array('Hello', PDO::PARAM_STR)));
$queryReponse = 'SELECT username FROM Users WHERE id_user=:idUser';
$con->executeQuery($queryReponse, array(':idUser'=>array('U003', PDO::PARAM_STR)));
$result = $con->getResults();
$u->setUsername($result[0]['username']);
//UPDATE email User
$query = 'UPDATE Users SET email=:newEmail WHERE id_user=:idUser';
$con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR), ':newEmail'=> array('hello@gmail.com', PDO::PARAM_STR)));
$queryReponse = 'SELECT email FROM Users WHERE id_user=:idUser';
$con->executeQuery($queryReponse, array(':idUser'=>array('U003', PDO::PARAM_STR)));
$result = $con->getResults();
$u->setEmail($result[0]['email']);
//UPDATE passwd User
$query = 'UPDATE Users SET pssword=:newPassWd WHERE id_user=:idUser';
$con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR), ':newPassWd'=> array('TestMotDePasssse', PDO::PARAM_STR)));
$queryReponse = 'SELECT pssword FROM Users WHERE id_user=:idUser';
$con->executeQuery($queryReponse, array(':idUser'=>array('U003', PDO::PARAM_STR)));
$result = $con->getResults();
$u->setPasswd($result[0]['pssword']); /*Test*/
// ================================================================================================================
function hidenPassWd(string $passwd){
if(strlen($passwd) >= 16) return str_repeat('*', 16);
return str_repeat('*', strlen($passwd));
}
?>

@ -8,14 +8,28 @@ class CommentaryGateway {
$this->co = $co;
}
public function firstIdComment():int{
$query = "Select id_comment from Commentary;";
$this -> co -> executeQuery($query);
$res = $this -> co -> getResults();
foreach($res as $r){
$tab[] = $r["id_comment"];
}
$id=1;
while(in_array($id,$tab)){$id=$id+1;}
return $id;
}
public function create(string $comment ,string $idUser, int $idQuote) :bool {
$id=$this->firstIdComment();
$query="INSERT INTO Commentary(quote,users,datec,comment) VALUES(:idQuote, :idUser , CURRENT_DATE,:comment )";
$query="INSERT INTO Commentary(quote,users,datec,comment,id_comment) VALUES(:idQuote, :idUser , CURRENT_DATE,:comment ,:idComment)";
return $this -> co -> executeQuery($query, array(
"comment" => array($comment, PDO::PARAM_STR),
"idUser" => array($idUser, PDO::PARAM_STR),
"idQuote" => array($idQuote, PDO::PARAM_INT)));
"idQuote" => array($idQuote, PDO::PARAM_INT),
"idComment" => array($id, PDO::PARAM_INT)));
}
public function findById(int $id) : array {
@ -27,7 +41,7 @@ class CommentaryGateway {
}
public function findByQuote(int $id) : array{
$query="SELECT c.id_comment, c.dateC, c.comment, u.username FROM Commentary c JOIN Users u ON u.id_user = c.users WHERE quote = :idQuote";
$query="SELECT c.id_comment, c.dateC, c.comment, u.username FROM Commentary c JOIN Users u ON u.id_user = c.users WHERE quote = :idQuote ORDER BY c.datec DESC";
$this -> co -> executeQuery($query, array("idQuote" => array($id,PDO::PARAM_STR)));
return $res = $this -> co -> getResults();
}

@ -19,21 +19,34 @@ Class UserGateway{
return $this -> con -> getResults();
}
public function insertUser(int $id, string $pseudo, string $email, string $password, bool $isAdmin, int $imgPrfl) : bool {
public function firstIdUser():int{
$query = "Select id_user from Users;";
$this -> con -> executeQuery($query);
$res = $this -> con -> getResults();
foreach($res as $r){
$tab[] = $r["id_user"];
}
$id=1;
while(in_array($id,$tab)){$id=$id+1;}
return $id;
}
public function insertUser(string $pseudo, string $email, string $password, bool $isAdmin, int $imgPrfl) : bool {
$id=$this->firstIdUser();
$query = "
INSERT INTO Users
VALUES (:id, :pseudo, :email, :password, CURRENT_DATE, :isAdmin, :imgPrfl)
INSERT INTO Users(id_user,username,email,password,creation,img)
VALUES (:id, :pseudo, :email, :password, CURRENT_DATE, :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

@ -14,7 +14,7 @@
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);
return $this->gateway->insertUser( $username, $email, $passwd, false, 1);
}
public function getNumberOfUsers() : int
@ -42,10 +42,9 @@
return new UserEntity(
$res[0]['id_user'],
$res[0]['username'],
$res[0]['pssword'],
$res[0]['password'],
$res[0]['email'],
$res[0]['img_prfl'],
$res[0]['is_admin'],
$res[0]['img'],
$res[0]['creation']
);
return null;
@ -58,10 +57,9 @@
return new UserEntity(
$res[0]['id_user'],
$res[0]['username'],
$res[0]['pssword'],
$res[0]['password'],
$res[0]['email'],
$res[0]['img_prfl'],
$res[0]['is_admin'],
$res[0]['img'],
$res[0]['creation']
);
return null;
@ -74,10 +72,9 @@
return new UserEntity(
$res[0]['id_user'],
$res[0]['username'],
$res[0]['pssword'],
$res[0]['password'],
$res[0]['email'],
$res[0]['img_prfl'],
$res[0]['is_admin'],
$res[0]['img'],
$res[0]['creation']
);
return null;

@ -9,5 +9,7 @@
));
echo $twig->render('bandeau.html.twig');
echo $twig->render('login.html.twig');
echo $twig->render('login.html.twig',array(
'error' => $errors??null
));
?>

@ -1,5 +1,4 @@
<?php
global $twig;
echo $twig->render('head.html.twig', array(
@ -9,5 +8,7 @@
));
echo $twig->render('bandeau.html.twig');
echo $twig->render('signin.html');
echo $twig->render('signin.html.twig',array(
'error'=>$errors??null)
);
?>

@ -1,33 +1,6 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../public/styles/styleLogin.css" media="screen">
<title>Wiki Fantasy : Connexion</title>
<link id="favicon" rel="icon" href="../../images/iconeSombre.ico"> <!-- Par défaut sombre -->
<link href="https://fonts.googleapis.com/css2?family=Lemon&display=swap" rel="stylesheet">
<script defer src="../public/script/theme-toggle.js"></script>
</head>
<body>
<div class="container">
<div class="header">
<div class="nav">
<img src="../images/coeur.svg" alt="coeur" width="67px" height="67px" onmousedown="return false">
<img id="theme-icon" src="../images/light.svg" alt="toggle theme" width="72px" height="37px" onmousedown="return false" onclick="toggleTheme()">
<img src="../images/quizz.svg" alt="quizz" width="51px" height="82px" onmousedown="return false">
</div>
<div class="logo">
<a href="accueil.html"><img src="../images/WIKIFANTASY.png" alt="Logo" width="227px" height="106px" onmousedown="return false"></a>
</div>
<div class="user">
<img src="../images/user_dark.png" alt="user" width="70px" height="70px" onmousedown="return false">
</div>
</div>
</div>
<h1>▶ Connexion ◀</h1>
<form class="login" method="post" action="/validlogin">
<form class="login" method="post" action="{{ racine }}/validlogin">
<p> <strong>Identifiant *</strong></p>
<input type="text" class="connexion" name="pseudo" id="pseudo" placeholder="Entrez votre pseudo" required />

@ -1,32 +1,5 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../public/styles/styleSignin.css" media="screen">
<title>Wiki Fantasy : Inscription</title>
<link id="favicon" rel="icon" href="../images/iconeSombre.ico"> <!-- Par défaut sombre -->
<link href="https://fonts.googleapis.com/css2?family=Lemon&display=swap" rel="stylesheet">
<script defer src="../public/script/theme-toggle.js"></script>
</head>
<body>
<div class="container">
<div class="header">
<div class="nav">
<a href="favorite.html"><img src="../images/coeur.svg" alt="coeur" width="67px" height="67px" onmousedown="return false"></a>
<img id="theme-icon" src="../images/light.svg" alt="toggle theme" width="72px" height="37px" onmousedown="return false" onclick="toggleTheme()">
<a href="quiz.html"><img src="../images/quizz.svg" alt="quizz" width="51px" height="82px" onmousedown="return false"></a>
</div>
<div class="logo">
<a href="accueil.html"><img src="../images/WIKIFANTASY.png" alt="Logo" width="227px" height="106px" onmousedown="return false"></a>
</div>
<div class="user">
<img src="../images/user_dark.png" alt="user" width="70px" height="70px" onmousedown="return false">
</div>
</div>
</div>
<h1>▶ S'inscrire ◀</h1>
<form method="post" action="/validsignin">
<form method="post" action="{{ racine }}/validsignin">
<div class="signin">
<div class="DivId">
<p>Identifiant *</p>
@ -63,7 +36,7 @@
<div class="connectAccount">
<p class="createAccount">Vous avez un compte?</p>
<a href="/login" class="connectAccount">Se connecter</a>
<a href="{{ racine }}/login" class="connectAccount">Se connecter</a>
</div>
<div class="confirmer">
<input type="submit" class="btn" name="action" value="S'inscrire" />

Loading…
Cancel
Save