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"
+ );
+?>
+
+
+
+ Supprimer le compte ⚠️
+
+
' => "/",
+ "Recette" => "/Recipe/view/36",
+ "+" => "/recipe/edit",
+ "Rechercher" => "rechercher",
+ '' => "/account/view"
+);
+?>
+= $A_view["NAME"] ?>
-Auteur: = $A_view["AUTHOR_NAME"] ?>
-Difficulté: = $A_view["DIFFICULTY_NAME"] ?>
-Ingrédients:
- -foreach($A_view["INGREDIENTS"] as $i){ - echo "{$i['NAME']}: {$i['QUANTITY']}
"; -} -?> \ No newline at end of file += $A_view["DESC"] ?>
+