[英]User logs into frontend - plugin to automatically be logged into backend
I need to create a system plugin (no auth plugin!) where a user which logges into the frontend automaticaly gets logged in the backend too. 我需要创建一个系统插件(没有auth插件!),其中登录前端的用户也自动登录到后端。 (The user has the rights to log into the backend via /administrator.)
(用户有权通过/ administrator登录到后端。)
I try to do it via the very basic code you see below, the result is positive, but if i go to the backend the user still needs to log in. 我尝试通过下面看到的非常基本的代码来执行此操作,结果是肯定的,但是如果我转到后端,则用户仍然需要登录。
In the session table the backend session row is set, but the "guest" field is set to 1 instead of 0 and the userid is set to 0 instead of the correct id. 在会话表中,设置了后端会话行,但“ guest”字段设置为1而不是0,而userid设置为0而不是正确的id。
How can this be done? 如何才能做到这一点?
function onAfterInitialise() {
if(JFactory::getUser()->get('id')) { // logged in?
$credentials = array();
$credentials['username'] = "walter"; // hardcoded first
$credentials['password'] = "123"; // hardcoded first
$options = array();
$options['action'] = 'core.login.admin';
$result = $app->login($credentials, $options); // this seams to work
if (!($result instanceof Exception)) {
$app->redirect("www.bummer.de");
}
}
Apart from this being a very bad idea, as mentioned in this question Joomla! 除了这是一个非常糟糕的主意,正如这个问题中提到的Joomla! is implemented as two applications a front-end (
/index.php
) and back-end application ( /administrator/index.php
). 被实现为两个应用程序:前端(
/index.php
)和后端应用程序( /administrator/index.php
)。
In the code provided you don't show where $app
is initialised so I'm guessing that it's probably something like $app->JFactory::getApplication('site');
在提供的代码中,您没有显示
$app
的初始化位置,因此我猜想它可能类似于$app->JFactory::getApplication('site');
. 。
To login to the admin app you need to get it rather than the front-end client app eg 要登录到管理应用程序,您需要获取它,而不是前端客户端应用程序,例如
$adminApp->JFactory::getApplication('administrator');
$result = $adminApp->login($credentials, $options);
nb this is untested code just typed in to stack overflow... it should be right. 注意,这是未经测试的代码,只是输入了堆栈溢出...应该是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.