I am making my own component in Joomla, which provides me login through an external site.

Last issue I need to solve is the login. When I trigger onUserLogin event by:

$dispatcher->triggerEvent('onUserLogin', array($response, $options));

It works, but only for front-end site.

What I have to do to login to the back-end? Is there any trick which would help me, for example manually create session and insert to db?

If not, what plugin method do I have to override?

  • front-end and back-end are two different sites.
    – FFrewin
    Dec 6 '17 at 18:57
  • Can you help me with login to backend? Very important for me Any help appreciated Dec 6 '17 at 20:23

I used code below to login to the backend automatically, and it works fine, the location where I put these code is: /plugins/system/mysociallogin/mysociallogin.php

The mistake I made before is that I requested to the wrong url. If you want to login to the backend, don't forget to request to /administrator/index.php, the frontend and backend are two different sites in fact.

if (isset ($identity->UserId))
    require_once JPATH_ADMINISTRATOR . '/components/com_login/models/login.php';
    $adminApp = JApplication::getInstance('administrator');

    $model       = JModelLegacy::getInstance('login', 'LoginModel');
    $credentials = array('username' => $user_login,
                         'password' => $user_identity_id);
    $return      = "index.php";

    $ret = $adminApp->login($credentials, array('action' => 'core.login.admin', 'entry_url' => '/administrator/index.php?option=com_users&task=user.login'));

    if ($ret && !($ret instanceof Exception))
        // Only redirect to an internal URL.
        if (JUri::isInternal($return))
            // If &tmpl=component - redirect to index.php
            if (strpos($return, 'tmpl=component') === false)

update Nov 4, 2018

finally, I found login to the backend is as easy as a few code below to achieve:

$options['group'] = 'Public Backend'; $options['autoregister'] = false; $options['action'] = 'core.login.admin';

$response = new stdClass(); $response->username = "su";

JPluginHelper::importPlugin ('user'); $result = $app->triggerEvent ('onUserLogin', array ((array) $response, $options)); /* key point*/

just FYI~


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.