diff --git a/Controllers/RecipeController.php b/Controllers/RecipeController.php index 761a965..40be43f 100644 --- a/Controllers/RecipeController.php +++ b/Controllers/RecipeController.php @@ -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); diff --git a/Controllers/UserController.php b/Controllers/UserController.php index b58d616..35fa480 100644 --- a/Controllers/UserController.php +++ b/Controllers/UserController.php @@ -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)); - } } diff --git a/Models/UserModel.php b/Models/UserModel.php index 753f6bb..7c0215b 100644 --- a/Models/UserModel.php +++ b/Models/UserModel.php @@ -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){ diff --git a/Views/account/edit.php b/Views/account/edit.php new file mode 100644 index 0000000..41fb170 --- /dev/null +++ b/Views/account/edit.php @@ -0,0 +1,28 @@ + "Jean_Michel_du_13", + "email" => "jeanmicheldu13@gmail.com" + ); +?> + +
+ Se déconnecter + +
+ + + + + "> + + + "> + + +
+ +
+ + Supprimer le compte ⚠️ + +
diff --git a/Views/common/404.php b/Views/common/404.php deleted file mode 100644 index 0d247fb..0000000 --- a/Views/common/404.php +++ /dev/null @@ -1 +0,0 @@ -

404 page not found

\ No newline at end of file diff --git a/Views/common/footer.php b/Views/common/footer.php index 76e95d6..4116ee6 100644 --- a/Views/common/footer.php +++ b/Views/common/footer.php @@ -1 +1 @@ - \ No newline at end of file + diff --git a/Views/common/header.php b/Views/common/header.php index 9432bf4..3cbed88 100644 --- a/Views/common/header.php +++ b/Views/common/header.php @@ -1,2 +1,22 @@

Titre

'; +$array_header = array( + 'Logo' => "/", + "Recette" => "/Recipe/view/36", + "+" => "/recipe/edit", + "Rechercher" => "rechercher", + '' => "/account/view" +); +?> +
+ + + +
diff --git a/Views/errors/404.php b/Views/errors/404.php new file mode 100644 index 0000000..6498186 --- /dev/null +++ b/Views/errors/404.php @@ -0,0 +1,3 @@ +

Error 404

+

La page n'a pas été trouvée 😥

+Retourner à l'accueil diff --git a/Views/recipe/view.php b/Views/recipe/view.php index 3f49e0e..438c2ef 100644 --- a/Views/recipe/view.php +++ b/Views/recipe/view.php @@ -1,10 +1,32 @@ -

-

Auteur:

-

Difficulté:

-

Ingrédients:

- -foreach($A_view["INGREDIENTS"] as $i){ - echo "

{$i['NAME']}: {$i['QUANTITY']}

"; -} -?> \ No newline at end of file + " alt="Image d'illustration de la recette"> + +
+
+

+
+

+
+ +
+

Ingrédients

+ +
+ +
+

Préparation

+
    + ".$instructions.""; + ?> +
+
+ + diff --git a/Views/user/login.php b/Views/user/login.php index 0dfad56..3afdca6 100644 --- a/Views/user/login.php +++ b/Views/user/login.php @@ -1,5 +1,25 @@ -
- - - -
\ No newline at end of file +
+
+
+ + + + + +
+
+
+
+
+ + + + + + + + + +
+
+
\ No newline at end of file diff --git a/Views/user/register.php b/Views/user/register.php deleted file mode 100644 index 0914ad7..0000000 --- a/Views/user/register.php +++ /dev/null @@ -1,5 +0,0 @@ -
- - - -
\ No newline at end of file diff --git a/static/img/defaultProfil.svg b/static/img/defaultProfil.svg new file mode 100644 index 0000000..738a36e --- /dev/null +++ b/static/img/defaultProfil.svg @@ -0,0 +1 @@ + diff --git a/static/img/logo.png b/static/img/logo.png new file mode 100644 index 0000000..94f1838 Binary files /dev/null and b/static/img/logo.png differ diff --git a/static/img/recettes/36.jpg b/static/img/recettes/36.jpg new file mode 100644 index 0000000..868c807 Binary files /dev/null and b/static/img/recettes/36.jpg differ