问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/26486946/joomla-acl-integration