Save admin status in persistent token
This commit is contained in:
@@ -251,7 +251,7 @@ The `config.php` file contains several key constants that may need adjustment fo
|
|||||||
Defines the maximum upload size (default is `5G`). Ensure that PHP’s `upload_max_filesize` and `post_max_size` in your `php.ini` are consistent with this setting. The startup script (`start.sh`) updates PHP limits at runtime based on this value.
|
Defines the maximum upload size (default is `5G`). Ensure that PHP’s `upload_max_filesize` and `post_max_size` in your `php.ini` are consistent with this setting. The startup script (`start.sh`) updates PHP limits at runtime based on this value.
|
||||||
|
|
||||||
- **Environment Variables (Docker):**
|
- **Environment Variables (Docker):**
|
||||||
The Docker image supports overriding configuration via environment variables. For example, you can set `SECURE`, `SHARE_URL`, and port settings via the container’s environment.
|
The Docker image supports overriding configuration via environment variables. For example, you can set `SECURE`, `SHARE_URL`, `PERSISTENT_TOKENS_KEY` and port settings via the container’s environment.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
5
auth.php
5
auth.php
@@ -110,10 +110,11 @@ if ($userRole !== false) {
|
|||||||
$persistentTokens = [];
|
$persistentTokens = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Save token along with username and expiry.
|
// Save token along with username, expiry, and admin status.
|
||||||
$persistentTokens[$token] = [
|
$persistentTokens[$token] = [
|
||||||
"username" => $username,
|
"username" => $username,
|
||||||
"expiry" => $expiry
|
"expiry" => $expiry,
|
||||||
|
"isAdmin" => ($userRole === "1")
|
||||||
];
|
];
|
||||||
$encryptedContent = encryptData(json_encode($persistentTokens, JSON_PRETTY_PRINT), $encryptionKey);
|
$encryptedContent = encryptData(json_encode($persistentTokens, JSON_PRETTY_PRINT), $encryptionKey);
|
||||||
file_put_contents($persistentTokensFile, $encryptedContent, LOCK_EX);
|
file_put_contents($persistentTokensFile, $encryptedContent, LOCK_EX);
|
||||||
|
|||||||
@@ -97,8 +97,7 @@ if (!isset($_SESSION["authenticated"]) && isset($_COOKIE['remember_me_token']))
|
|||||||
// Token is valid; auto-authenticate the user.
|
// Token is valid; auto-authenticate the user.
|
||||||
$_SESSION["authenticated"] = true;
|
$_SESSION["authenticated"] = true;
|
||||||
$_SESSION["username"] = $tokenData["username"];
|
$_SESSION["username"] = $tokenData["username"];
|
||||||
// Optionally, set admin status if stored in token data:
|
$_SESSION["isAdmin"] = $tokenData["isAdmin"]; // Restore admin status from the token
|
||||||
// $_SESSION["isAdmin"] = $tokenData["isAdmin"];
|
|
||||||
} else {
|
} else {
|
||||||
// Token expired; remove it and clear the cookie.
|
// Token expired; remove it and clear the cookie.
|
||||||
unset($persistentTokens[$_COOKIE['remember_me_token']]);
|
unset($persistentTokens[$_COOKIE['remember_me_token']]);
|
||||||
|
|||||||
Reference in New Issue
Block a user