Add login
This commit is contained in:
parent
42de15afa0
commit
655b15286a
5 changed files with 48 additions and 1 deletions
|
@ -1,3 +1,12 @@
|
|||
<?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
11
lib/getPDD.php
Normal 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;
|
||||
}
|
||||
}
|
|
@ -1,2 +1,18 @@
|
|||
<?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");
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
<!-- Début de la page -->
|
||||
|
||||
<!-- 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 -->
|
||||
|
||||
|
|
|
@ -20,9 +20,15 @@
|
|||
<!-- Début de la page -->
|
||||
|
||||
<!-- Liste -->
|
||||
<?php if ($user) { ?>
|
||||
<ul>
|
||||
<?php for ($i=0;$i<$user["nbRepet"];$i++) { ?>
|
||||
<li><?= $user["mot"] ?></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<?php } ?>
|
||||
|
||||
<!-- Fin de la page -->
|
||||
|
||||
|
||||
<!-- Pied de page -->
|
||||
<?php require_once(PATH_VIEWS.'footer.php');
|
||||
|
|
Reference in a new issue