diff --git a/app/core/ErrorHandler.php b/app/core/ErrorHandler.php index 86f9618..ed1fe11 100644 --- a/app/core/ErrorHandler.php +++ b/app/core/ErrorHandler.php @@ -1,6 +1,7 @@ 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); } } \ No newline at end of file diff --git a/app/view/pages/teamtable/edit/index.php b/app/view/pages/teamtable/edit/index.php index 45ceee1..9a0f789 100644 --- a/app/view/pages/teamtable/edit/index.php +++ b/app/view/pages/teamtable/edit/index.php @@ -36,5 +36,4 @@ echo ''; } ?> - -Opprett lag ] \ No newline at end of file + \ No newline at end of file