簡體   English   中英

用戶登錄到前端-插件自動登錄到后端

[英]User logs into frontend - plugin to automatically be logged into backend

我需要創建一個系統插件(沒有auth插件!),其中登錄前端的用戶也自動登錄到后端。 (用戶有權通過/ administrator登錄到后端。)

我嘗試通過下面看到的非常基本的代碼來執行此操作,結果是肯定的,但是如果我轉到后端,則用戶仍然需要登錄。

在會話表中,設置了后端會話行,但“ guest”字段設置為1而不是0,而userid設置為0而不是正確的id。

如何才能做到這一點?

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");
    } 
}

除了這是一個非常糟糕的主意,正如這個問題中提到的Joomla! 被實現為兩個應用程序:前端( /index.php )和后端應用程序( /administrator/index.php )。

在提供的代碼中,您沒有顯示$app的初始化位置,因此我猜想它可能類似於$app->JFactory::getApplication('site');

要登錄到管理應用程序,您需要獲取它,而不是前端客戶端應用程序,例如

$adminApp->JFactory::getApplication('administrator');
$result = $adminApp->login($credentials, $options);

注意,這是未經測試的代碼,只是輸入了堆棧溢出...應該是正確的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM