diff --git a/Controller/UserController.php b/Controller/UserController.php index 0ff5a1e..9f263ba 100644 --- a/Controller/UserController.php +++ b/Controller/UserController.php @@ -20,7 +20,7 @@ class UserController public function loginUser() { $erg = array(); - $erg = $this->userModel->verifyLogin($_POST["username"], $_POST["password"]); + $erg = $this->userModel->loginUser($_POST["username"], $_POST["password"]); if ($erg["success"] == true) { header("Location: ?controller=Welcome&do=showWelcome"); exit(); @@ -28,9 +28,9 @@ class UserController } else { $this->view->setDoMethodName("showUserLoginForm"); - $this->view->setVars([ - "errmsg" => $erg["message"] - ]); + ## $this->view->setVars([ + ## "errmsg" => $erg["message"] + ## ]); $this->showUserLoginForm(); } @@ -43,12 +43,36 @@ class UserController exit(); } + public function registerUser() + { + $erg = array(); + $erg = $this->userModel->registerUser($_POST["username"], $_POST["password"]); + if ($erg["success"] == true) { + header("Location: ?controller=Welcome&do=showWelcome"); + exit(); + } + else { + $this->view->setDoMethodName("showUserRegisterForm"); + + ## $message = $erg['message']; + ## echo ""; + ## $this->view->setVars([ + ## "errmsg" => $erg["message"] + ## ]); + $this->showUserRegisterForm(); + } + } public function showUserLoginForm() { } + public function showUserRegisterForm() + { + + } + } \ No newline at end of file diff --git a/Model/UserModel.php b/Model/UserModel.php index 23975b8..dfac769 100644 --- a/Model/UserModel.php +++ b/Model/UserModel.php @@ -7,7 +7,7 @@ use PDOException; class UserModel extends Database { - public function verifyLogin($username, $password) + public function loginUser($username, $password) { $pdo = $this->linkDB(); if (!$pdo) return ['success' => false, 'message' => 'Database connection error.']; @@ -31,8 +31,42 @@ class UserModel extends Database function logoutUser() { - session_unset(); // Unset all session variables + session_unset(); session_destroy(); return ['success' => true, 'message' => 'Logged out successfully.']; } + + + function registerUser($username, $password) { + $pdo = $this->linkDB(); + if (!$pdo) return ['success' => false, 'message' => 'Database connection error.']; + $errors = []; + if (empty($username)) $errors[] = "Username is required."; + if (empty($password)) $errors[] = "Password is required."; + if (strlen($password) < 8) $errors[] = "Password must be at least 8 characters."; + if (!preg_match('/[A-Z]/', $password)) $errors[] = "Password needs an uppercase letter."; + if (!preg_match('/[a-z]/', $password)) $errors[] = "Password needs a lowercase letter."; + if (!preg_match('/[0-9]/', $password)) $errors[] = "Password needs a number."; + if (!preg_match('/[^A-Za-z0-9]/', $password)) $errors[] = "Password needs a special character."; + + if (!empty($errors)) { + return ['success' => false, 'message' => "
Don't have an account? Register here
+Don't have an account? Register here
diff --git a/Views/User/showUserRegisterForm.phtml b/Views/User/showUserRegisterForm.phtml new file mode 100644 index 0000000..2d658a5 --- /dev/null +++ b/Views/User/showUserRegisterForm.phtml @@ -0,0 +1,28 @@ + +