loginError) {
- require_once('Views/template/loginError.phtml');
- }
if(!$view->user->isLoggedIn()) {
require_once('Views/template/loginModal.phtml');
}
diff --git a/Views/template/loginError.phtml b/Views/template/loginError.phtml
index e69de29..ac49647 100644
--- a/Views/template/loginError.phtml
+++ b/Views/template/loginError.phtml
@@ -0,0 +1,18 @@
+
\ No newline at end of file
diff --git a/Views/template/loginModal.phtml b/Views/template/loginModal.phtml
index 5225248..2e1c950 100644
--- a/Views/template/loginModal.phtml
+++ b/Views/template/loginModal.phtml
@@ -1,7 +1,11 @@
-
+
Login
-
+= isset($view->loginError) ? '
' : '' ?>
+
diff --git a/index.php b/index.php
index ae4ed47..66039fd 100644
--- a/index.php
+++ b/index.php
@@ -1,10 +1,10 @@
pageTitle = 'Home';
+require_once("logincontroller.php");
//if (isset($_POST['applyAdvFilters'])) {
diff --git a/logincontroller.php b/logincontroller.php
index 717d213..ea6c2ad 100644
--- a/logincontroller.php
+++ b/logincontroller.php
@@ -4,21 +4,39 @@ require_once("Models/User.php");
$user = new User();
$userDataSet = new UserDataSet();
-
if (isset($_POST["loginButton"])) {
$username = $_POST["username"];
$password = hash("sha256", $_POST["password"]);
+ if (isset($view->loginError)) {
+ $generatedCaptcha = $_POST["generatedCaptcha"];
+ $userCaptcha = $_POST["captcha"];
+ if ($generatedCaptcha !== $userCaptcha) {
+ $view->loginError = "Incorrect CAPTCHA.";
+ return;
+ }
+ }
// create a new student dataset object that we can generate data from
+ // Error handling is VERY hacky, because of the lack of JS usage.
if($userDataSet->checkUserCredentials($username, $password)) {
$user->Authenticate($username, $password);
- }
- else {
- echo "Error in Uname / Pass";
- }
+ // Unset modal boolean to hide it's usage.
+ unset($_GET['modal']);
+ } else {
+ // Add error message and redirect to display modal
+ $view->loginError = "Invalid username or password.";
+ // Set modal boolean to header to allow modal to reappear
+ $queryParams = http_build_query(['modal' => 'true']);
+ header("Location: {$_SERVER['PHP_SELF']}?$queryParams");
+ exit;
+}
}
if (isset($_POST["logoutButton"]))
{
$user->logout();
}
+
+if (isset($_GET['modal']) && $_GET['modal'] === 'true') {
+ $view->loginError = $view->loginError ?? "Please solve the Captcha and try again.";
+}
\ No newline at end of file