public function run() { global $ilLog; $status = ilCronJobResult::STATUS_NO_ACTION; $messages = array(); foreach (ilLDAPServer::_getCronServerIds() as $server_id) { try { $this->current_server = new ilLDAPServer($server_id); $this->current_server->doConnectionCheck(); $ilLog->write("LDAP: starting user synchronization for " . $this->current_server->getName()); $this->ldap_query = new ilLDAPQuery($this->current_server); $this->ldap_query->bind(IL_LDAP_BIND_DEFAULT); if (is_array($users = $this->ldap_query->fetchUsers())) { // Deactivate ldap users that are not in the list $this->deactivateUsers($this->current_server, $users); } if (count($users)) { $ilLog->write("LDAP: Starting update/creation of users ..."); include_once './Services/User/classes/class.ilUserCreationContext.php'; ilUserCreationContext::getInstance()->addContext(ilUserCreationContext::CONTEXT_LDAP); $this->ldap_to_ilias = new ilLDAPAttributeToUser($this->current_server); $this->ldap_to_ilias->setNewUserAuthMode($this->current_server->getAuthenticationMappingKey()); #$ilLog->write(print_r($users,true)); $this->ldap_to_ilias->setUserData($users); $this->ldap_to_ilias->refresh(); $ilLog->write("LDAP: Finished update/creation"); $this->counter++; } else { $ilLog->write("LDAP: No users for update/create. Aborting."); } } catch (ilLDAPQueryException $exc) { $mess = $exc->getMessage(); $ilLog->write($mess); $messages[] = $mess; } } if ($this->counter) { $status = ilCronJobResult::STATUS_OK; } $result = new ilCronJobResult(); if (sizeof($messages)) { $result->setMessage(implode("\n", $messages)); } $result->setStatus($status); return $result; }
protected function __createUser($a_role) { /** * @var $ilSetting ilSetting * @var $rbacadmin ilRbacAdmin * @var $lng ilLanguage */ global $ilSetting, $rbacadmin, $lng; // something went wrong with the form validation if (!$a_role) { global $ilias; $ilias->raiseError("Invalid role selection in registration" . ", IP: " . $_SERVER["REMOTE_ADDR"], $ilias->error_obj->FATAL); } $this->userObj = new ilObjUser(); include_once "./Services/User/classes/class.ilUserProfile.php"; $up = new ilUserProfile(); $up->setMode(ilUserProfile::MODE_REGISTRATION); $map = array(); $up->skipGroup("preferences"); $up->skipGroup("settings"); $up->skipGroup("instant_messengers"); $up->skipField("password"); $up->skipField("birthday"); $up->skipField("upload"); foreach ($up->getStandardFields() as $k => $v) { if ($v["method"]) { $method = "set" . substr($v["method"], 3); if (method_exists($this->userObj, $method)) { if ($k != "username") { $k = "usr_" . $k; } $field_obj = $this->form->getItemByPostVar($k); if ($field_obj) { $this->userObj->{$method}($this->form->getInput($k)); } } } } $this->userObj->setFullName(); $birthday_obj = $this->form->getItemByPostVar("usr_birthday"); if ($birthday_obj) { $birthday = $this->form->getInput("usr_birthday"); $birthday = $birthday["date"]; // when birthday was not set, array will not be substituted with string by ilBirthdayInputGui if (!is_array($birthday)) { $this->userObj->setBirthday($birthday); } } // messenger $map = array("icq", "yahoo", "msn", "aim", "skype", "jabber", "voip"); foreach ($map as $client) { $field = "usr_im_" . $client; $field_obj = $this->form->getItemByPostVar($field); if ($field_obj) { $this->userObj->setInstantMessengerId($client, $this->form->getInput($field)); } } $this->userObj->setTitle($this->userObj->getFullname()); $this->userObj->setDescription($this->userObj->getEmail()); if ($this->registration_settings->passwordGenerationEnabled()) { $password = ilUtil::generatePasswords(1); $password = $password[0]; } else { $password = $this->form->getInput("usr_password"); } $this->userObj->setPasswd($password); // Set user defined data include_once './Services/User/classes/class.ilUserDefinedFields.php'; $user_defined_fields =& ilUserDefinedFields::_getInstance(); $defs = $user_defined_fields->getRegistrationDefinitions(); $udf = array(); foreach ($_POST as $k => $v) { if (substr($k, 0, 4) == "udf_") { $f = substr($k, 4); $udf[$f] = $v; } } $this->userObj->setUserDefinedData($udf); $this->userObj->setTimeLimitOwner(7); $access_limit = null; $this->code_was_used = false; if ($this->code_enabled) { $code_local_roles = $code_has_access_limit = null; // #10853 - could be optional $code = $this->form->getInput('usr_registration_code'); if ($code) { include_once './Services/Registration/classes/class.ilRegistrationCode.php'; // set code to used ilRegistrationCode::useCode($code); $this->code_was_used = true; // handle code attached local role(s) and access limitation $code_data = ilRegistrationCode::getCodeData($code); if ($code_data["role_local"]) { // need user id before we can assign role(s) $code_local_roles = explode(";", $code_data["role_local"]); } if ($code_data["alimit"]) { // see below $code_has_access_limit = true; switch ($code_data["alimit"]) { case "absolute": $abs = date_parse($code_data["alimitdt"]); $access_limit = mktime(23, 59, 59, $abs['month'], $abs['day'], $abs['year']); break; case "relative": $rel = unserialize($code_data["alimitdt"]); $access_limit = $rel["d"] * 86400 + $rel["m"] * 2592000 + $rel["y"] * 31536000 + time(); break; } } } } // code access limitation will override any other access limitation setting if (!($this->code_was_used && $code_has_access_limit) && $this->registration_settings->getAccessLimitation()) { include_once 'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php'; $access_limitations_obj = new ilRegistrationRoleAccessLimitations(); switch ($access_limitations_obj->getMode($a_role)) { case 'absolute': $access_limit = $access_limitations_obj->getAbsolute($a_role); break; case 'relative': $rel_d = (int) $access_limitations_obj->getRelative($a_role, 'd'); $rel_m = (int) $access_limitations_obj->getRelative($a_role, 'm'); $rel_y = (int) $access_limitations_obj->getRelative($a_role, 'y'); $access_limit = $rel_d * 86400 + $rel_m * 2592000 + $rel_y * 31536000 + time(); break; } } if ($access_limit) { $this->userObj->setTimeLimitUnlimited(0); $this->userObj->setTimeLimitUntil($access_limit); } else { $this->userObj->setTimeLimitUnlimited(1); $this->userObj->setTimeLimitUntil(time()); } $this->userObj->setTimeLimitFrom(time()); include_once './Services/User/classes/class.ilUserCreationContext.php'; ilUserCreationContext::getInstance()->addContext(ilUserCreationContext::CONTEXT_REGISTRATION); $this->userObj->create(); if ($this->registration_settings->getRegistrationType() == IL_REG_DIRECT || $this->registration_settings->getRegistrationType() == IL_REG_CODES || $this->code_was_used) { $this->userObj->setActive(1, 0); } else { if ($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION) { $this->userObj->setActive(0, 0); } else { $this->userObj->setActive(0, 0); } } $this->userObj->updateOwner(); // set a timestamp for last_password_change // this ts is needed by ilSecuritySettings $this->userObj->setLastPasswordChangeTS(time()); $this->userObj->setIsSelfRegistered(true); //insert user data in table user_data $this->userObj->saveAsNew(); try { require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceSignableDocumentFactory.php'; ilTermsOfServiceHelper::trackAcceptance($this->userObj, ilTermsOfServiceSignableDocumentFactory::getByLanguageObject($lng)); } catch (ilTermsOfServiceNoSignableDocumentFoundException $e) { } // setup user preferences $this->userObj->setLanguage($this->form->getInput('usr_language')); $hits_per_page = $ilSetting->get("hits_per_page"); if ($hits_per_page < 10) { $hits_per_page = 10; } $this->userObj->setPref("hits_per_page", $hits_per_page); $show_online = $ilSetting->get("show_users_online"); if ($show_online == "") { $show_online = "y"; } $this->userObj->setPref("show_users_online", $show_online); $this->userObj->writePrefs(); $rbacadmin->assignUser((int) $a_role, $this->userObj->getId()); // local roles from code if ($this->code_was_used && is_array($code_local_roles)) { foreach (array_unique($code_local_roles) as $local_role_obj_id) { // is given role (still) valid? if (ilObject::_lookupType($local_role_obj_id) == "role") { $rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId()); // patch to remove for 45 due to mantis 21953 $role_obj = $GLOBALS['rbacreview']->getObjectOfRole($local_role_obj_id); switch (ilObject::_lookupType($role_obj)) { case 'crs': case 'grp': $role_refs = ilObject::_getAllReferences($role_obj); $role_ref = end($role_refs); ilObjUser::_addDesktopItem($this->userObj->getId(), $role_ref, ilObject::_lookupType($role_obj)); break; } } } } return $password; }
/** * Update user account and role assignments * @return bool */ protected function performUpdate() { #$GLOBALS['ilLog']->write(__METHOD__.': '.print_r($this->getUserData(),true)); include_once './Services/User/classes/class.ilUserCreationContext.php'; ilUserCreationContext::getInstance()->addContext(ilUserCreationContext::CONTEXT_LDAP); include_once 'Services/LDAP/classes/class.ilLDAPAttributeToUser.php'; $update = new ilLDAPAttributeToUser($this->getServer()); $update->setNewUserAuthMode($this->getAuthMode()); $update->setUserData(array($this->getExternalAccount() => $this->getUserData())); $update->refresh(); // User has been created, now read internal account again $this->readInternalAccount(); return true; }