简体   繁体   English

用户登录到前端-插件自动登录到后端

[英]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.

相关问题 如何清除登录到joomla前端和后端的同一用户的数据库会话? - How to clear session from database for same user logged into frontend and backend of joomla? 使用来自后端插件的命令更改前端的样式 - Changing style in Frontend with commands from Backend Plugin 在前端已经登录时如何在不重新认证的情况下登录joomla后端? - How to login into joomla backend without reauthenticated when already logged in frontend? 获取仅记录到Joomla后端的用户会话 - Get User Session logged only to Joomla Backend Wordpress 自定义插件后端复选框在前端更改 css - Wordpress custom plugin backend checkbox changing css in frontend Wordpress插件高级自定义字段Pro不保存前端和后端 - Wordpress plugin Advanced Custom Fields Pro not saving Frontend and Backend wordpress插件如何从后端向前端发送数据 - How to send data from the backend to the frontend in a wordpress plugin 如何在前端显示未登录用户的wordpress编辑器项目? - How to display wordpress Editor Items for non Logged in User in frontend? 用户以不同的用户身份自动登录 - Users get logged in automatically as different user 用户注册后自动登录 - User gets automatically logged in after Registeration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM