?
avatar JTBlum
JTBlum
28 Apr 2017

Steps to reproduce the issue

$app = JApplicationCms::getInstance();
$credentials = array(
'username'=>$username
'password'=>$password
);
$options = array('action'=>'core.login.site'); // Define options and suppress 'cannot access private section of this website' warning in Joomla Core
$app->login($credentials,$options);

Expected result

The user is logged in with no error messages or the call fails and returns false or throws an exception

Actual result

Joomla displays an error message: "Call to a member function get() on null" from the line "$app->login($credentials,$options);"
Attempting to use JApplication (via JFactory::getApplication()) instead of JApplicationCms results in the same error. JApplicationWeb, which is indicated as a replacement for JApplicationCms in the Joomla 3.6 API documentation simply does not have a login method. Attempting to use triggerEvent instead seems to do nothing, but I'll admit I've never used it before and could have done it incorrectly. I tried the following:

$app = JApplicationWeb::getInstance();
$credentials = array(
'username'=>$username
'password'=>$password
);
$app->triggerEvent('core.login.site',$credentials)

System information (as much as possible)

PHP Built On Linux jbdev01 3.10.0-514.6.1.el7.x86_64 #1 SMP Wed Jan 18 13:06:36 UTC 2017 x86_64
Database Version 5.5.52-MariaDB
Database Collation utf8_general_ci
Database Connection Collation utf8mb4_general_ci
PHP Version 7.0.16
Web Server Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_fcgid/2.3.9 PHP/7.0.16
WebServer to PHP Interface apache2handler

The Joomla install was freshly updated from 3.6.5 to 3.7.0 with nothing else changed. The code worked perfectly well before the update.

Additional comments

I'm not really familiar with how Joomla authentication works beyond what I researched for our plugin-turned-component, so I'm afraid I don't know how to pursue this without dedicating significant research time to it (which I don't have, given my other projects).

avatar JTBlum JTBlum - open - 28 Apr 2017
avatar joomla-cms-bot joomla-cms-bot - labeled - 28 Apr 2017
avatar PhilETaylor
PhilETaylor - comment - 2 May 2017

Sounds like you are looking for support rather than reporting an issue in Joomla.

The 'correct' way to attempt authentication with the Joomla API in recent versions of Joomla would be something like:

// jimport('joomla.user.authentication'); // May be needed depending on your stack to this point.

$credentials = array('username' => 'admin', 'password' =>'admin');

$response = JAuthentication::getInstance()->authenticate($credentials, array());

if ($response->status != JAuthentication::STATUS_SUCCESS) {
	echo "Oh Snap! Failure!";
} else {
	echo "W00t! Success";
}

A full example, based on the /index.php file of Joomla can be seen here (prepared for you)

https://gist.github.com/PhilETaylor/9bdf7b3032825f9f457e86196bb3909d

As this is not an issue in Joomla please close this issue and seek support in the Joomla Forums

avatar joomla-cms-bot joomla-cms-bot - change - 2 May 2017
Status New Closed
Closed_Date 0000-00-00 00:00:00 2017-05-02 18:43:05
Closed_By joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 2 May 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 2 May 2017
Priority Urgent Medium
Closed_By joomla-cms-bot franz-wohlkoenig
avatar joomla-cms-bot
joomla-cms-bot - comment - 2 May 2017
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 2 May 2017

closed as no Core Issue.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/15663.

avatar JTBlum
JTBlum - comment - 2 May 2017

Aah. Thanks for the help then, and my apologies for wasting time. That shouldn't have taken me long to find.

Add a Comment

Login with GitHub to post a comment