Create function in \fengoffice\application\models\users\User.class.php
/**
* Get user attributes from ldap
*
* @return attribute value
*/
function AttribFromLdap($user, $password, $config, $attrib) {
// Connecting using the configuration:
require_once "Net/LDAP2.php";
$ldap = Net_LDAP2::connect($config);
// Testing for connection error
if (PEAR::isError($ldap)) {
return false;
}
$filter = Net_LDAP2_Filter::create($config['uid'], 'equals', $user);
$search = $ldap->search(null, $filter, array());
if (Net_LDAP2::isError($search)) {
return false;
}
if ($search->count() != 1) {
return false;
}
// User exists so we may rebind to authenticate the password
$entries = $search->entries();
$result = $entries[0]->getValue($attrib);
return $result;
} // AttribFromLdap
Change \fengoffice\application\controllers\AccessController.class.php in section // If ldap authentication is enabled ldap.config.php will return true.
// If ldap authentication is enabled ldap.config.php will return true.
$config_ldap_file_path = ROOT . '/config/ldap.config.php';
$config_ldap_is_set = file_exists($config_ldap_file_path) && include_once($config_ldap_file_path);
// create temp object and check LDAP
$temp_user = new User();
$temp_user->setCompanyId(1);
$temp_user->setUsername($username);
$temp_user->setPassword($password);
$userIsValidPassword = $temp_user->isValidPasswordLdap($username, $password, $config_ldap); // Check password
if ($userIsValidPassword && !($user instanceof User)) { //If user found in LDAP and not registered then save user and set properties
$temp_user->setEmail($temp_user->AttribFromLdap($username, $password, $config_ldap, "mail")); // Use custom function. \fengoffice\application\models\users\User.class.php
$temp_user->setDisplayName($temp_user->AttribFromLdap($username, $password, $config_ldap, "cn"));
$temp_user->save();
$user = $temp_user;
$project = new Project();
$project->setName(new_personal_project_name($user->getDisplayName())); // set Project name. For exemple $user->getUsername()
$project->setDescription(lang('files'));
$project->setCreatedById($user->getId());
$project->save();
$user->setPersonalProjectId($project->getId()); // set default project
$project_user = new ProjectUser();
$project_user->setProjectId($project->getId());
$project_user->setUserId($user->getId());
$project_user->setCreatedById($user->getId());
$project_user->setAllPermissions(true);
$project_user->save();
}
if(!($user instanceof User)) {
AdministrationLogs::createLog("invalid login", array_var($_SERVER, 'REMOTE_ADDR'), AdministrationLogs::ADM_LOG_CATEGORY_SECURITY);
tpl_assign('error', new Error(lang('invalid login data')));
$this->render();
} // if
Working!