Skip to content

Commit 98259d6

Browse files
committed
UserPanel: displays 'Session is closed' on closed session [Closes #52]
1 parent 8f8965a commit 98259d6

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/Bridges/SecurityTracy/UserPanel.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ public function __construct(Nette\Security\User $user)
3535
*/
3636
public function getTab(): ?string
3737
{
38-
if (headers_sent() && !session_id()) {
38+
if (!session_id()) {
3939
return null;
4040
}
4141

4242
return Nette\Utils\Helpers::capture(function () {
43-
$user = $this->user;
43+
$status = session_status() === PHP_SESSION_ACTIVE
44+
? $this->user->isLoggedIn()
45+
: '?';
4446
require __DIR__ . '/templates/UserPanel.tab.phtml';
4547
});
4648
}
@@ -49,8 +51,11 @@ public function getTab(): ?string
4951
/**
5052
* Renders panel.
5153
*/
52-
public function getPanel(): string
54+
public function getPanel(): ?string
5355
{
56+
if (session_status() !== PHP_SESSION_ACTIVE) {
57+
return null;
58+
}
5459
return Nette\Utils\Helpers::capture(function () {
5560
$user = $this->user;
5661
require __DIR__ . '/templates/UserPanel.panel.phtml';

src/Bridges/SecurityTracy/templates/UserPanel.tab.phtml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ declare(strict_types=1);
33

44
namespace Nette\Bridges\SecurityTracy;
55

6+
$message = [true => 'Logged in', false => 'Unlogged', '?' => 'Session is closed'];
7+
$color = [true => '#61A519', false => '#ababab', '?' => '#bb0000'];
68
?>
7-
<span title="<?= $user->isLoggedIn() ? 'Logged in' : 'Unlogged' ?>">
8-
<svg viewBox="0 -50 2048 2048"><path fill="<?= $user->isLoggedIn() ? '#61A519' : '#ababab' ?>" d="m1615 1803.5c-122 17-246 7-369 8-255 1-510 3-765-1-136-2-266-111-273-250-11-192 11-290.5 115-457.5 62-100 192-191 303-147 110 44 201 130 321 149 160 25 317-39 446-130 82-58 200-9 268 51 157 173 186.8 275.49 184 484.49-1.9692 147.11-108.91 271.41-230 293zm-144-1226.5c0 239-208 447-447 447s-447-208-447-447 208-447 447-447c240 1 446 207 447 447z"/></svg>
9+
<span title="<?= $message[$status] ?>">
10+
<svg viewBox="0 -50 2048 2048"><path fill="<?= $color[$status] ?>" d="m1615 1803.5c-122 17-246 7-369 8-255 1-510 3-765-1-136-2-266-111-273-250-11-192 11-290.5 115-457.5 62-100 192-191 303-147 110 44 201 130 321 149 160 25 317-39 446-130 82-58 200-9 268 51 157 173 186.8 275.49 184 484.49-1.9692 147.11-108.91 271.41-230 293zm-144-1226.5c0 239-208 447-447 447s-447-208-447-447 208-447 447-447c240 1 446 207 447 447z"/></svg>
911
</span>

0 commit comments

Comments
 (0)