This commit is contained in:
William 2022-02-02 12:47:06 +01:00
parent 542e9bf5f2
commit 0773afdae5
2 changed files with 17 additions and 3 deletions

View File

@ -4,14 +4,17 @@
class User
{
private Session $session;
private Database $database;
public ?bool $loggedIn;
public ?string $username;
public ?string $password;
public ?int $level;
public function __construct(Session $session)
public function __construct(Session $session, Database $database)
{
$this->session = $session;
$this->database = $database;
$this->setProps();
}
@ -26,6 +29,14 @@ class User
$this->logout();
$this->session->flash('Kontodetaljer endret, vennligst logg inn igjen', 'warning');
}
if ($this->loggedIn) {
$sth = $this->database->conn->prepare('SELECT * FROM brukertabell WHERE Navn = ? AND Passord = ?');
$sth->execute([$this->username, $this->password]);
$row = $sth->fetch(PDO::FETCH_ASSOC);
$this->level = $row['Nivå'];
}
}
// Set session if user and password match
@ -45,7 +56,10 @@ class User
// Check if user and pass match
private function authenticate(string $username, string $password): bool
{
if ($username === 'William' && $password === 'William')
$sth = $this->database->conn->prepare('SELECT * FROM brukertabell WHERE Navn = ? AND Passord = ?');
$sth->execute([$username, $password]);
if ($sth->rowCount())
{
return TRUE;
}

View File

@ -30,7 +30,7 @@ $config = (
$database = new Database($config['database']);
$session = new Session;
$user = new User($session);
$user = new User($session, $database);
new AccessControl($user);