Merge pull request #7 from ThomasRubini/views
This commit is contained in:
commit
65d96820a2
@ -6,13 +6,13 @@ final class RecipeController
|
||||
public function viewAction(Array $A_urlParams = null, Array $A_postParams = null)
|
||||
{
|
||||
if(count($A_urlParams)!=1){
|
||||
return View::show("common/404");
|
||||
return View::show("errors/404");
|
||||
}
|
||||
|
||||
$O_recipeModel = new RecipeModel();
|
||||
$A_returnArray = $O_recipeModel->getFullRecipeWithComments($A_urlParams[0]);
|
||||
if ($A_returnArray === null) {
|
||||
return View::show("common/404");
|
||||
return View::show("errors/404");
|
||||
}
|
||||
|
||||
View::show("recipe/view", $A_returnArray);
|
||||
|
||||
@ -8,11 +8,6 @@ final class UserController
|
||||
View::show("user/login");
|
||||
}
|
||||
|
||||
public function registerAction(Array $A_urlParams = null, Array $A_postParams = null)
|
||||
{
|
||||
View::show("user/register");
|
||||
}
|
||||
|
||||
private function get_or_die($DICT, $key)
|
||||
{
|
||||
if (isset($DICT[$key])) return $DICT[$key];
|
||||
@ -21,11 +16,11 @@ final class UserController
|
||||
|
||||
public function signInAction(Array $A_urlParams = null, Array $A_postParams = null)
|
||||
{
|
||||
$S_username = self::get_or_die($A_postParams, "username");
|
||||
$S_email = self::get_or_die($A_postParams, "email");
|
||||
$S_password = self::get_or_die($A_postParams, "password");
|
||||
|
||||
$O_userModel = new UserModel();
|
||||
if ($O_userModel->isPasswordValid($S_username, $S_password)) {
|
||||
if ($O_userModel->isPasswordValid($S_email, $S_password)) {
|
||||
View::show("user/signin", array("success" => True));
|
||||
} else {
|
||||
View::show("user/signin", array("success" => False));
|
||||
@ -34,21 +29,20 @@ final class UserController
|
||||
|
||||
public function signUpAction(Array $A_urlParams = null, Array $A_postParams = null)
|
||||
{
|
||||
$S_email = self::get_or_die($A_postParams, "email");
|
||||
$S_username = self::get_or_die($A_postParams, "username");
|
||||
$S_password = self::get_or_die($A_postParams, "password");
|
||||
|
||||
if ( strlen($S_username) < 4 || strlen($S_username) > 16 ) {
|
||||
$S_errmsg = "username must be between 4 and 16 characters";
|
||||
} else if(!ctype_alnum($S_username)) {
|
||||
$S_errmsg = "username must be alphanumeric";
|
||||
} else if( strlen($S_password) < 8 || strlen($S_username) > 150 ) {
|
||||
if (!filter_var($S_email, FILTER_VALIDATE_EMAIL)) {
|
||||
$S_errmsg = "invalid email";
|
||||
} else if( strlen($S_password) < 8 || strlen($S_password) > 150 ) {
|
||||
$S_errmsg = "password must be between 8 and 150 characters";
|
||||
}
|
||||
|
||||
$O_userModel = new UserModel();
|
||||
|
||||
if($O_userModel->isUserInDatabase($S_username)){
|
||||
$S_errmsg = "An user with this name is already registered";
|
||||
if($O_userModel->isEmailInDatabase($S_email)){
|
||||
$S_errmsg = "An user with this email is already registered";
|
||||
}
|
||||
|
||||
if(isset($S_errmsg)){
|
||||
@ -57,9 +51,8 @@ final class UserController
|
||||
|
||||
$S_password_hash = password_hash($S_password, PASSWORD_DEFAULT);
|
||||
|
||||
$O_userModel->createUser($S_username, $S_password_hash);
|
||||
$O_userModel->createUser($S_email, $S_username, $S_password_hash);
|
||||
return View::show("user/signup", array("success" => True));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,29 +3,31 @@
|
||||
final class UserModel
|
||||
{
|
||||
|
||||
public function createUser($S_name, $S_password_hash){
|
||||
public function createUser($S_email, $S_username, $S_password_hash){
|
||||
$O_model = Model::get();
|
||||
$stmt = $O_model->prepare("INSERT INTO USER (NAME, PASS_HASH) VALUES(:name, :password_hash)");
|
||||
$stmt = $O_model->prepare("INSERT INTO USER (EMAIL, NAME, PASS_HASH) VALUES(:email, :name, :password_hash)");
|
||||
$stmt->bindParam("email", $S_email);
|
||||
$stmt->bindParam("name", $S_name);
|
||||
$stmt->bindParam("password_hash", $S_password_hash);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
public function isUserInDatabase($S_name){
|
||||
public function isEmailInDatabase($S_email){
|
||||
|
||||
$O_model = Model::get();
|
||||
$stmt = $O_model->prepare("SELECT count(*) FROM USER WHERE NAME=:name");
|
||||
$stmt->bindParam("name", $S_name);
|
||||
$stmt = $O_model->prepare("SELECT count(*) FROM USER WHERE EMAIL=:email");
|
||||
$stmt->bindParam("email", $S_email);
|
||||
$stmt->execute();
|
||||
|
||||
return $stmt->fetch()[0] !== 0;
|
||||
$count = $stmt->fetch()[0];
|
||||
return $count != 0;
|
||||
}
|
||||
|
||||
|
||||
public function isPasswordValid($S_name, $S_password){
|
||||
public function isPasswordValid($S_email, $S_password){
|
||||
$O_model = Model::get();
|
||||
$stmt = $O_model->prepare("SELECT PASS_HASH FROM USER WHERE NAME=:name");
|
||||
$stmt->bindParam("name", $S_name);
|
||||
$stmt = $O_model->prepare("SELECT PASS_HASH FROM USER WHERE EMAIL=:email");
|
||||
$stmt->bindParam("email", $S_email);
|
||||
$stmt->execute();
|
||||
|
||||
if($stmt->rowCount()==1){
|
||||
|
||||
28
Views/account/edit.php
Normal file
28
Views/account/edit.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
$array_account = array(
|
||||
"username" => "Jean_Michel_du_13",
|
||||
"email" => "jeanmicheldu13@gmail.com"
|
||||
);
|
||||
?>
|
||||
|
||||
<main>
|
||||
<a href="/disconnect">Se déconnecter</a>
|
||||
|
||||
<form action="/account/disconnect" method="post">
|
||||
<label for="profilPicture">Changer l'image de profil </label>
|
||||
<input type="file" name="profilPicture" id="profilPicture" accept="image/*">
|
||||
|
||||
<label for="username">Changer le nom d'utilisateur </label>
|
||||
<input type="text" name="username" id="username" placeholder="<?= $array_account["username"] ?>">
|
||||
|
||||
<label for="email">Changer d'e-mail </label>
|
||||
<input type="email" name="email" id="email" placeholder="<?= $array_account["email"] ?>">
|
||||
|
||||
<button type="button">Enregistrer</button>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
|
||||
<a href="/account/delete">Supprimer le compte ⚠️</a>
|
||||
|
||||
</main>
|
||||
@ -1 +0,0 @@
|
||||
<h1>404 page not found</h1>
|
||||
@ -1 +1 @@
|
||||
<footer>Pied</footer>
|
||||
<footer>❤️ Fait avec amour par Capelier, Lafitte, Laurent, Rubini, Simaila & Vachet ❤️</footer>
|
||||
|
||||
@ -1,2 +1,22 @@
|
||||
<?php
|
||||
echo '<header> <h1>Titre</h1></header>';
|
||||
$array_header = array(
|
||||
'<img src="/static/img/logo.png" alt="Logo">' => "/",
|
||||
"Recette" => "/Recipe/view/36",
|
||||
"+" => "/recipe/edit",
|
||||
"Rechercher" => "rechercher",
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" width="50px" height="50px"><path d="M 30.933594 32.527344 C 30.785156 30.914063 30.84375 29.789063 30.84375 28.316406 C 31.574219 27.933594 32.882813 25.492188 33.101563 23.429688 C 33.675781 23.382813 34.582031 22.824219 34.847656 20.613281 C 34.988281 19.425781 34.421875 18.757813 34.074219 18.546875 C 35.007813 15.738281 36.949219 7.046875 30.488281 6.148438 C 29.820313 4.980469 28.117188 4.390625 25.90625 4.390625 C 17.050781 4.554688 15.984375 11.078125 17.925781 18.546875 C 17.578125 18.757813 17.011719 19.425781 17.152344 20.613281 C 17.421875 22.824219 18.324219 23.382813 18.898438 23.429688 C 19.117188 25.492188 20.476563 27.933594 21.210938 28.316406 C 21.210938 29.789063 21.265625 30.914063 21.117188 32.527344 C 19.367188 37.238281 7.546875 35.914063 7 45 L 45 45 C 44.453125 35.914063 32.683594 37.238281 30.933594 32.527344 Z"/></svg>' => "/account/view"
|
||||
);
|
||||
?>
|
||||
<header>
|
||||
|
||||
<nav>
|
||||
<ul>
|
||||
<?php
|
||||
foreach ($array_header as $key => $value) {
|
||||
echo '<li><a href="'.$value.'">'.$key.'</a></li>';
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</header>
|
||||
|
||||
3
Views/errors/404.php
Normal file
3
Views/errors/404.php
Normal file
@ -0,0 +1,3 @@
|
||||
<h1>Error 404</h1>
|
||||
<h2>La page n'a pas été trouvée 😥</h2>
|
||||
<a href="/">Retourner à l'accueil<a>
|
||||
@ -1,10 +1,32 @@
|
||||
<p> <?= $A_view["NAME"] ?> </p>
|
||||
<p> Auteur: <?= $A_view["AUTHOR_NAME"] ?> </p>
|
||||
<p> Difficulté: <?= $A_view["DIFFICULTY_NAME"] ?> </p>
|
||||
<p> Ingrédients: </p>
|
||||
<?php
|
||||
<main>
|
||||
|
||||
foreach($A_view["INGREDIENTS"] as $i){
|
||||
echo "<p> {$i['NAME']}: {$i['QUANTITY']} </p>";
|
||||
}
|
||||
?>
|
||||
<img src="<?= $A_view["imageRecette"] ?>" alt="Image d'illustration de la recette">
|
||||
|
||||
<section class="infosRecette">
|
||||
<header>
|
||||
<h1><?= $A_view["NAME"] ?></h1>
|
||||
</header>
|
||||
<p><?= $A_view["DESC"] ?></p>
|
||||
</section>
|
||||
|
||||
<section class="ingredientsRecette">
|
||||
<h2>Ingrédients</h2>
|
||||
<ul>
|
||||
<?php
|
||||
foreach($A_view["INGREDIENTS"] as $ingredient)
|
||||
echo "<li> ${ingredient["NAME"]}: ${ingredient["QUANTITY"]} </li>";
|
||||
?>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Préparation</h2>
|
||||
<ol>
|
||||
<?php
|
||||
foreach(explode("\n", $A_view["RECIPE"]) as $instructions)
|
||||
echo "<li>".$instructions."</li>";
|
||||
?>
|
||||
</ol>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
|
||||
@ -1,5 +1,25 @@
|
||||
<form action="/user/signin" method="POST">
|
||||
<input type="text" name="username" placeholder="username">
|
||||
<input type="password" name="password" placeholder="password">
|
||||
<input type="submit" value="Se connecter">
|
||||
</form>
|
||||
<main>
|
||||
<section>
|
||||
<form method="POST" action="/user/signin">
|
||||
<label for="email">Entrez votre email</label>
|
||||
<input type="email" name="email" id="email" placeholder="Email" required>
|
||||
<label for="password">Entrez votre mot de passe</label>
|
||||
<input type="password" name="password" id="password" placeholder="Mot de passe" required>
|
||||
<input type="submit" value="Envoyer">
|
||||
</form>
|
||||
</section>
|
||||
<hr>
|
||||
<section>
|
||||
<form method="POST" action="/user/signup" id="signin">
|
||||
<label for="email">Entrez votre email</label>
|
||||
<input type="email" name="email" id="email" placeholder="Email" required>
|
||||
<label for="text">Entrez votre nom d'utilisateur</label>
|
||||
<input type="text" name="username" id="username" placeholder="Nom d'utilisateur" required>
|
||||
<label for="password">Entrez votre mot de passe</label>
|
||||
<input type="password" name="password" id="password" placeholder="Mot de passe" required>
|
||||
<label for="password_confirm">Confirmez le mot de passe</label>
|
||||
<input type="password" name="password_confirm" id="password_confirm" placeholder="Confirmer le mot de passe" required>
|
||||
<input type="submit" value="Envoyer">
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
@ -1,5 +0,0 @@
|
||||
<form action="/user/signup" method="POST">
|
||||
<input type="text" name="username" placeholder="username">
|
||||
<input type="password" name="password" placeholder="password">
|
||||
<input type="submit" value="Créer un compte">
|
||||
</form>
|
||||
1
static/img/defaultProfil.svg
Normal file
1
static/img/defaultProfil.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" width="50px" height="50px"><path d="M 30.933594 32.527344 C 30.785156 30.914063 30.84375 29.789063 30.84375 28.316406 C 31.574219 27.933594 32.882813 25.492188 33.101563 23.429688 C 33.675781 23.382813 34.582031 22.824219 34.847656 20.613281 C 34.988281 19.425781 34.421875 18.757813 34.074219 18.546875 C 35.007813 15.738281 36.949219 7.046875 30.488281 6.148438 C 29.820313 4.980469 28.117188 4.390625 25.90625 4.390625 C 17.050781 4.554688 15.984375 11.078125 17.925781 18.546875 C 17.578125 18.757813 17.011719 19.425781 17.152344 20.613281 C 17.421875 22.824219 18.324219 23.382813 18.898438 23.429688 C 19.117188 25.492188 20.476563 27.933594 21.210938 28.316406 C 21.210938 29.789063 21.265625 30.914063 21.117188 32.527344 C 19.367188 37.238281 7.546875 35.914063 7 45 L 45 45 C 44.453125 35.914063 32.683594 37.238281 30.933594 32.527344 Z"/></svg>
|
||||
|
After Width: | Height: | Size: 919 B |
BIN
static/img/logo.png
Normal file
BIN
static/img/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 279 KiB |
BIN
static/img/recettes/36.jpg
Normal file
BIN
static/img/recettes/36.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 298 KiB |
Loading…
Reference in New Issue
Block a user