Commit
This commit is contained in:
parent
542e9bf5f2
commit
0773afdae5
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user