As @Martin's answer option, the component can return the JUser object associated with the specified credentials. In Joomla 2.5, the following component is tested:
View view.raw.php :
defined( '_JEXEC' ) or die( 'Restricted access' ); jimport( 'joomla.application.component.view' ); class ExtauthViewLogin extends JView { function display( $tpl = null ) { $username = JRequest::getVar( 'username', 'John Doe' ); $password = JRequest::getVar( 'password', 'rattlesnake' ); jimport('joomla.user.authentication'); $app = JFactory::getApplication(); $credentials = array( "username" => $username, "password" => $password); $options = array("silent" => true); $authorized = $app->logout(null, $options); $authorized = $app->login($credentials, $options); $user = JFactory::getUser(); echo json_encode($user); } }
Pay attention to the exit before login . After a successful login, all subsequent calls with incorrect credentials will still return the user of the first call without logging out!
Also note the silent parameter. This causes the input function to return gracefully with true or false, without spawning.
controller.php :
defined( '_JEXEC' ) or die( 'Restricted access' ); jimport( 'joomla.application.component.controller' ); class ExtauthController extends JController { function display($cachable = false, $urlparams = false) { $view = JRequest::getVar( 'view', 'login' ); $layout = JRequest::getVar( 'layout', 'default' ); $format = JRequest::getVar( 'format', 'raw' ); $view = $this->getView( $view, $format ); $view->setLayout( $layout ); $view->display(); } }
Pay attention to the raw format. This is necessary so that joomla returns pure json code instead of the entire html page.
A component can be invoked (via ajax) using url:
index.php?option=com_extauth&task=view&format=raw&username=John&password=Doe
The returned JSON object will contain NULL values ββfor most fields if the login fails.
The full component is the simplest, based on com_hello without a model or tmpl.
source share