2

Does anyone know of any way to integrate with Joomla ACL, specifically create users and log users in programatically within a custom component's controller and modules.

I've scoured Google but either am asking the wrong questions, no one has documented how to do it, or it's not possible (which I don't believe!)

Why you may ask?! - I am developing a single sign on application for a component that must log a user into several API's when they sign in. Unfortuanetly my client also wants this to work with ACL such that they can show control content on the front end of the website based on if a user is logged in or not.

So what I need to be abole to do is create my own login view and when used, log the user into the various systems using their API's and log them into (or create an account and log into) Joomla ACL.

dan360
  • 361
  • 2
  • 16

1 Answers1

2

You could just clone the installed mod_login for the login portion of it, and use some form of the below code for creating the user account:

You can create the user with this:

require_once('registration.php');
jimport('joomla.user.helper');
jimport('joomla.application.component.modeladmin');
$data = array(
    'username'  => 'jdoe',
    'name'      => 'Joan Doe',
    'email1'    => jdoe@jdoe.com,
    'password1' => 'abc123', // First password field
    'password2' => 'abc123', // Confirm password field
    'block'     => 0,
    'params'    => array(
        'admin_style'=>'',
        'admin_language'=>'',
        'language'=>'',
        'editor'=>'',
        'helpsite'=>'',
        'timezone'=>''
    )
);
$model = new UsersModelRegistration();
if(!$user = $model->register($data)) {
    echo $model->getError();
}

You can login with this:

$app = JFactory::getApplication('site');
$credentials = array(
    'username' => 'someusername',
    'password' => 'somepassword'
);
if(!$app->login($credentials)){
    echo 'Logged in';
}else{
    echo 'Not logged in';
}
$app->logout();    // Log out with this
$app->close();     // Close the app

To add custom code to the login process, you can write a simple User Authentication plugin. (See Creating an Authentication Plugin for Joomla) and put your code in the onAuthenticate() function.

To add custom code AFTER authentication, write a User Plugin (See Plugin/Events/User) and use one of the events that fire there.

I wasn't clear on the ACL values being stored, and got clarification with this question. It's about category permissions, but it's answer may help.

Community
  • 1
  • 1
GDP
  • 8,109
  • 6
  • 45
  • 82
  • This is great and has got be along way so thank you very much. Howwever when I register an account "block" is set to 1 - I can't seem to set it to 0, or find the id to set it to zero - or find an activation code in order to call the activate method. Any further help would be very appreciated. – dan360 Nov 04 '14 at 12:34
  • Ignore the above comment I worked it out by looking through the code for the class - You've been a great help thank you very much! – dan360 Nov 04 '14 at 12:42