Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #36

Merged
merged 3 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,28 +165,6 @@ public function serviceCenterLogout(Request $request, Response $response)
$response->redirect('/service-centre-landing');
}

/* admin sign up method */
public function adminSignUp(Request $request)
{
$admin = new Admin();
if ($request->isPost()) {

$admin->loadData($request->getBody());
if ($admin->validate() && $admin->save()) {
Application::$app->session->setFlash('success', 'You have been registered successfully!');
Application::$app->response->redirect('/admin-login');
}
$this->setLayout('auth');
return $this->render('/admin/admin-sign-up', [
'model' => $admin
]);
}
$this->setLayout('auth');
return $this->render('/admin/admin-sign-up', [
'model' => $admin
]);
}

/* admin login method */
public function adminLogin(Request $request, Response $response)
{
Expand Down
189 changes: 0 additions & 189 deletions controllers/AuthController.php~

This file was deleted.

26 changes: 18 additions & 8 deletions core/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class Request
{

public function getPath()
{
$path = $_SERVER['REQUEST_URI'] ?? '/';
Expand Down Expand Up @@ -34,7 +33,6 @@ public function getBody()
{
// Empty associative array
$body = [];
// Checks if the request method is GET
if ($this->method() === 'get') {
// $_GET: A PHP superglobal that holds query parameters from the URL (e.g., ?key=value).
// Iterates through each key-value pair in the $_GET array
Expand All @@ -43,13 +41,25 @@ public function getBody()
$body[$key] = filter_input(INPUT_GET, $key, FILTER_SANITIZE_SPECIAL_CHARS);
}
}
// Checks if the request method is POST

if ($this->method() === 'post') {
// $_POST: A PHP superglobal that holds form data submitted via HTTP POST.
// Iterates through each key-value pair in the $_POST array
foreach ($_POST as $key => $value) {
// Sanitizes the values and adds to the $body array
$body[$key] = filter_input(INPUT_POST, $key, FILTER_SANITIZE_SPECIAL_CHARS);
// Check Content-Type header to determine how to process the body
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';

if (strpos($contentType, 'application/json') !== false) {
// Handle JSON input
$rawInput = file_get_contents('php://input');
$decodedInput = json_decode($rawInput, true);
if (json_last_error() === JSON_ERROR_NONE && is_array($decodedInput)) {
$body = $decodedInput;
}
} else {
// $_POST: A PHP superglobal that holds form data submitted via HTTP POST.
// Iterates through each key-value pair in the $_POST array
// Handle form-encoded input
foreach ($_POST as $key => $value) {
$body[$key] = filter_input(INPUT_POST, $key, FILTER_SANITIZE_SPECIAL_CHARS);
}
}
}
// Returns the sanitized data
Expand Down
20 changes: 19 additions & 1 deletion models/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class Admin extends DbModel
{

public string $fname = '';
public string $lname = '';
public string $email = '';
Expand Down Expand Up @@ -81,4 +80,23 @@ public function attributes(): array
'password',
];
}

public static function findAllCustomers()
{
$sql = "SELECT cus_id, fname, lname, email, phone_no, address, reg_date FROM customer";
$statement = (new Admin)->prepare($sql);
$statement->execute();
return $statement->fetchAll(\PDO::FETCH_ASSOC);
}

public static function deleteCustomerById($cus_id)
{
$db = Application::$app->db; // Ensure this points to the correct Database instance
$sql = "DELETE FROM customer WHERE cus_id = :cus_id";
$stmt = $db->prepare($sql);
$stmt->bindParam(':cus_id', $cus_id, \PDO::PARAM_INT);
return $stmt->execute();

}

}
Binary file added public/assets/uploads/HomeImage2.webp
Binary file not shown.
Binary file added public/assets/uploads/OIP.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading