1
0
Fork 0

Add login

This commit is contained in:
Ethanell 2020-10-16 09:28:41 +02:00
parent 42de15afa0
commit 655b15286a
5 changed files with 48 additions and 1 deletions

View file

@ -1,3 +1,12 @@
<?php <?php
$user = false;
if (isset($_POST["username"]) AND $_POST["username"]) {
$username = htmlspecialchars($_POST["username"]);
require_once(PATH_MODELS.$page.".php");
if ($user)
require_once(PATH_VIEWS.$page.".php");
else
require_once(PATH_VIEWS."accueil.php");
}

11
lib/getPDD.php Normal file
View file

@ -0,0 +1,11 @@
<?php
function getPDO() {
try {
$bdd = new PDO("mysql:host=" . BD_HOST . ";dbname=" . BD_DBNAME . ";charset = utf8", BD_USER, BD_PWD);
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $bdd;
} catch (Exception $e) {
return $e;
}
}

View file

@ -1,2 +1,18 @@
<?php <?php
require_once("lib/getPDD.php");
$bdd = getPDO();
if ($bdd instanceof PDO) {
try {
$req = $bdd->prepare("SELECT * FROM Utilisateur WHERE nom = ?");
$req->execute(array($username));
if (!$user = $req->fetch())
$alert = choixAlert("login");
} catch (Exception $e) {
$alert = choixAlert("query");
}
} elseif ($bdd instanceof Exception)
$alert = choixAlert("connexion");

View file

@ -19,6 +19,11 @@
<!-- Début de la page --> <!-- Début de la page -->
<!-- Formulaire --> <!-- Formulaire -->
<form action="?page=hello" method="POST">
<label for="username">Username: </label>
<input id="username" type="text" name="username">
<input type="submit" value="Login">
</form>
<!-- Fin de la page --> <!-- Fin de la page -->

View file

@ -20,9 +20,15 @@
<!-- Début de la page --> <!-- Début de la page -->
<!-- Liste --> <!-- Liste -->
<?php if ($user) { ?>
<ul>
<?php for ($i=0;$i<$user["nbRepet"];$i++) { ?>
<li><?= $user["mot"] ?></li>
<?php } ?>
</ul>
<?php } ?>
<!-- Fin de la page --> <!-- Fin de la page -->
<!-- Pied de page --> <!-- Pied de page -->
<?php require_once(PATH_VIEWS.'footer.php'); <?php require_once(PATH_VIEWS.'footer.php');