35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
class Account {
|
|
private $current_user;
|
|
private $conn;
|
|
|
|
public function __construct($current_user, $conn) {
|
|
$this->current_user = $current_user;
|
|
$this->conn = $conn;
|
|
}
|
|
|
|
public function isLoggedIn() {
|
|
return isset($_SESSION["user"]) && $_SESSION["user"] == $this->current_user;
|
|
}
|
|
|
|
public function accountExists() {
|
|
$stmt = $this->conn->prepare("SELECT username FROM accounts WHERE username = :username");
|
|
$stmt->bindParam(":username", $this->current_user);
|
|
$stmt->execute();
|
|
|
|
return $stmt->rowCount() > 0;
|
|
}
|
|
|
|
public function getDetails($info) {
|
|
if (!$this->accountExists() || !$this->isLoggedIn())
|
|
return NULL;
|
|
|
|
$stmt = $this->conn->prepare("SELECT * FROM accounts WHERE username = :username");
|
|
$stmt->bindParam(":username", $this->current_user);
|
|
$stmt->execute();
|
|
|
|
$current_user = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
return $current_user[$info] ?? NULL;
|
|
}
|
|
}
|
|
?>
|