/** * Replace owner callback (preg_replace_callback) */ protected function replaceOwnerCallback($matches) { if (isset($matches[2])) { if ($usr_id = ilObjUser::_loginExists($matches[2])) { return $matches[1] . $usr_id; } } return $matches[0]; }
/** * Set consultation hour manager for current user * @param string $a_user_name * @return bool */ public static function setManager($a_user_name) { global $ilDB, $ilUser; $user_id = false; if ($a_user_name) { $user_id = ilObjUser::_loginExists($a_user_name); if (!$user_id) { return false; } } $ilDB->manipulate('DELETE FROM cal_ch_settings' . ' WHERE user_id = ' . $ilDB->quote($ilUser->getId(), 'integer')); if ($user_id && $user_id != $ilUser->getId()) { $ilDB->manipulate('INSERT INTO cal_ch_settings (user_id, admin_id)' . ' VALUES (' . $ilDB->quote($ilUser->getId(), 'integer') . ',' . $ilDB->quote($user_id, 'integer') . ')'); } return true; }
public function showResults() { global $lng, $ilUser, $rbacreview, $ilObjDataCache; $form = $this->initSearchForm(); $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_search.html", "Services/Contact"); $this->tpl->setVariable("ACTION", $this->ctrl->getFormAction($this)); $this->tpl->setTitle($this->lng->txt("mail")); $this->tpl->setVariable('SEARCHFORM', $form->getHtml()); // #14109 if (strlen($_SESSION['mail_search_search']) < 3) { if ($_GET["ref"] != "wsp") { $this->tpl->show(); } return; } $abook = new ilAddressbook($ilUser->getId()); $entries = $abook->searchUsers(addslashes(urldecode($_SESSION['mail_search_search']))); // remove all contacts who are not registered users for personal workspace if ($_GET["ref"] == "wsp") { foreach ($entries as $idx => $entry) { if (!$entry["login"]) { unset($entries[$idx]); } } } if (count($entries)) { $tbl_addr = new ilTable2GUI($this); $tbl_addr->setTitle($lng->txt('mail_addressbook')); $tbl_addr->setRowTemplate('tpl.mail_search_addr_row.html', 'Services/Contact'); $result = array(); $counter = 0; foreach ($entries as $entry) { if ($_GET["ref"] != "wsp") { $result[$counter]['check'] = ilUtil::formCheckbox(0, 'search_name_to_addr[]', $entry['login'] ? $entry['login'] : $entry['email']) . ilUtil::formCheckbox(0, 'search_name_cc[]', $entry['login'] ? $entry['login'] : $entry['email']) . ilUtil::formCheckbox(0, 'search_name_bcc[]', $entry['login'] ? $entry['login'] : $entry['email']); } else { $user_id = ilObjUser::_loginExists($entry["login"]); $result[$counter]['check'] = ilUtil::formCheckbox(0, 'search_name_to_addr[]', $user_id); } $result[$counter]['login'] = $entry['login']; $result[$counter]['firstname'] = $entry['firstname']; $result[$counter]['lastname'] = $entry['lastname']; $id = ilObjUser::_lookupId($entry['login']); if (ilObjUser::_lookupPref($id, 'public_email') == 'y' || !$entry['login']) { $has_mail_addr = true; $result[$counter]['email'] = $entry['email']; } ++$counter; } if ($_GET["ref"] != "wsp") { $tbl_addr->addColumn($this->lng->txt('mail_to') . '/' . $this->lng->txt('cc') . '/' . $this->lng->txt('bc'), 'check', '10%'); } else { $tbl_addr->addColumn("", "", "1%"); } $tbl_addr->addColumn($this->lng->txt('login'), 'login', "15%"); $tbl_addr->addColumn($this->lng->txt('firstname'), 'firstname', "15%"); $tbl_addr->addColumn($this->lng->txt('lastname'), 'lastname', "15%"); if ($has_mail_addr) { foreach ($result as $key => $val) { if ($val['email'] == '') { $result[$key]['email'] = ' '; } } $tbl_addr->addColumn($this->lng->txt('email'), 'email', "15%"); } $tbl_addr->setData($result); $tbl_addr->setDefaultOrderField('login'); $tbl_addr->setPrefix('addr_'); $tbl_addr->enable('select_all'); $tbl_addr->setSelectAllCheckbox('search_name_to_addr'); $tbl_addr->setFormName('recipients'); $this->tpl->setVariable('TABLE_ADDR', $tbl_addr->getHTML()); } include_once 'Services/Search/classes/class.ilQueryParser.php'; include_once 'Services/Search/classes/class.ilObjectSearchFactory.php'; include_once 'Services/Search/classes/class.ilSearchResult.php'; $all_results = new ilSearchResult(); $query_parser = new ilQueryParser(addcslashes($_SESSION['mail_search_search'], '%_')); $query_parser->setCombination(QP_COMBINATION_AND); $query_parser->setMinWordLength(3); $query_parser->parse(); $user_search =& ilObjectSearchFactory::_getUserSearchInstance($query_parser); $user_search->enableActiveCheck(true); $user_search->setFields(array('login')); $result_obj = $user_search->performSearch(); $all_results->mergeEntries($result_obj); $user_search->setFields(array('firstname')); $result_obj = $user_search->performSearch(); $all_results->mergeEntries($result_obj); $user_search->setFields(array('lastname')); $result_obj = $user_search->performSearch(); $all_results->mergeEntries($result_obj); $all_results->setMaxHits(100000); $all_results->preventOverwritingMaxhits(true); $all_results->filter(ROOT_FOLDER_ID, true); // Filter users (depends on setting in user accounts) include_once 'Services/User/classes/class.ilUserFilter.php'; $users = ilUserFilter::getInstance()->filter($all_results->getResultIds()); if (count($users)) { $tbl_users = new ilTable2GUI($this); $tbl_users->setTitle($lng->txt('system') . ': ' . $lng->txt('persons')); $tbl_users->setRowTemplate('tpl.mail_search_users_row.html', 'Services/Contact'); $result = array(); $counter = 0; foreach ($users as $user) { $login = ilObjUser::_lookupLogin($user); if ($_GET["ref"] != "wsp") { $result[$counter]['check'] = ilUtil::formCheckbox(0, 'search_name_to_usr[]', $login) . ilUtil::formCheckbox(0, 'search_name_cc[]', $login) . ilUtil::formCheckbox(0, 'search_name_bcc[]', $login); } else { $result[$counter]['check'] = ilUtil::formCheckbox(0, 'search_name_to_usr[]', $user); } $result[$counter]['login'] = $login; if (in_array(ilObjUser::_lookupPref($user, 'public_profile'), array('y', "g"))) { $name = ilObjUser::_lookupName($user); $result[$counter]['firstname'] = $name['firstname']; $result[$counter]['lastname'] = $name['lastname']; } else { $result[$counter]['firstname'] = ''; $result[$counter]['lastname'] = ''; } if (ilObjUser::_lookupPref($user, 'public_email') == 'y') { $has_mail_usr = true; $result[$counter]['email'] = ilObjUser::_lookupEmail($user); } ++$counter; } if ($_GET["ref"] != "wsp") { $tbl_users->addColumn($this->lng->txt('mail_to') . '/' . $this->lng->txt('cc') . '/' . $this->lng->txt('bc'), 'check', '10%'); } else { $tbl_users->addColumn("", "", "1%"); } $tbl_users->addColumn($this->lng->txt('login'), 'login', '15%'); $tbl_users->addColumn($this->lng->txt('firstname'), 'firstname', '15%'); $tbl_users->addColumn($this->lng->txt('lastname'), 'lastname', '15%'); if ($has_mail_usr == true) { foreach ($result as $key => $val) { if ($val['email'] == '') { $result[$key]['email'] = ' '; } } $tbl_users->addColumn($this->lng->txt('email'), 'email', '15%'); } $tbl_users->setData($result); $tbl_users->setDefaultOrderField('login'); $tbl_users->setPrefix('usr_'); $tbl_users->enable('select_all'); $tbl_users->setSelectAllCheckbox('search_name_to_usr'); $tbl_users->setFormName('recipients'); $this->tpl->setVariable('TABLE_USERS', $tbl_users->getHTML()); } include_once 'Services/Search/classes/class.ilQueryParser.php'; include_once 'Services/Search/classes/class.ilObjectSearchFactory.php'; include_once 'Services/Search/classes/class.ilSearchResult.php'; include_once 'Services/Membership/classes/class.ilParticipants.php'; $group_results = new ilSearchResult(); $query_parser = new ilQueryParser(addcslashes($_SESSION['mail_search_search'], '%_')); $query_parser->setCombination(QP_COMBINATION_AND); $query_parser->setMinWordLength(3); $query_parser->parse(); $search = ilObjectSearchFactory::_getObjectSearchInstance($query_parser); $search->setFilter(array('grp')); $result = $search->performSearch(); $group_results->mergeEntries($result); $group_results->setMaxHits(PHP_INT_MAX); $group_results->preventOverwritingMaxhits(true); $group_results->setRequiredPermission('read'); $group_results->filter(ROOT_FOLDER_ID, true); $visible_groups = array(); if ($group_results->getResults()) { $tbl_grp = new ilTable2GUI($this); $tbl_grp->setTitle($lng->txt('system') . ': ' . $lng->txt('groups')); $tbl_grp->setRowTemplate('tpl.mail_search_groups_row.html', 'Services/Contact'); $result = array(); $counter = 0; $ilObjDataCache->preloadReferenceCache(array_keys($group_results->getResults())); $groups = $group_results->getResults(); foreach ($groups as $grp) { if (!ilParticipants::hasParticipantListAccess($grp['obj_id'])) { continue; } if ($_GET["ref"] != "wsp") { $members = array(); $roles = $rbacreview->getAssignableChildRoles($grp['ref_id']); foreach ($roles as $role) { if (substr($role['title'], 0, 14) == 'il_grp_member_' || substr($role['title'], 0, 13) == 'il_grp_admin_') { // does not work if Pear is enabled and Mailbox Address contain special chars!! //array_push($members, $rbacreview->getRoleMailboxAddress($role['obj_id'])); // FIX for Mantis: 7523 array_push($members, '#' . $role['title']); } } $str_members = implode(',', $members); $result[$counter]['check'] = ilUtil::formCheckbox(0, 'search_name_to_grp[]', $str_members) . ilUtil::formCheckbox(0, 'search_name_cc[]', $str_members) . ilUtil::formCheckbox(0, 'search_name_bcc[]', $str_members); } else { $result[$counter]['check'] = ilUtil::formCheckbox(0, 'search_name_to_grp[]', $grp['obj_id']); } $result[$counter]['title'] = $ilObjDataCache->lookupTitle($grp['obj_id']); $result[$counter]['description'] = $ilObjDataCache->lookupDescription($grp['obj_id']); ++$counter; $visible_groups[] = $grp; } if ($visible_groups) { $tbl_grp->setData($result); if ($_GET["ref"] != "wsp") { $tbl_grp->addColumn($this->lng->txt('mail_to') . '/' . $this->lng->txt('cc') . '/' . $this->lng->txt('bc'), 'check', '10%'); } else { $tbl_grp->addColumn("", "", "1%"); } $tbl_grp->addColumn($this->lng->txt('title'), 'title', '15%'); $tbl_grp->addColumn($this->lng->txt('description'), 'description', '15%'); $tbl_grp->setDefaultOrderField('title'); $tbl_grp->setPrefix('grp_'); $tbl_grp->enable('select_all'); $tbl_grp->setSelectAllCheckbox('search_name_to_grp'); $tbl_grp->setFormName('recipients'); $this->tpl->setVariable('TABLE_GRP', $tbl_grp->getHTML()); } } if (count($users) || count($visible_groups) || count($entries)) { $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.svg")); $this->tpl->setVariable("ALT_ARROW", ''); if ($_GET["ref"] != "wsp") { $this->tpl->setVariable('BUTTON_ADOPT', $this->lng->txt('adopt')); } else { $this->tpl->setVariable('BUTTON_ADOPT', $this->lng->txt('wsp_share_with_users')); } } else { $this->lng->loadLanguageModule('search'); ilUtil::sendInfo($this->lng->txt('search_no_match')); } if ($_GET["ref"] != "wsp") { $this->tpl->show(); } }
/** * Note: This function can only be used, when ILIAS is configured to not * use standards compliant mail addresses. * If standards compliant mail addresses are used, substitution is * not supported, because then we do the parsing of mail addresses * using the Pear Mail Extension. */ function __substituteRecipients($a_rcp, $direction) { $new_name = array(); $tmp_names = $this->explodeRecipients($a_rcp); foreach ($tmp_names as $name) { if (strpos($name, "#") === 0) { $new_name[] = $name; continue; } switch ($direction) { case "substitute": if (strpos($name, "@") and ilObjUser::_loginExists($name)) { $new_name[] = preg_replace("/@/", "�#�", $name); } else { $new_name[] = $name; } break; case "resubstitute": if (stristr($name, "�#�")) { $new_name[] = preg_replace("/�#�/", "@", $name); } else { $new_name[] = $name; } break; } } return implode(",", $new_name); }
/** * Creates a user, sets preferences, lookups data, delete user * @group IL_Init */ public function testCreateSetLookupDelete() { include_once "./Services/User/classes/class.ilObjUser.php"; // delete all aatestuser from previous runs while (($i = ilObjUser::_lookupId("aatestuser")) > 0) { $user = new ilObjUser($i); $user->delete(); } $user = new ilObjUser(); // creation $d = array("login" => "aatestuser", "passwd_type" => IL_PASSWD_PLAIN, "passwd" => "password", "gender" => "m", "firstname" => "Max", "lastname" => "Mutzke", "email" => "*****@*****.**", "client_ip" => "1.2.3.4", "ext_account" => "ext_mutzke"); $user->assignData($d); $user->create(); $user->saveAsNew(); $user->setLanguage("no"); $user->writePrefs(); $id = $user->getId(); $value .= $user->getFirstname() . "-"; // update $user->setFirstname("Maxi"); $user->update(); $value .= $user->getFirstname() . "-"; // other update methods $user->refreshLogin(); // lookups $value .= ilObjUser::_lookupEmail($id) . "-"; $value .= ilObjUser::_lookupGender($id) . "-"; $value .= ilObjUser::_lookupClientIP($id) . "-"; $n = ilObjUser::_lookupName($id); $value .= $n["lastname"] . "-"; ilObjUser::_lookupFields($id); $value .= ilObjUser::_lookupLogin($id) . "-"; $value .= ilObjUser::_lookupExternalAccount($id) . "-"; $value .= ilObjUser::_lookupId("aatestuser") . "-"; ilObjUser::_lookupLastLogin($id); $value .= ilObjUser::_lookupLanguage($id) . "-"; ilObjUser::_readUsersProfileData(array($id)); if (ilObjUser::_loginExists("aatestuser")) { $value .= "le-"; } // preferences... $user->writePref("testpref", "pref1"); $value .= ilObjUser::_lookupPref($id, "testpref") . "-"; $user->deletePref("testpref"); if (ilObjUser::_lookupPref($id, "testpref") == "") { $value .= "pref2" . "-"; } // activation $user->setActive(false); if (!ilObjUser::getStoredActive($id)) { } $value .= "act1-"; $user->setActive(true); if (ilObjUser::getStoredActive($id)) { } $value .= "act2-"; ilObjUser::_toggleActiveStatusOfUsers(array($id), false); if (!ilObjUser::getStoredActive($id)) { } $value .= "act3-"; // deletion $user->delete(); $this->assertEquals("Max-Maxi-de@de.de-m-1.2.3.4-Mutzke-aatestuser-ext_mutzke-{$id}-no-le-" . "pref1-pref2-act1-act2-act3-", $value); }
protected function loadNotificationRecipients() { $this->notification->setRecipients(array()); foreach ((array) $_POST['notu'] as $rcp) { $rcp = trim(ilUtil::stripSlashes($rcp)); $usr_id = ilObjUser::_loginExists($rcp); if (strlen($rcp) == 0) { continue; } if ($usr_id) { $this->notification->addRecipient(ilCalendarUserNotification::TYPE_USER, $usr_id); } else { $this->notification->addRecipient(ilCalendarUserNotification::TYPE_EMAIL, 0, $rcp); } } }
/** * Save personal data form * */ public function savePersonalData() { global $tpl, $lng, $ilCtrl, $ilUser, $ilSetting, $ilAuth; $this->initPersonalDataForm(); if ($this->form->checkInput()) { $form_valid = true; // if form field name differs from setter $map = array("firstname" => "FirstName", "lastname" => "LastName", "title" => "UTitle", "sel_country" => "SelectedCountry", "phone_office" => "PhoneOffice", "phone_home" => "PhoneHome", "phone_mobile" => "PhoneMobile", "referral_comment" => "Comment", "interests_general" => "GeneralInterests", "interests_help_offered" => "OfferingHelp", "interests_help_looking" => "LookingForHelp"); include_once "./Services/User/classes/class.ilUserProfile.php"; $up = new ilUserProfile(); foreach ($up->getStandardFields() as $f => $p) { // if item is part of form, it is currently valid (if not disabled) $item = $this->form->getItemByPostVar("usr_" . $f); if ($item && !$item->getDisabled()) { $value = $this->form->getInput("usr_" . $f); switch ($f) { case "birthday": if (is_array($value)) { if (is_array($value['date'])) { if ($value['d'] > 0 && $value['m'] > 0 && $value['y'] > 0) { $ilUser->setBirthday(sprintf("%04d-%02d-%02d", $value['y'], $value['m'], $value['d'])); } else { $ilUser->setBirthday(""); } } else { $ilUser->setBirthday($value['date']); } } break; default: $m = ucfirst($f); if (isset($map[$f])) { $m = $map[$f]; } $ilUser->{"set" . $m}($value); break; } } } $ilUser->setFullname(); // set instant messengers if ($this->workWithUserSetting("instant_messengers")) { $ilUser->setInstantMessengerId('icq', $this->form->getInput("usr_im_icq")); $ilUser->setInstantMessengerId('yahoo', $this->form->getInput("usr_im_yahoo")); $ilUser->setInstantMessengerId('msn', $this->form->getInput("usr_im_msn")); $ilUser->setInstantMessengerId('aim', $this->form->getInput("usr_im_aim")); $ilUser->setInstantMessengerId('skype', $this->form->getInput("usr_im_skype")); $ilUser->setInstantMessengerId('jabber', $this->form->getInput("usr_im_jabber")); $ilUser->setInstantMessengerId('voip', $this->form->getInput("usr_im_voip")); } // check map activation include_once "./Services/Maps/classes/class.ilMapUtil.php"; if (ilMapUtil::isActivated()) { $location = $this->form->getInput("location"); $ilUser->setLatitude(ilUtil::stripSlashes($location["latitude"])); $ilUser->setLongitude(ilUtil::stripSlashes($location["longitude"])); $ilUser->setLocationZoom(ilUtil::stripSlashes($location["zoom"])); } // Set user defined data $defs = $this->user_defined_fields->getVisibleDefinitions(); $udf = array(); foreach ($defs as $definition) { $f = "udf_" . $definition['field_id']; $item = $this->form->getItemByPostVar($f); if ($item && !$item->getDisabled()) { $udf[$definition['field_id']] = $this->form->getInput($f); } } $ilUser->setUserDefinedData($udf); // if loginname is changeable -> validate $un = $this->form->getInput('username'); if ((int) $ilSetting->get('allow_change_loginname') && $un != $ilUser->getLogin()) { if (!strlen($un) || !ilUtil::isLogin($un)) { ilUtil::sendFailure($lng->txt('form_input_not_valid')); $this->form->getItemByPostVar('username')->setAlert($this->lng->txt('login_invalid')); $form_valid = false; } else { if (ilObjUser::_loginExists($un, $ilUser->getId())) { ilUtil::sendFailure($lng->txt('form_input_not_valid')); $this->form->getItemByPostVar('username')->setAlert($this->lng->txt('loginname_already_exists')); $form_valid = false; } else { $ilUser->setLogin($un); try { $ilUser->updateLogin($ilUser->getLogin()); $ilAuth->setAuth($ilUser->getLogin()); $ilAuth->start(); } catch (ilUserException $e) { ilUtil::sendFailure($lng->txt('form_input_not_valid')); $this->form->getItemByPostVar('username')->setAlert($e->getMessage()); $form_valid = false; } } } } // everthing's ok. save form data if ($form_valid) { $this->uploadUserPicture(); // profile ok $ilUser->setProfileIncomplete(false); // save user data & object_data $ilUser->setTitle($ilUser->getFullname()); $ilUser->setDescription($ilUser->getEmail()); $ilUser->update(); ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true); if (ilSession::get('orig_request_target')) { $target = ilSession::get('orig_request_target'); ilSession::set('orig_request_target', ''); ilUtil::redirect($target); } else { if ($redirect = $_SESSION['profile_complete_redirect']) { unset($_SESSION['profile_complete_redirect']); ilUtil::redirect($redirect); } else { $ilCtrl->redirect($this, "showPersonalData"); } } } } $this->form->setValuesByPost(); $this->showPersonalData(true); }
/** * Called after successful login * @return * @param array $a_username * @param object $a_auth */ protected function loginObserver($a_username, $a_auth) { global $ilLog, $ilAppEventHandler, $ilSetting; if ($this->getContainer()->loginObserver($a_username, $a_auth)) { // validate user include_once "Services/User/classes/class.ilObjUser.php"; $user_id = ilObjUser::_loginExists($a_auth->getUsername()); if ($user_id != ANONYMOUS_USER_ID) { $user = new ilObjUser($user_id); // check if profile is complete include_once "Services/User/classes/class.ilUserProfile.php"; if (ilUserProfile::isProfileIncomplete($user) and ilAuthFactory::getContext() != ilAuthFactory::CONTEXT_ECS) { $user->setProfileIncomplete(true); $user->update(); } // --- extended user validation // // we only have a single status, so abort after each one // order from highest priority to lowest // active? if (!$user->getActive()) { $this->status = AUTH_USER_INACTIVE; $a_auth->logout(); return; } // time limit if (!$user->checkTimeLimit()) { $this->status = AUTH_USER_TIME_LIMIT_EXCEEDED; // #16327 $this->exceeded_user_name = $this->getUserName(); $a_auth->logout(); return; } // check client ip $clientip = $user->getClientIP(); if (trim($clientip) != "") { $clientip = preg_replace("/[^0-9.?*,:]+/", "", $clientip); $clientip = str_replace(".", "\\.", $clientip); $clientip = str_replace(array("?", "*", ","), array("[0-9]", "[0-9]*", "|"), $clientip); if (!preg_match("/^" . $clientip . "\$/", $_SERVER["REMOTE_ADDR"])) { $this->status = AUTH_USER_WRONG_IP; $a_auth->logout(); return; } } // simultaneous login if ($ilSetting->get('ps_prevent_simultaneous_logins') && ilObjUser::hasActiveSession($user_id)) { $this->status = AUTH_USER_SIMULTANEOUS_LOGIN; $a_auth->logout(); return; } include_once 'Services/Tracking/classes/class.ilOnlineTracking.php'; ilOnlineTracking::addUser($user_id); include_once 'Modules/Forum/classes/class.ilObjForum.php'; ilObjForum::_updateOldAccess($user_id); require_once 'Services/PrivacySecurity/classes/class.ilSecuritySettings.php'; $security_settings = ilSecuritySettings::_getInstance(); // determine first login of user for setting an indicator // which still is available in PersonalDesktop, Repository, ... // (last login date is set to current date in next step) if ($security_settings->isPasswordChangeOnFirstLoginEnabled() && $user->getLastLogin() == null) { $user->resetLastPasswordChange(); } $user->refreshLogin(); // reset counter for failed logins ilObjUser::_resetLoginAttempts($user_id); } // --- anonymous/registered user $ilLog->write(__METHOD__ . ': logged in as ' . $a_auth->getUsername() . ', remote:' . $_SERVER['REMOTE_ADDR'] . ':' . $_SERVER['REMOTE_PORT'] . ', server:' . $_SERVER['SERVER_ADDR'] . ':' . $_SERVER['SERVER_PORT']); ilSessionControl::handleLoginEvent($a_auth->getUsername(), $a_auth); $ilAppEventHandler->raise('Services/Authentication', 'afterLogin', array('username' => $a_auth->getUsername())); } }
public function saveForm() { global $lng, $ilSetting; $this->__initForm(); $form_valid = $this->form->checkInput(); require_once 'Services/User/classes/class.ilObjUser.php'; // custom validation // validate email against restricted domains $email = $this->form->getInput("usr_email"); if ($email) { // #10366 $domains = array(); foreach ($this->registration_settings->getAllowedDomains() as $item) { if (trim($item)) { $domains[] = $item; } } if (sizeof($domains)) { $mail_valid = false; foreach ($domains as $domain) { $domain = str_replace("*", "~~~", $domain); $domain = preg_quote($domain); $domain = str_replace("~~~", ".+", $domain); if (preg_match("/^" . $domain . "\$/", $email, $hit)) { $mail_valid = true; break; } } if (!$mail_valid) { $mail_obj = $this->form->getItemByPostVar('usr_email'); $mail_obj->setAlert(sprintf($lng->txt("reg_email_domains"), implode(", ", $domains))); $form_valid = false; } } } if (!$this->form->getInput("usr_agreement")) { $agr_obj = $this->form->getItemByPostVar('usr_agreement'); $agr_obj->setAlert($lng->txt("force_accept_usr_agreement")); $form_valid = false; } $valid_role = false; // code if ($this->code_enabled) { $code = $this->form->getInput('usr_registration_code'); // could be optional if ($code) { // code validation include_once './Services/Registration/classes/class.ilRegistrationCode.php'; if (!ilRegistrationCode::isUnusedCode($code)) { $code_obj = $this->form->getItemByPostVar('usr_registration_code'); $code_obj->setAlert($lng->txt('registration_code_not_valid')); $form_valid = false; } else { // get role from valid code $valid_role = (int) ilRegistrationCode::getCodeRole($code); } } } // no need if role is attached to code if (!$valid_role) { // manual selection if ($this->registration_settings->roleSelectionEnabled()) { include_once "./Services/AccessControl/classes/class.ilObjRole.php"; $selected_role = $this->form->getInput("usr_roles"); if ($selected_role && ilObjRole::_lookupAllowRegister($selected_role)) { $valid_role = (int) $selected_role; } } else { include_once 'Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.php'; $registration_role_assignments = new ilRegistrationRoleAssignments(); $valid_role = (int) $registration_role_assignments->getRoleByEmail($this->form->getInput("usr_email")); } } // no valid role could be determined if (!$valid_role) { ilUtil::sendInfo($lng->txt("registration_no_valid_role")); $form_valid = false; } // validate username $login_obj = $this->form->getItemByPostVar('username'); $login = $this->form->getInput("username"); if (!ilUtil::isLogin($login)) { $login_obj->setAlert($lng->txt("login_invalid")); $form_valid = false; } else { if (ilObjUser::_loginExists($login)) { $login_obj->setAlert($lng->txt("login_exists")); $form_valid = false; } else { if ((int) $ilSetting->get('allow_change_loginname') && (int) $ilSetting->get('reuse_of_loginnames') == 0 && ilObjUser::_doesLoginnameExistInHistory($login)) { $login_obj->setAlert($lng->txt('login_exists')); $form_valid = false; } } } if (!$form_valid) { ilUtil::sendFailure($lng->txt('form_input_not_valid')); } else { $password = $this->__createUser($valid_role); $this->__distributeMails($password, $this->form->getInput("usr_language")); $this->login($password); return true; } $this->form->setValuesByPost(); $this->displayForm(); return false; }
function __validateUserData(&$user_data, $check_complete = true) { global $lng, $styleDefinition, $ilLog; $this->__setMessage(''); include_once './Services/Authentication/classes/class.ilAuthUtils.php'; $allow_empty_password = ilAuthUtils::_needsExternalAccountByAuthMode(ilAuthUtils::_getAuthMode($user_data['auth_mode'])); if ($check_complete) { if (!isset($user_data['login'])) { $this->__appendMessage('No login given.'); } if (!isset($user_data['passwd']) and !$allow_empty_password) { $this->__appendMessage('No password given.'); } if (!isset($user_data['email'])) { $this->__appendMessage('No email given'); } if (!isset($user_data['user_language'])) { $user_data['user_language'] = $lng->getDefaultLanguage(); } } foreach ($user_data as $field => $value) { switch ($field) { case 'login': if (!ilUtil::isLogin($value)) { $this->__appendMessage('Login invalid.'); } // check loginname if ($check_complete) { if (ilObjUser::_loginExists($value)) { $this->__appendMessage('Login already exists.'); } } break; case 'passwd': if (!strlen($value) and $allow_empty_password) { break; } if (!ilUtil::isPassword($value)) { $this->__appendMessage('Password invalid.'); } break; case 'email': if (!ilUtil::is_email($value)) { $this->__appendMessage('Email invalid.'); } break; case 'time_limit_unlimited': if ($value != 1) { if ($user_data['time_limit_from'] >= $user_data['time_limit_until']) { $this->__appendMessage('Time limit invalid'); } } break; case 'user_language': $lang_inst = $lng->getInstalledLanguages(); if (!in_array($user_data['user_language'], $lang_inst)) { $this->__appendMessage('Language: ' . $user_data['user_language'] . ' is not installed'); } break; case 'user_skin': case 'user_style': if ($user_data['user_skin'] and !$user_data['user_style'] or !$user_data['user_skin'] and $user_data['user_style']) { $this->__appendMessage('user_skin, user_style not valid.'); } elseif ($user_data['user_skin'] and $user_data['user_style']) { $ok = false; $templates = $styleDefinition->getAllTemplates(); if (count($templates) > 0 && is_array($templates)) { foreach ($templates as $template) { $styleDef =& new ilStyleDefinition($template["id"]); $styleDef->startParsing(); $styles = $styleDef->getStyles(); foreach ($styles as $style) { if ($user_data['user_skin'] == $template["id"] && $user_data['user_style'] == $style["id"]) { $ok = true; } } } if (!$ok) { $this->__appendMessage('user_skin, user_style not valid.'); } } } break; case 'time_limit_owner': $type = ilObject::_lookupType($user_data['time_limit_owner'], true); if ($type != 'cat' and $type != 'usrf') { $this->__appendMessage('time_limit_owner must be ref_id of category or user folder' . $type); } break; default: continue; } } return strlen($this->__getMessage()) ? false : true; }
/** * Does input checks and updates a user account if everything is fine. * @access public */ function updateObjectOld() { global $ilias, $rbacsystem, $rbacadmin, $ilUser; include_once './Services/Authentication/classes/class.ilAuthUtils.php'; //load ILIAS settings $settings = $ilias->getAllSettings(); // User folder if ($this->usrf_ref_id == USER_FOLDER_ID and !$rbacsystem->checkAccess('visible,read,write', $this->usrf_ref_id)) { $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_user"), $this->ilias->error_obj->MESSAGE); } // if called from local administration $this->usrf_ref_id is category id // Todo: this has to be fixed. Do not mix user folder id and category id if ($this->usrf_ref_id != USER_FOLDER_ID) { // check if user is assigned to category if (!$rbacsystem->checkAccess('cat_administrate_users', $this->object->getTimeLimitOwner())) { $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_user"), $this->ilias->error_obj->MESSAGE); } } foreach ($_POST["Fobject"] as $key => $val) { $_POST["Fobject"][$key] = ilUtil::stripSlashes($val); } // check dynamically required fields foreach ($settings as $key => $val) { $field = substr($key, 8); switch ($field) { case 'passwd': case 'passwd2': if (ilAuthUtils::_allowPasswordModificationByAuthMode(ilAuthUtils::_getAuthMode($_POST['Fobject']['auth_mode']))) { $require_keys[] = $field; } break; default: $require_keys[] = $field; break; } } foreach ($require_keys as $key => $val) { // exclude required system and registration-only fields $system_fields = array("default_role"); if (!in_array($val, $system_fields)) { if (isset($settings["require_" . $val]) && $settings["require_" . $val]) { if (empty($_POST["Fobject"][$val])) { $this->ilias->raiseError($this->lng->txt("fill_out_all_required_fields") . ": " . $this->lng->txt($val), $this->ilias->error_obj->MESSAGE); } } } } if (!$this->__checkUserDefinedRequiredFields()) { $this->ilias->raiseError($this->lng->txt("fill_out_all_required_fields"), $this->ilias->error_obj->MESSAGE); } // validate login if ($this->object->getLogin() != $_POST["Fobject"]["login"] && !ilUtil::isLogin($_POST["Fobject"]["login"])) { $this->ilias->raiseError($this->lng->txt("login_invalid"), $this->ilias->error_obj->MESSAGE); } // check loginname if (ilObjUser::_loginExists($_POST["Fobject"]["login"], $this->id)) { $this->ilias->raiseError($this->lng->txt("login_exists"), $this->ilias->error_obj->MESSAGE); } if (ilAuthUtils::_allowPasswordModificationByAuthMode(ilAuthUtils::_getAuthMode($_POST['Fobject']['auth_mode']))) { if ($_POST['Fobject']['passwd'] == "********" and !strlen($this->object->getPasswd())) { $this->ilias->raiseError($this->lng->txt("fill_out_all_required_fields") . ": " . $this->lng->txt('password'), $this->ilias->error_obj->MESSAGE); } // check passwords if ($_POST["Fobject"]["passwd"] != $_POST["Fobject"]["passwd2"]) { $this->ilias->raiseError($this->lng->txt("passwd_not_match"), $this->ilias->error_obj->MESSAGE); } // validate password if (!ilUtil::isPassword($_POST["Fobject"]["passwd"])) { $this->ilias->raiseError($this->lng->txt("passwd_invalid"), $this->ilias->error_obj->MESSAGE); } } else { // Password will not be changed... $_POST['Fobject']['passwd'] = "********"; } if (ilAuthUtils::_needsExternalAccountByAuthMode(ilAuthUtils::_getAuthMode($_POST['Fobject']['auth_mode']))) { if (!strlen($_POST['Fobject']['ext_account'])) { $this->ilias->raiseError($this->lng->txt('ext_acccount_required'), $this->ilias->error_obj->MESSAGE); } } if ($_POST['Fobject']['ext_account'] && ($elogin = ilObjUser::_checkExternalAuthAccount($_POST['Fobject']['auth_mode'], $_POST['Fobject']['ext_account']))) { if ($elogin != $this->object->getLogin()) { $this->ilias->raiseError(sprintf($this->lng->txt("err_auth_ext_user_exists"), $_POST["Fobject"]["ext_account"], $_POST['Fobject']['auth_mode'], $elogin), $this->ilias->error_obj->MESSAGE); } } // The password type is not passed with the post data. Therefore we // append it here manually. include_once './Services/User/classes/class.ilObjUser.php'; $_POST["Fobject"]["passwd_type"] = IL_PASSWD_PLAIN; // validate email if (strlen($_POST['Fobject']['email']) and !ilUtil::is_email($_POST["Fobject"]["email"])) { $this->ilias->raiseError($this->lng->txt("email_not_valid"), $this->ilias->error_obj->MESSAGE); } $start = $this->__toUnix($_POST["time_limit"]["from"]); $end = $this->__toUnix($_POST["time_limit"]["until"]); // validate time limit if (!$_POST["time_limit"]["unlimited"] and $start > $end) { $this->ilias->raiseError($this->lng->txt("time_limit_not_valid"), $this->ilias->error_obj->MESSAGE); } if (!$this->ilias->account->getTimeLimitUnlimited()) { if ($start < $this->ilias->account->getTimeLimitFrom() or $end > $this->ilias->account->getTimeLimitUntil() or $_POST['time_limit']['unlimited']) { $_SESSION['error_post_vars'] = $_POST; ilUtil::sendFailure($this->lng->txt('time_limit_not_within_owners')); $this->editObject(); return false; } } // TODO: check length of login and passwd // checks passed. save user $_POST['Fobject']['time_limit_owner'] = $this->object->getTimeLimitOwner(); $_POST['Fobject']['time_limit_unlimited'] = (int) $_POST['time_limit']['unlimited']; $_POST['Fobject']['time_limit_from'] = $this->__toUnix($_POST['time_limit']['from']); $_POST['Fobject']['time_limit_until'] = $this->__toUnix($_POST['time_limit']['until']); if ($_POST['Fobject']['time_limit_unlimited'] != $this->object->getTimeLimitUnlimited() or $_POST['Fobject']['time_limit_from'] != $this->object->getTimeLimitFrom() or $_POST['Fobject']['time_limit_until'] != $this->object->getTimeLimitUntil()) { $_POST['Fobject']['time_limit_message'] = 0; } else { $_POST['Fobject']['time_limit_message'] = $this->object->getTimeLimitMessage(); } $this->object->assignData($_POST["Fobject"]); $this->object->setUserDefinedData($_POST['udf']); try { $this->object->updateLogin($_POST['Fobject']['login']); } catch (ilUserException $e) { ilUtil::sendFailure($e->getMessage()); $this->form_gui->setValuesByPost(); return $tpl->setContent($this->form_gui->getHtml()); } $this->object->setTitle($this->object->getFullname()); $this->object->setDescription($this->object->getEmail()); $this->object->setLanguage($_POST["Fobject"]["language"]); //set user skin and style $sknst = explode(":", $_POST["Fobject"]["skin_style"]); if ($this->object->getPref("style") != $sknst[1] || $this->object->getPref("skin") != $sknst[0]) { $this->object->setPref("skin", $sknst[0]); $this->object->setPref("style", $sknst[1]); } // set hits per pages $this->object->setPref("hits_per_page", $_POST["Fobject"]["hits_per_page"]); // set show users online $this->object->setPref("show_users_online", $_POST["Fobject"]["show_users_online"]); // set hide_own_online_status if ($_POST["Fobject"]["hide_own_online_status"]) { $this->object->setPref("hide_own_online_status", $_POST["Fobject"]["hide_own_online_status"]); } else { $this->object->setPref("hide_own_online_status", "n"); } $this->update = $this->object->update(); //$rbacadmin->updateDefaultRole($_POST["Fobject"]["default_role"], $this->object->getId()); // BEGIN DiskQuota: Remember the state of the "send info mail" checkbox global $ilUser; $ilUser->setPref('send_info_mails', $_POST['send_mail'] == 'y' ? 'y' : 'n'); $ilUser->writePrefs(); // END DiskQuota: Remember the state of the "send info mail" checkbox $mail_message = $this->__sendProfileMail(); $msg = $this->lng->txt('saved_successfully') . $mail_message; // feedback ilUtil::sendSuccess($msg, true); if (strtolower($_GET["baseClass"]) == 'iladministrationgui') { $this->ctrl->redirectByClass("ilobjuserfoldergui", "view"); } else { $this->ctrl->redirectByClass('ilobjcategorygui', 'listUsers'); } }
/** * Check input, strip slashes etc. set alert, if input is not ok. * * @return boolean Input ok, true/false */ function checkInput() { global $lng; $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]); if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "") { $this->setAlert($lng->txt("msg_input_is_required")); return false; } if (!ilUtil::isLogin($_POST[$this->getPostVar()])) { $this->setAlert($lng->txt("login_invalid")); return false; } if (ilObjUser::_loginExists($_POST[$this->getPostVar()], $this->getCurrentUserId())) { $this->setAlert($lng->txt("login_exists")); return false; } return true; }
/** * @param string $raw * @param string $encoded * @param string string $cryptType * @return bool */ public function verifyPassword($raw, $encoded, $crypt_type = 'md5') { $this->log(__METHOD__ . ' called.', AUTH_LOG_DEBUG); if (in_array($crypt_type, array('none', ''))) { return parent::verifyPassword($raw, $encoded, $crypt_type); } require_once 'Services/User/classes/class.ilUserPasswordManager.php'; $crypt_type = ilUserPasswordManager::getInstance()->getEncoderName(); if (ilUserPasswordManager::getInstance()->isEncodingTypeSupported($crypt_type)) { /** * @var $user ilObjUser */ $user = ilObjectFactory::getInstanceByObjId(ilObjUser::_loginExists($this->_auth_obj->username)); $user->setPasswd($encoded, IL_PASSWD_CRYPTED); return ilUserPasswordManager::getInstance()->verifyPassword($user, $raw); } // Fall through: Let pear verify the password return parent::verifyPassword($raw, $encoded, $crypt_type); }