簡體   English   中英

Joomla JAuthentication導致應用程序實例化錯誤

[英]Joomla JAuthentication giving Application Instantiation error

我有一個可以驗證joomla用戶password的api。 盡管它在Joomla 2.5中可以完美運行,但在Joomla 3.5中卻出現了“應用程序實例化”錯誤。 代碼部分如下:

函數checkAuthentication($ username,$ password){

jimport( 'joomla.user.authentication');
$auth = & JAuthentication::getInstance();
$credentials = array( 'username' => $username, 'password' => $password );
$options = array();
$response = $auth->authenticate($credentials, $options);

if ($response->status != JAUTHENTICATE_STATUS_SUCCESS)
{
    echo "Failure";
}
else
{
    echo "Success~" . $username;
}

}

在$ auth =&JAuthentication :: getInstance();行失敗。

我已經在配置文件中檢查了所有的配置,如數據庫設置等。 有人可以幫我找出原因。

下面的代碼應該可以解決問題-它是Joomla身份驗證插件(插件/身份驗證/joomla/joomla.php)的修改版本。

$query = $db->getQuery(true);
$query->select(array('id, 'password'));
$query->from('#__users');
$query->where($db->quoteName('username') . ' = ' . $db->quote($username));
$db->setQuery($query);
$result = $db->loadObject();

/*
 * This block supports Joomla 3.2 upwards
 */
if ($result)
{
    $match = JUserHelper::verifyPassword($password, $result->password, $result->id);

    if ($match === true)
    {
        $user = JUser::getInstance($result->id);
        $response->email = $user->email;
        $response->fullname = $user->name;

        if (JFactory::getApplication()->isAdmin())
        {
            $response->language = $user->getParam('admin_language');
        }
        else
        {
            $response->language = $user->getParam('language');
        }

        $response->status = JAuthentication::STATUS_SUCCESS;
        $response->error_message = '';
    }
    else
    {
        // Invalid password
        $response->status = JAuthentication::STATUS_FAILURE;
        $response->error_message = JText::_('JGLOBAL_AUTH_INVALID_PASS');
    }
}

暫無
暫無

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

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