Twig, Tests, AES,
This commit is contained in:
@@ -17,7 +17,9 @@ class User extends ApiObject {
|
||||
private ?Session $session;
|
||||
private int $uid;
|
||||
private string $username;
|
||||
private string $fullName;
|
||||
private ?string $email;
|
||||
private ?string $profilePicture;
|
||||
private Language $language;
|
||||
private array $groups;
|
||||
|
||||
@@ -55,6 +57,7 @@ class User extends ApiObject {
|
||||
public function getId(): int { return $this->uid; }
|
||||
public function isLoggedIn(): bool { return $this->loggedIn; }
|
||||
public function getUsername(): string { return $this->username; }
|
||||
public function getFullName(): string { return $this->fullName; }
|
||||
public function getEmail(): ?string { return $this->email; }
|
||||
public function getSQL(): ?SQL { return $this->sql; }
|
||||
public function getLanguage(): Language { return $this->language; }
|
||||
@@ -63,6 +66,7 @@ class User extends ApiObject {
|
||||
public function getConfiguration(): Configuration { return $this->configuration; }
|
||||
public function getGroups(): array { return $this->groups; }
|
||||
public function hasGroup(int $group): bool { return isset($this->groups[$group]); }
|
||||
public function getProfilePicture() : ?string { return $this->profilePicture; }
|
||||
|
||||
public function __debugInfo(): array {
|
||||
$debugInfo = array(
|
||||
@@ -83,6 +87,8 @@ class User extends ApiObject {
|
||||
return array(
|
||||
'uid' => $this->uid,
|
||||
'name' => $this->username,
|
||||
'fullName' => $this->fullName,
|
||||
'profilePicture' => $this->profilePicture,
|
||||
'email' => $this->email,
|
||||
'groups' => $this->groups,
|
||||
'language' => $this->language->jsonSerialize(),
|
||||
@@ -99,8 +105,10 @@ class User extends ApiObject {
|
||||
$this->uid = 0;
|
||||
$this->username = '';
|
||||
$this->email = '';
|
||||
$this->groups = [];
|
||||
$this->loggedIn = false;
|
||||
$this->session = null;
|
||||
$this->profilePicture = null;
|
||||
}
|
||||
|
||||
public function logout(): bool {
|
||||
@@ -137,9 +145,9 @@ class User extends ApiObject {
|
||||
* @param bool $sessionUpdate update session information, including session's lifetime and browser information
|
||||
* @return bool true, if the data could be loaded
|
||||
*/
|
||||
public function readData($userId, $sessionId, $sessionUpdate = true): bool {
|
||||
public function readData($userId, $sessionId, bool $sessionUpdate = true): bool {
|
||||
|
||||
$res = $this->sql->select("User.name", "User.email",
|
||||
$res = $this->sql->select("User.name", "User.email", "User.fullName", "User.profilePicture",
|
||||
"Language.uid as langId", "Language.code as langCode", "Language.name as langName",
|
||||
"Session.data", "Session.stay_logged_in", "Session.csrf_token", "Group.uid as groupId", "Group.name as groupName")
|
||||
->from("User")
|
||||
@@ -162,7 +170,10 @@ class User extends ApiObject {
|
||||
$csrfToken = $row["csrf_token"];
|
||||
$this->username = $row['name'];
|
||||
$this->email = $row["email"];
|
||||
$this->fullName = $row["fullName"];
|
||||
$this->uid = $userId;
|
||||
$this->profilePicture = $row["profilePicture"];
|
||||
|
||||
$this->session = new Session($this, $sessionId, $csrfToken);
|
||||
$this->session->setData(json_decode($row["data"] ?? '{}'));
|
||||
$this->session->stayLoggedIn($this->sql->parseBool(["stay_logged_in"]));
|
||||
@@ -183,16 +194,14 @@ class User extends ApiObject {
|
||||
}
|
||||
|
||||
private function parseCookies() {
|
||||
if(isset($_COOKIE['session'])
|
||||
&& is_string($_COOKIE['session'])
|
||||
&& !empty($_COOKIE['session'])) {
|
||||
if(isset($_COOKIE['session']) && is_string($_COOKIE['session']) && !empty($_COOKIE['session'])) {
|
||||
try {
|
||||
$token = $_COOKIE['session'];
|
||||
$settings = $this->configuration->getSettings();
|
||||
$decoded = (array)JWT::decode($token, $settings->getJwtSecret());
|
||||
if(!is_null($decoded)) {
|
||||
$userId = (isset($decoded['userId']) ? $decoded['userId'] : NULL);
|
||||
$sessionId = (isset($decoded['sessionId']) ? $decoded['sessionId'] : NULL);
|
||||
$userId = ($decoded['userId'] ?? NULL);
|
||||
$sessionId = ($decoded['sessionId'] ?? NULL);
|
||||
if(!is_null($userId) && !is_null($sessionId)) {
|
||||
$this->readData($userId, $sessionId);
|
||||
}
|
||||
@@ -226,7 +235,8 @@ class User extends ApiObject {
|
||||
return true;
|
||||
}
|
||||
|
||||
$res = $this->sql->select("ApiKey.user_id as uid", "User.name", "User.email", "User.confirmed",
|
||||
$res = $this->sql->select("ApiKey.user_id as uid", "User.name", "User.fullName", "User.email",
|
||||
"User.confirmed", "User.profilePicture",
|
||||
"Language.uid as langId", "Language.code as langCode", "Language.name as langName",
|
||||
"Group.uid as groupId", "Group.name as groupName")
|
||||
->from("ApiKey")
|
||||
@@ -240,8 +250,8 @@ class User extends ApiObject {
|
||||
->execute();
|
||||
|
||||
$success = ($res !== FALSE);
|
||||
if($success) {
|
||||
if(empty($res)) {
|
||||
if ($success) {
|
||||
if (empty($res) || !is_array($res)) {
|
||||
$success = false;
|
||||
} else {
|
||||
$row = $res[0];
|
||||
@@ -251,7 +261,9 @@ class User extends ApiObject {
|
||||
|
||||
$this->uid = $row['uid'];
|
||||
$this->username = $row['name'];
|
||||
$this->fullName = $row["fullName"];
|
||||
$this->email = $row['email'];
|
||||
$this->profilePicture = $row["profilePicture"];
|
||||
|
||||
if(!is_null($row['langId'])) {
|
||||
$this->setLanguage(Language::newInstance($row['langId'], $row['langCode'], $row['langName']));
|
||||
|
||||
Reference in New Issue
Block a user