Вход под пользователем: право users.impersonate, Auth::impersonate()/realUser()
This commit is contained in:
1 parent
8dddca6d1a
commit
b8af28c181
11 files changed
+495
-36
No files matched your search
@@ -10,6 +10,7 @@ use Rsgrinko\Proton\Auth\Auth;
|
||||
use Rsgrinko\Proton\Auth\Csrf;
|
||||
use Rsgrinko\Proton\Http\Response;
|
||||
use Rsgrinko\Proton\Http\Router;
|
||||
use Rsgrinko\Proton\Models\User;
|
||||
use Rsgrinko\Proton\Support\Config;
|
||||
use Rsgrinko\Proton\Support\ProtonException;
|
||||
|
||||
@@ -212,6 +213,23 @@ final class View
|
||||
return Auth::viewer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Идёт ли сейчас «вход под пользователем» — каркас страницы по этому
|
||||
* показывает верхнюю плашку с кнопкой возврата.
|
||||
*/
|
||||
public static function isImpersonating(): bool
|
||||
{
|
||||
return Auth::isImpersonating();
|
||||
}
|
||||
|
||||
/**
|
||||
* Настоящий вошедший во время подмены — тот, кому вернётся сессия.
|
||||
*/
|
||||
public static function impersonator(): ?User
|
||||
{
|
||||
return Auth::realUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Человеческая дата.
|
||||
*/
|
||||
|
||||
@@ -261,6 +261,13 @@ $unread = $viewer->isGuest() ? 0 : UserNotification::unreadFor($viewer->id());
|
||||
.flash.ok { background: var(--ok-bg); color: var(--ok); }
|
||||
.flash.error { background: var(--err-bg); color: var(--err); }
|
||||
|
||||
/* Плашка «вход под пользователем»: сверху шапки, чтобы не спутать
|
||||
с обычным флеш-сообщением и не потерять при прокрутке */
|
||||
.impersonating { background: var(--warn-bg); color: var(--warn); padding: 6px 20px;
|
||||
display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; }
|
||||
.impersonating form { display: inline; }
|
||||
.impersonating button { padding: 3px 10px; font-size: 12px; }
|
||||
|
||||
.muted { color: var(--muted); }
|
||||
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
|
||||
.nowrap { white-space: nowrap; }
|
||||
@@ -363,6 +370,16 @@ $unread = $viewer->isGuest() ? 0 : UserNotification::unreadFor($viewer->id());
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?php if (!$bare && View::isImpersonating()) { ?>
|
||||
<div class="impersonating">
|
||||
Вы вошли как <b><?= View::e($viewer->name()) ?></b>, обычно — <?= View::e((string) View::impersonator()?->login) ?>.
|
||||
<form method="post" action="<?= View::e(View::route('admin.impersonate.stop')) ?>">
|
||||
<?= View::csrf() ?>
|
||||
<button type="submit">Вернуться в свою учётную запись</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (!$bare) { ?>
|
||||
<header>
|
||||
<input type="checkbox" id="menu-toggle" class="menu-toggle" hidden>
|
||||
|
||||
Reference in new issue
Block a user