Commit
This commit is contained in:
parent
46c83e377f
commit
5c891551df
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
// Janky error handler page thingy that looks cool
|
||||
// Bit of a janky way to display a custom page on error or exception.
|
||||
// But looks pretty cool and professional!
|
||||
class ErrorHandler
|
||||
{
|
||||
public array $errors; // Holds error messages (even though for now we only display a maximum of 1)
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
// TODO: ...
|
||||
class User
|
||||
{
|
||||
private const SESSION_KEY = 'UserClass';
|
||||
private Session $session;
|
||||
private Database $database;
|
||||
|
||||
@ -19,7 +19,7 @@ class User
|
||||
$this->session = $session;
|
||||
$this->database = $database;
|
||||
|
||||
$user = $this->session->get('user');
|
||||
$user = $this->session->get(self::SESSION_KEY);
|
||||
|
||||
// Check if user session has been set
|
||||
if (!$user)
|
||||
@ -38,17 +38,25 @@ class User
|
||||
}
|
||||
|
||||
// All is good, we should be logged in now! (hopefully)
|
||||
$this->loggedIn = TRUE;
|
||||
$this->username = $user['username'];
|
||||
$this->password = $user['password'];
|
||||
$this->loggedIn = TRUE;
|
||||
$this->username = $user['username'];
|
||||
$this->password = $user['password'];
|
||||
$this->powerLevel = $this->getPowerLevel();
|
||||
}
|
||||
|
||||
// Set powerLevel
|
||||
// Get current user power level
|
||||
private function getPowerLevel(): int
|
||||
{
|
||||
if (!$this->loggedIn)
|
||||
{
|
||||
throw new Exception("Can't get power level without being logged in!");
|
||||
}
|
||||
$sth = $this->database->conn->prepare(
|
||||
'SELECT * FROM brukertabell WHERE Navn = ? AND Passord = ?'
|
||||
'SELECT Nivå FROM brukertabell WHERE Navn = ? AND Passord = ?'
|
||||
);
|
||||
$sth->execute([$this->username, $this->password]);
|
||||
$row = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
$this->powerLevel = $row['Nivå'];
|
||||
return $row['Nivå'];
|
||||
}
|
||||
|
||||
// Set session if user and password match
|
||||
@ -56,7 +64,7 @@ class User
|
||||
{
|
||||
if ($this->authenticate($username, $password))
|
||||
{
|
||||
$this->session->set('user', [
|
||||
$this->session->set(self::SESSION_KEY, [
|
||||
'loggedIn' => TRUE,
|
||||
'username' => $username,
|
||||
'password' => $password
|
||||
@ -82,6 +90,6 @@ class User
|
||||
|
||||
public function logout(): void
|
||||
{
|
||||
$this->session->remove('user');
|
||||
$this->session->remove(self::SESSION_KEY);
|
||||
}
|
||||
}
|
@ -37,4 +37,3 @@
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<span class="float-right">[ <a class="success" href="add.php">Opprett lag</a> ]</span>
|
Reference in New Issue
Block a user