diff --git a/jobs/controllers/Admin.php b/jobs/controllers/Admin.php index 8672f6d..b070941 100644 --- a/jobs/controllers/Admin.php +++ b/jobs/controllers/Admin.php @@ -23,31 +23,6 @@ class Admin { } 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'; - } - - return ['template' => 'admin.html.php', - 'title' => 'Jo\'s Jobs- Login', - 'vars' => $this->vars - ]; + } } \ No newline at end of file diff --git a/jobs/controllers/User.php b/jobs/controllers/User.php index 682eb84..ffd0eb4 100644 --- a/jobs/controllers/User.php +++ b/jobs/controllers/User.php @@ -17,4 +17,47 @@ class User { 'title' => 'Jo\'s Jobs- Login', 'vars' => $this->vars]; } + + public function loginSubmit() { + if ($_POST['username'] == '' && $_POST['password'] = '') { + $user = $this->usersTable->find("username", $_POST['username']); + if (password_verify($_POST['password'], $user->password)) { + $_SESSION['loggedin'] = $user->id; + if ($user->admin == 'y') { + $_SESSION['admin'] = true; + } + $this->vars['response'] = 'You are now logged in'; + } + else { + unset($_SESSION['loggedin']); + unset($_SESSION['admin']); + $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'; + } + + return ['template' => 'admin.html.php', + 'title' => 'Jo\'s Jobs- Login', + 'vars' => $this->vars + ]; + } + + public function logout() { + unset($_SESSION['loggedin']); + unset($_SESSION['admin']); + $this->vars['response'] = 'Logged Out Successfully'; + + return ['template' => 'response.html.php', + 'title' => 'Jo\'s Jobs- Logged Out', + 'vars' => $this->vars]; + } } \ No newline at end of file