CSY2028-assignment-2/jobs/controllers/Admin.php

53 lines
1.8 KiB
PHP
Raw Normal View History

2023-01-23 18:34:00 +00:00
<?php
namespace jobs\controllers;
class Admin {
private $jobsTable;
private $catsTable;
private $appsTable;
private $usersTable;
private $vars = [];
public function __construct(\CSY2028\DatabaseTable $jobsTable, \CSY2028\DatabaseTable $catsTable, \CSY2028\DatabaseTable $appsTable, \CSY2028\DatabaseTable $usersTable) {
$this->jobsTable = $jobsTable;
$this->catsTable = $catsTable;
$this->appsTable = $appsTable;
$this->usersTable = $usersTable;
$this->vars['cats'] = $this->catsTable->findAll();
2023-01-23 18:45:00 +00:00
$this->vars['response'] = '';
2023-01-23 18:34:00 +00:00
}
public function home() {
2023-01-25 13:22:20 +00:00
return ['template' => 'login.html.php',
2023-01-23 18:34:00 +00:00
'title' => 'Jo\'s Jobs- Login',
'vars' => $this->vars];
}
public function homeSubmit() {
if ($_POST['username'] == '' && $_POST['password'] = '') {
$user = $this->usersTable->find("username", $_POST['username']);
if (password_verify($_POST['password'], $user->password)) {
$_SESSION['loggedin'] = true;
$this->vars['response'] = 'You are now logged in';
}
else {
unset($_SESSION['loggedin']);
$this->vars['response'] = 'Login Unsuccessful';
}
}
else {
if ($_POST['username'] == '') {
$this->vars['response'] .= "No Username was entered \n";
}
if ($_POST['password'] == '') {
$this->vars['response'] .= "No Username was entered \n";
}
$this->vars['response'] .= 'Login Unsuccessful';
}
2023-01-23 18:45:00 +00:00
return ['template' => 'admin.html.php',
2023-01-23 18:34:00 +00:00
'title' => 'Jo\'s Jobs- Login',
'vars' => $this->vars
];
}
}