Add register
This commit is contained in:
parent
655b15286a
commit
cf97fd7b3b
8 changed files with 87 additions and 5 deletions
|
@ -1,12 +1,11 @@
|
|||
<?php
|
||||
|
||||
$user = false;
|
||||
if (isset($_POST["username"]) AND $_POST["username"]) {
|
||||
$username = htmlspecialchars($_POST["username"]);
|
||||
if ((isset($_POST["username"]) AND $_POST["username"]) OR (isset($_GET["username"]) AND $_GET["username"])) {
|
||||
$username = (isset($_POST["username"]) AND $_POST["username"])? htmlspecialchars($_POST["username"]) : htmlspecialchars($_GET["username"]);
|
||||
require_once(PATH_MODELS.$page.".php");
|
||||
if ($user)
|
||||
require_once(PATH_VIEWS.$page.".php");
|
||||
else
|
||||
require_once(PATH_VIEWS."accueil.php");
|
||||
}
|
||||
|
||||
|
|
12
controllers/c_register.php
Normal file
12
controllers/c_register.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
if (isset($_POST["username"]) AND isset($_POST["nb"]) AND isset($_POST["word"])) {
|
||||
$username = htmlspecialchars($_POST["username"]);
|
||||
$nb = htmlspecialchars($_POST["nb"]);
|
||||
$word = htmlspecialchars($_POST["word"]);
|
||||
require_once(PATH_MODELS.$page.".php");
|
||||
if (!isset($alert) OR !$alert)
|
||||
header("Location: index.php?page=hello&username=$username");
|
||||
} elseif (isset($_POST["username"]) OR isset($_POST["nb"]) OR isset($_POST["word"]))
|
||||
$alert = choixAlert("login");
|
||||
|
||||
require_once(PATH_VIEWS.$page.".php");
|
|
@ -3,6 +3,7 @@
|
|||
define('LOGO', 'Logo de la compagnie'); // Affiché si image non trouvée
|
||||
|
||||
define('MENU_ACCUEIL','Accueil');
|
||||
define("MENU_REGISTER", "Créer un compte");
|
||||
define('TITRE','Helloworld5');
|
||||
|
||||
define('TEXTE_PAGE_404','Oops, la page demandée n\'existe pas !');
|
||||
|
@ -10,3 +11,4 @@ define('MESSAGE_ERREUR',"Une erreur s'est produite");
|
|||
define('ERREUR_CONNECT_BDD','Erreur de connection à la base de données');
|
||||
define('ERREUR_INSCRIPTION', "Login inconnu");
|
||||
define('ERREUR_QUERY_BDD',"Erreur d'accès à la base de données");
|
||||
define("ERREUR_REGISTER", "Utilisateur déjà crée");
|
||||
|
|
|
@ -11,6 +11,9 @@ function choixAlert($message)
|
|||
case 'login' :
|
||||
$alert['messageAlert'] = ERREUR_INSCRIPTION;
|
||||
break;
|
||||
case "register":
|
||||
$alert['messageAlert'] = ERREUR_REGISTER;
|
||||
break;
|
||||
case 'query' :
|
||||
$alert['messageAlert'] = ERREUR_QUERY_BDD;
|
||||
break;
|
||||
|
|
|
@ -11,6 +11,7 @@ if ($bdd instanceof PDO) {
|
|||
|
||||
if (!$user = $req->fetch())
|
||||
$alert = choixAlert("login");
|
||||
$req->closeCursor();
|
||||
} catch (Exception $e) {
|
||||
$alert = choixAlert("query");
|
||||
}
|
||||
|
|
24
models/m_register.php
Normal file
24
models/m_register.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?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 ($req->fetch())
|
||||
$alert = choixAlert("register");
|
||||
else {
|
||||
$req->closeCursor();
|
||||
$req = $bdd->prepare("INSERT INTO Utilisateur (nom, nbRepet, mot) values (?, ?, ?)");
|
||||
$req->execute(array($username, $nb, $word));
|
||||
}
|
||||
$req->closeCursor();
|
||||
} catch (Exception $e) {
|
||||
$alert = choixAlert("query");
|
||||
}
|
||||
} elseif ($bdd instanceof Exception)
|
||||
$alert = choixAlert("connexion");
|
|
@ -22,8 +22,13 @@
|
|||
<?= MENU_ACCUEIL ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php if (!isset($user) or !$user) { ?>
|
||||
<li >
|
||||
<a href="index.php?page=register">
|
||||
<?= MENU_REGISTER ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
|
|
36
views/v_register.php
Normal file
36
views/v_register.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/*
|
||||
* DS PHP
|
||||
* Vue page index - page d'accueil
|
||||
*
|
||||
* Copyright 2016, Eric Dufour
|
||||
* http://techfacile.fr
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/MIT
|
||||
*
|
||||
*/
|
||||
// En tête de page
|
||||
?>
|
||||
<?php require_once(PATH_VIEWS.'header.php');?>
|
||||
|
||||
<!-- Zone message d'alerte -->
|
||||
<?php require_once(PATH_VIEWS.'alert.php');?>
|
||||
|
||||
<!-- Début de la page -->
|
||||
|
||||
<!-- Form -->
|
||||
<form method="POST">
|
||||
<label for="username">Usernamne: </label>
|
||||
<input id="username" name="username" type="text" maxlength="64"> <br />
|
||||
<label for="nb">nb: </label>
|
||||
<input id="nb" name="nb" type="number" min="0" max="100"> <br />
|
||||
<label for="word">mot: </label>
|
||||
<input id="word" name="word" type="text" maxlength="64"> <br />
|
||||
<input type="submit" value="Save">
|
||||
</form>
|
||||
|
||||
<!-- Fin de la page -->
|
||||
|
||||
<!-- Pied de page -->
|
||||
<?php require_once(PATH_VIEWS.'footer.php');
|
Reference in a new issue