adamkiss/kirby-impersonate

在 Kirby CMS 控制面板中模仿用户

0.6.1 2024-04-28 12:54 UTC

This package is auto-updated.

Last update: 2024-09-28 13:46:10 UTC


README

此插件允许在您的面板和/或前端中模仿用户,通过添加一个“用户正在被模仿”的会话标记,然后强制调用 kirby()->impersonate() 来模仿目标用户。

安装

composer require adamkiss/kirby-impersonate

与所有 Kirby 插件一样,下载 zip 文件应该也能正常工作。也应该可以使用 git 子模块,但我从未测试过这一点。

使用方法

如果您只想使用此插件进行面板调试,只需安装它,可能还需要配置谁可以模仿/被模仿,然后即可完成。如果您还想要测试不同的前端可用性,您可以更改管理员在开始模仿后重定向到的位置,前端应该“仅”像被模仿的用户一样工作。

对于关于持续模仿的通知,您可以使用 kirby()->user()->isImpersonated(),您可以使用路由 /__impersonate/stop 来停止模仿。例如,在您的模板中使用以下内容

<?= kirby()->user()->isImpersonated() ? '<a href="/__impersonate/stop">Stop Impersonation</a>' : ''?>

配置

默认情况下,任何可以访问用户表的用户都可以模仿任何其他用户。在模仿开始时,窗口会重新加载,在模仿结束时,您将被重定向到面板中的用户视图;所有这些都可以通过选项进行配置。

// config.php
return [
	'adamkiss.kirby-impersonate' => [
		'can-impersonate' => function () {
			// who can impersonate? this is a user method,
			// so "$this" is a user who's checked.
			// you have access to role, email, uuid…

			/** @var User $this */
			return true;
		},
		'can-be-impersonated' => function () {
			// who can be target of impersonation? this is a user method,
			// so "$this" is a user who's checked
			// you have access to role, email, uuid…

			/** @var User $this */
			return true;
		},
		
		// Since the start of redirection is in the users area, null just reloads
		// You can also use a string to get a URL, or a Closure with the impersonated user
		// if you need different redirects base on role / email / whatever
		'redirect-after-impersonation-start' => null,

		// Where you're redirected after the impersonation stops
		// this can be only a string
		'redirect-after-impersonation-stop' => kirby()->url('panel') . '/users',    ]
];

许可证

MIT, (c) 2024 Adam Kiss

有关更多信息,请参阅 LICENSE.md