generifying users
This commit is contained in:
parent
6064009729
commit
6f1138388b
|
|
@ -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
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue