Summary Files Commits Branches @commit @diff @stats
path: root / src / controllers
diff options
context:
space:
mode:
Commitfb2645d444729d656a209ef586a13fb569429280 (patch)
Author
 Kamen Mladenov <kamen.d.mladenov@protonmail.com>
2021-04-03 18:27:33 +0300
Committer
 GitHub <noreply@github.com>
2021-04-03 18:27:33 +0300
Files91daafcdb8af6cd41551bbf442f4be77dee575a4 /src/controllers
devrix-job-board-1.0.tar
devrix-job-board-1.0.tar.gz
devrix-job-board-1.0.zip
Parent67bc860ea4b3db5033a42038ab86d0df955c9295 (diff)
Parent3b0cbc90e3046a8bb979c2b9a17fae5a94bb2707 (diff)
Merge pull request #3 from Syndamia/dev v1.0
Exam version finished
diff --git a/src/controllers/BaseController.php b/src/controllers/BaseController.php
index 2c2a647..412cf25 100644
--- a/src/controllers/BaseController.php
+++ b/src/controllers/BaseController.php
@@ -1,14 +1,18 @@
<?php
class BaseController {
+ /**
+ * Calls the get, post, put or delete static methods, depending on the server request method ($_SERVER['REQUEST_METHOD'])
+ * **By default** all requests that are not POST, PUT or DELETE execute the GET request method
+ */
public static function invoke() {
- switch ($_SERVER["REQUEST_METHOD"]) {
- case "POST":
+ switch ($_SERVER['REQUEST_METHOD']) {
+ case 'POST':
static::post();
break;
- case "PUT":
+ case 'PUT':
static::put();
break;
- case "DELETE":
+ case 'DELETE':
static::delete();
break;
default:
@@ -18,19 +22,18 @@ class BaseController {
}
protected static function get() {
- echo "GET method not implemented!";
+ echo 'GET method not implemented!';
}
protected static function post() {
-
- echo "POST method not implemented!";
+ echo 'POST method not implemented!';
}
protected static function put() {
- echo "PUT method not implemented!";
+ echo 'PUT method not implemented!';
}
protected static function delete() {
- echo "DELETE method not implemented!";
+ echo 'DELETE method not implemented!';
}
}
diff --git a/src/controllers/CreateOfferController.php b/src/controllers/CreateOfferController.php
index a223463..bb6015b 100644
--- a/src/controllers/CreateOfferController.php
+++ b/src/controllers/CreateOfferController.php
@@ -7,7 +7,7 @@ class CreateOfferController extends BaseController {
public static function get() {
self::$companies = Company::getAllFromDB();
- include 'views/create-offer.php';
+ include('views/create-offer.php');
}
public static function post() {
@@ -15,7 +15,7 @@ class CreateOfferController extends BaseController {
JobOffer::insertIntoDB($newJobOffer);
// Redirect to landing page
- header("Location: /", TRUE, 301);
+ header('Location: /', TRUE, 301);
exit();
}
}
diff --git a/src/controllers/DashboardController.php b/src/controllers/DashboardController.php
index 548f60b..59c1090 100644
--- a/src/controllers/DashboardController.php
+++ b/src/controllers/DashboardController.php
@@ -12,18 +12,21 @@ class DashboardController extends BaseController {
foreach(Company::getAllFromDB() as $company) {
self::$companies[$company->id] = $company->name;
}
- include "views/dashboard.php";
+ include('views/dashboard.php');
}
public static function post() {
+ // Forms can only send POST or GET requests.
+ // EditOfferController doesn't have it's own URI, so we can't send a request.
+ // We also can't just invoke it, because that means manually changing the server's request method.
switch($_POST['_method']) {
- case "get":
+ case 'get':
EditOfferController::get();
break;
- case "put":
+ case 'put':
EditOfferController::put();
break;
- case "delete":
+ case 'delete':
EditOfferController::delete();
break;
}
diff --git a/src/controllers/DashboardLoginController.php b/src/controllers/DashboardLoginController.php
index fe2009b..c6ac070 100644
--- a/src/controllers/DashboardLoginController.php
+++ b/src/controllers/DashboardLoginController.php
@@ -6,20 +6,23 @@ class DashboardLoginController extends BaseController {
private static $message;
public static function get() {
- include "views/dashboard-login.php";
+ include('views/dashboard-login.php');
}
public static function post() {
+ // The dashboard(controller) doesn't have it's own URI (and all requests are sent in this controller), so
+ // we can't send a request directly to dashboard.
+ // This does compromise security, but for now it will have to do.
if (isset($_POST['_method'])) {
DashboardController::invoke();
}
- else if ($_POST['username'] == "admin" && $_POST['password'] == "admin") {
+ else if ($_POST['username'] == 'admin' && $_POST['password'] == 'admin') {
// Load normal dashboard
DashboardController::get();
}
else {
- self::$message = "Bad credentials!";
- include "views/dashboard-login.php";
+ self::$message = 'Bad credentials!';
+ include('views/dashboard-login.php');
}
}
}
diff --git a/src/controllers/EditOfferController.php b/src/controllers/EditOfferController.php
index ae49c5b..dc9a753 100644
--- a/src/controllers/EditOfferController.php
+++ b/src/controllers/EditOfferController.php
@@ -11,7 +11,7 @@ class EditOfferController extends BaseController {
public static function get() {
self::$job = JobOffer::getFromDBById($_POST['jobId']);
self::$companies = Company::getAllFromDB();
- include "views/edit-offer.php";
+ include('views/edit-offer.php');
}
public static function put() {
diff --git a/src/controllers/LandingController.php b/src/controllers/LandingController.php
index ffa8644..9e81751 100644
--- a/src/controllers/LandingController.php
+++ b/src/controllers/LandingController.php
@@ -1,7 +1,7 @@
<?php
-include_once("models/JobOffer.php");
+include_once('models/JobOffer.php');
include_once('models/Company.php');
-include_once("controllers/BaseController.php");
+include_once('controllers/BaseController.php');
class LandingController extends BaseController {
private static $companies = array();
@@ -11,6 +11,6 @@ class LandingController extends BaseController {
foreach(Company::getAllFromDB() as $company) {
self::$companies[$company->id] = $company->name;
}
- include "views/landing.php";
+ include('views/landing.php');
}
}