diff --git a/accueil.php b/accueil.php index 21d604914167bd9e269f540e7b66accb64f2fa87..d33986263f1ba7bba6b853101a3e867b79fcaaee 100644 --- a/accueil.php +++ b/accueil.php @@ -28,7 +28,8 @@ $bdd=bdd(); ?> <button type="button" class="btn btn-success btn-right" onclick="location.href='./edit.php'" >Edit</button> <button type="button" class="btn btn-success btn-right" onclick="location.href='./deconnexion.php'">Deconnexion</button> - <label for="hello"><?php echo "Bonjour, $pseudo";?></label> + <button type="button" class="btn btn-success btn-right" onclick="location.href='./newtopics.php'" >Nouveau sujet</button> + <label for="hello"><?php echo "Vous êtes connectés entant que : $pseudo";?></label> <?php } else @@ -48,10 +49,16 @@ $bdd=bdd(); <ul class="nav navbar-nav"> <li class="dropdown active"><a class="dropdown-toggle" data-toggle="dropdown" href="./topiclist.php">Commercial <span class="caret"></span></a> <ul class="dropdown-menu"> - <li><a id="cat" href="./topiclist.php">Multimédia</a></li> - <li><a id="cat" href="./topiclist.php">Vêtement</a></li> - <li><a id="cat" href="./topiclist.php">Animal</a></li> - <li><a id="cat" href="./topiclist.php">Autre</a></li> + <?php + + $dn2 = pg_query("SELECT * FROM keys ORDER BY name asc"); + while($reponse=pg_fetch_assoc($dn2)) + { + ?> + <li><a id="cat" href="./topiclist.php?category=<?php echo $reponse['name']; ?>"><?php echo $reponse['name']; ?></a></li> + <?php + } + ?> </ul> </li> </ul> @@ -63,47 +70,24 @@ $bdd=bdd(); <div class="container-fluid text-center"> <div class="row content"> <div class="col-sm-2 sidenav"> - <p><a href="#">Link</a></p> - <p><a href="#">Link</a></p> - <p><a href="#">Link</a></p> + </div> - <div class="col-lg-8 text-left"> - <table id="tableAccueil"> - <col width="50%"> - <col width="50%"> - <tbody> - <tr class="accueil"> - <td> - <a href="./topiclist.php"> - <img src="./img/Multimedia.jpg" alt="Multimedia" style="width:180px;height:120px"> - <p id="mPic">Multimédia</p> - </a> - </td> - <td> - <a href="./topiclist.php"> - <img src="./img/vetement.png" alt="Vetement" style="width:180px;height:120px"> - <p id="vPic">Vêtement</p> - </a> - </td> - </tr> - <tr class="accueil"> - <td> - <a href="./topiclist.php"> - <img src="./img/animal.jpg" alt="Multimedia" style="width:150px;height:120px"> - <p id="aPic">Animal</p> - </a> - </td> - <td> - <a href="./topiclist.php"> - <img src="./img/autre.png" alt="Autre" style="width:180px;height:120px"> - <p id="oPic">Autre</p> - </a> - </td> + <div class="col-lg-8 lg-8 text-left"> + <table class="table"> + <col width="20%"> + <col width="60%"> + <col width="20%"> + <thead> + <tr> + <th class="lead">Catégorie</th> + <th class="lead">Sujet</th> + <th class="lead">Date</th> + </tr> - </tbody> - </table> - </div> + </thead> + </table> + </div> </div> diff --git a/class/connexion.class.php b/class/connexion.class.php index 4c7fb7cb4c8a17037fb440f9ea8af73dc7df811e..ba31f75235bb54bf2a2f8abca25a5a46df408718 100644 --- a/class/connexion.class.php +++ b/class/connexion.class.php @@ -17,15 +17,15 @@ class connexion public function verify() { - $requete = "SELECT * FROM users WHERE pseudo = '$this->pseudo' AND mdp ='$this->mdp'"; - $sql = pg_query($requete); - if($sql) + $requete = pg_query("SELECT * FROM users WHERE pseudo = '$this->pseudo'"); + $sql = pg_fetch_array(($requete)); + if($sql AND password_verify($this->mdp,$sql['mdp'])) { - return 1; + return "ok"; } else { - return 0; + return "Erreur d'authentification"; } } diff --git a/class/inscription.class.php b/class/inscription.class.php index 6c8b1f46e1b81ce0210d6a9f0099b8ef0d7d0ac6..e977c746e581f9ddb70586f937103c6a969cb324 100644 --- a/class/inscription.class.php +++ b/class/inscription.class.php @@ -28,7 +28,7 @@ class inscription { if(strlen($this->mdp) >= 6 AND strlen($this->mdp) <= 30) { - if($this->mdp === $this->mdpC) + if($this->mdp == $this->mdpC) { $syntax = "#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#"; if(preg_match($syntax, $this->mail)) @@ -58,7 +58,8 @@ class inscription public function enregistrer() { - $requete = ("INSERT INTO users(pseudo,mdp,adr_mail) VALUES('$this->pseudo','$this->mdp','$this->mail')"); + $this->mdp = password_hash($this->mdp, PASSWORD_BCRYPT); + $requete = ("INSERT INTO users(pseudo, mdp, adr_mail) VALUES('$this->pseudo','$this->mdp','$this->mail')"); $sql=pg_query($requete); return 1; diff --git a/class/newtopics.class.php b/class/newtopics.class.php new file mode 100644 index 0000000000000000000000000000000000000000..a77d1dcd2c6375d6ac15508250e9e31a016e7aca --- /dev/null +++ b/class/newtopics.class.php @@ -0,0 +1,45 @@ +<?php +require_once"/../fonction.php"; +class newtopics +{ + private $name; + private $content; + private $bdd; + + public function __construct($name, $content) + { + $name = htmlspecialchars($name); + $content = htmlspecialchars($content); + + $this->name = $name; + $this->content = $content; + $this->bdd= bdd(); + } + + public function verif() + { + if (strlen($this->name) >=5 AND strlen($this->name) <= 40) { + if (strlen($this->content)<=10) { + return "Veuillez saisir une déscription compléte"; + } + else + { + return "ok"; + } + } + else + { + return "Le nom du sujet doit contenir 5 carctéres minimum et 40 maximum" + } + } + + public function insert() + { + $id = $_SESSION['id']; + $requete = "INSERT INTO toppics values('$this->name', '$this->content', '$id')"; + $sql = pg_query($requete); + + return 1; + } +} +?> \ No newline at end of file diff --git a/login.php b/login.php index 4a1c2fa4c314e56e45b7f5b2d78eefd964bae59f..3413ece978408ef828f5138df35758b7e107c8b1 100644 --- a/login.php +++ b/login.php @@ -11,11 +11,10 @@ if (isset($_POST['pseudo']) AND isset($_POST['mdp'])) $mdp = $_POST['mdp']; $connexion = new connexion($pseudo, $mdp); $verif = $connexion->verify(); - if($verif == 1) + if($verif=="ok") { - if ($connexion->session()) { - header("Location: ./accueil.php"); - } + $verif = $connexion->session(); + header("Location: ./accueil.php"); } else { @@ -58,9 +57,15 @@ if (isset($_POST['pseudo']) AND isset($_POST['mdp'])) <ul class="nav navbar-nav"> <li class="dropdown active"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Commercial <span class="caret"></span></a> <ul class="dropdown-menu"> - <li><a href="#">Livre</a></li> - <li><a href="#">Electric</a></li> - <li><a href="#">Loisir</a></li> + <?php + $dn2 = pg_query("SELECT * FROM keys ORDER BY name asc"); + while($reponse=pg_fetch_assoc($dn2)) + { + ?> + <li><a id="cat" href="./topiclist.php?category=<?php echo $reponse['name']; ?>"><?php echo $reponse['name']; ?></a></li> + <?php + } + ?> </ul> </li> </ul> diff --git a/newtopics.php b/newtopics.php new file mode 100644 index 0000000000000000000000000000000000000000..f1a817cd7eabbca7349086033f9621502ae2a579 --- /dev/null +++ b/newtopics.php @@ -0,0 +1,140 @@ +<?php +session_start(); +require_once"fonction.php"; +require_once"./class/newtopics.class.php"; +$bdd=bdd(); + +if (isset($_POST['name'], $_POST['content']) { + $name=$_POST['name']; + $content = $_POST['content']; + $newtop = new newtopics($name, $content); + $verif = $newtop->verif(); + + if ($verif =="ok") { + $insert = $newtop->insert(); + } + else + { + $erreur = $verif; + } +} + +?> + +<!DOCTYPE html> +<html lang="en"> +<head> + <title>Com-Ensiie</title> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <link rel="stylesheet" href="./bootstrap/css/bootstrap.css"> + <link rel="stylesheet" href="./bootstrap/css/mystyle.css"> + <script src="./bootstrap/js/jquery.min.js"></script> + <script src="./bootstrap/js/bootstrap.min.js"></script> +</head> +<body> + <div class="container-fluid"> + <div class="jumbotron"> + <h1><span style="color: white">Com-Ensiie</span></h1> +<?php +if(isset($_SESSION['pseudo'])){ + $pseudo=$_SESSION['pseudo']; +?> + </div> + <button type="button" class="btn btn-success btn-right" onclick="location.href='./deconnexion.php'" >Deconnexion</button> + <button type="button" class="btn btn-success btn-right" onclick="location.href='./edit.php'" >Edit</button> + <label for="hello"><?php echo "Vous êtes connectés entant que : $pseudo";?></label> + </div> +<?php +} +else +{ +?> + </div> + <button type="button" class="btn btn-success btn-right" onclick="location.href='./login.php'" >Log In</button> + <button type="button" class="btn btn-success btn-right" onclick="location.href='./register.php'">Register</button> + </div> +<?php +} +?> + <nav class="navbar navbar-inverse"> + <div class="navbar-header"> + <a class="navbar-brand" href="./accueil.php">Com-Ensiie</a> + </div> + <ul class="nav navbar-nav"> + <li class="dropdown active"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Commercial <span class="caret"></span></a> + <ul class="dropdown-menu"> + <?php + $dn2 = pg_query("SELECT * FROM keys ORDER BY name asc"); + while($reponse=pg_fetch_assoc($dn2)) + { + ?> + <li><a id="cat" href="./topiclist.php?category=<?php echo $reponse['name']; ?>"><?php echo $reponse['name']; ?></a></li> + + <?php + } + ?> + </ul> + </li> + </ul> + </nav> +</div> + + + +<div class="container-fluid text-center"> + <div class="row content"> + <div class="col-sm-2 sidenav"> + + </div> + <div class="col-lg-8 text-left"> + <h1>Create Topic</h1> + <form class="form-horizontal" role="form" method="post" action="./newtopics.php"> + <div class="row topic-create"> + <div class="col-sm-2 text-right"> + <label class="col-sm-2 text-right">Catégorie</label> + </div> + <div class="col-sm-10"> + <select class="selectpicker" name="category"> + <?php + $dn2 = pg_query("SELECT * FROM keys ORDER BY name asc"); + while($reponse=pg_fetch_assoc($dn2)) + { + ?> + <option id="cat"><?php echo $reponse['name']; ?></a></li> + + <?php + } + ?> + + </select> + </div> + </div> + <div class="row topic-create"> + <label class="col-sm-2 text-right">Titre</label> + <div class="col-sm-10"> + <input class="form-control" id="focusedInput" type="text" name="name" placeholder ="Le titre ..."required> + </div> + </div> + <div class="row topic-create"> + <label class="col-sm-2 text-right ">Déscription</label> + <div class="col-sm-10"> + <textarea name="content" class="form-control" rows="5" placeholder="Le contenu ..."required></textarea> + </div> + </div> + <button id="submit" class="btn btn-primary topic-create center-block">Ajouter</button> + <?php + if (isset($erreur)) { + echo $erreur; + } + ?> + </form> + </div> + + + </div> +</div> + <div class="footer"></div> +</div> +</body> +</html> diff --git a/register.php b/register.php index 23b697f0256123bd89eae364e3b1764c8f46ca65..2db0d0e71a725799a7d5dc64e6d172772de94cd7 100644 --- a/register.php +++ b/register.php @@ -1,8 +1,27 @@ <?php +session_start(); require_once"fonction.php"; require_once"/class/inscription.class.php"; $bdd=bdd(); +if (isset($_POST['pseudo'], $_POST['mdp'], $_POST['mdpC'], $_POST['mail'])) +{ + $pseudo = $_POST['pseudo']; + $mdp = $_POST['mdp']; + $mdpC = $_POST['mdpC']; + $mail = $_POST['mail']; + $inscription = new inscription($pseudo, $mail, $mdp, $mdpC); + $verif = $inscription->verify(); + if ($verif=="ok") { + $inscription->enregistrer(); + header("Location: login.php"); + exit; + } + else + { + $erreur = $verif; + } +} ?> <!DOCTYPE html> <html lang="en"> @@ -32,9 +51,15 @@ $bdd=bdd(); <ul class="nav navbar-nav"> <li class="dropdown active"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Commercial <span class="caret"></span></a> <ul class="dropdown-menu"> - <li><a href="#">Livre</a></li> - <li><a href="#">Electric</a></li> - <li><a href="#">Loisir</a></li> + <?php + $dn2 = pg_query("SELECT * FROM keys ORDER BY name asc"); + while($reponse=pg_fetch_assoc($dn2)) + { + ?> + <li><a id="cat" href="./topiclist.php?category=<?php echo $reponse['name']; ?>"><?php echo $reponse['name']; ?></a></li> + <?php + } + ?> </ul> </li> </ul> @@ -44,9 +69,7 @@ $bdd=bdd(); <div class="container-fluid text-center"> <div class="row content"> <div class="col-sm-2 sidenav"> - <p><a href="#">Link</a></p> - <p><a href="#">Link</a></p> - <p><a href="#">Link</a></p> + </div> <div class="col-lg-8 text-left"> @@ -86,7 +109,12 @@ $bdd=bdd(); <div class="form-group"> <div class="col-sm-offset-2 col-xs-4"> - <input type="submit" name="signup" class="btn btn-primary" value="S'enregistrer"> + <button type="submit" name="signup" class="btn btn-primary">S'enregistrer</button> + <?php + if (isset($erreur)) { + echo $erreur; + } + ?> </div> </div> </form> diff --git a/topiclist.php b/topiclist.php index 5fba91cb2960128d1bf1009873e57aeea3625265..2adf233a361afdaa80a9726f75908f5292f846d4 100644 --- a/topiclist.php +++ b/topiclist.php @@ -28,7 +28,7 @@ if(isset($_SESSION['pseudo'])){ <button type="button" class="btn btn-success btn-right" onclick="location.href='./deconnexion.php'" >Deconnexion</button> <button type="button" class="btn btn-success btn-right" onclick="location.href='./edit.php'" >Edit</button> <button type="button" class="btn btn-success btn-right" onclick="location.href='./newtopic.php'" >Nouveau sujet</button> - <label for="hello"><?php echo "Bonjour, $pseudo";?></label> + <label for="hello"><?php echo "Vous êtes connectés entant que : $pseudo";?></label> <?php } @@ -42,6 +42,7 @@ else } ?> </div> +<div> <nav class="navbar navbar-inverse"> <div class="navbar-header"> <a class="navbar-brand" href="accueil.php">Com-Ensiie</a> @@ -49,48 +50,59 @@ else <ul class="nav navbar-nav"> <li class="dropdown active"><a class="dropdown-toggle" data-toggle="dropdown" href="./topiclist.php">Commercial <span class="caret"></span></a> <ul class="dropdown-menu"> - <li><a id="cat" href="./topiclist.php">Multimédia</a></li> - <li><a id="cat" href="./topiclist.php">Vêtement</a></li> - <li><a id="cat" href="./topiclist.php">Animal</a></li> - <li><a id="cat" href="./topiclist.php">Autre</a></li> + <?php + + $dn2 = pg_query("SELECT * FROM keys ORDER BY name asc"); + while($reponse=pg_fetch_assoc($dn2)) + { + ?> + <li><a id="cat" href="./topiclist.php?category=<?php echo $reponse['name']; ?>"><?php echo $reponse['name']; ?></a></li> + <?php + } + ?> </ul> </li> </ul> </nav> + </div> + <div class="container-fluid text-center"> + <div class="row content"> + <div class="col-sm-2 sidenav"> + + </div> <?php - -$dn2 = pg_query("SELECT * FROM toppics NATURAL JOIN users"); -$nb = pg_fetch_row($dn2); -if($nb>=0) +if(isset($_GET['name'])){ + $name=htmlspecialchars($_GET['name']); + $sql=pg_query("SELECT * FROM toppics WHERE name='$name' ORDER BY date"); +} +else { + $sql=pg_query("SELECT * FROM toppics ORDER BY date"); +} ?> <div class="col-lg-8 lg-8 text-left"> <table class="table"> - <col width="20%"> - <col width="60%"> - <col width="20%"> - <thead> - <tr> - <th class="lead">Category</th> - <th class="lead">Sujet</th> - <th class="lead">Date</th> - <?php - if(isset($_SESSION['pseudo']) and $_SESSION['su']) - { - ?> - <th class="lead">Action</th> - <?php - } - ?> - </tr> - </thead> - - </tr> -<div class="message">Cette catégorie ne contient aucun sujet.</div> -<?php -} -?> + <col width="20%"> + <col width="60%"> + <col width="20%"> + <thead> + <tr> + <th class="lead">Category</th> + <th class="lead">Sujet</th> + <th class="lead">Date</th> + <?php + while($reponse=pg_fetch_assoc($sql)) + { + } + ?> + </tr> + </thead> + </table> +</div> + <div class="message">Cette catégorie ne contient aucun sujet.</div> +</div> +</div> </body> </html> \ No newline at end of file