public static function _createRandomUserAccount($keyarray) { global $ilDB, $ilUser, $ilSetting, $rbacadmin; if ($_SESSION['create_user_account'] != NULL) { $obj_user = new ilObjUser($_SESSION['create_user_account']); return $obj_user; } else { $userLogin = array(); $res = $ilDB->query('SELECT sequence FROM object_data_seq'); $row = $ilDB->fetchAssoc($res); $temp_user_id = (int) $row['sequence'] + 1; $userLogin['login'] = '******' . $temp_user_id; $userLogin['passwd'] = ilUtil::generatePasswords(1); require_once 'Services/User/classes/class.ilObjUser.php'; include_once "Services/Mail/classes/class.ilAccountMail.php"; $obj_user = new ilObjUser(); $obj_user->setId($temp_user_id); $obj_user->setLogin($userLogin['login']); $obj_user->setPasswd((string) $userLogin['passwd'][0], IL_PASSWD_PLAIN); $_SESSION['tmp_user_account']['login'] = $userLogin['login']; $_SESSION['tmp_user_account']['passwd'] = $userLogin['passwd']; $obj_user->setFirstname($keyarray['first_name']); $obj_user->setLastname($keyarray['last_name']); $obj_user->setEmail($keyarray['payer_email']); # $obj_user->setEmail('*****@*****.**'); $obj_user->setGender('f'); $obj_user->setLanguage($ilSetting->get("language")); $obj_user->setActive(true); $obj_user->setTimeLimitUnlimited(true); $obj_user->setTitle($obj_user->getFullname()); $obj_user->setDescription($obj_user->getEmail()); $obj_user->setTimeLimitOwner(7); $obj_user->setTimeLimitUnlimited(1); $obj_user->setTimeLimitMessage(0); $obj_user->setApproveDate(date("Y-m-d H:i:s")); // Set default prefs $obj_user->setPref('hits_per_page', $ilSetting->get('hits_per_page', 30)); $obj_user->setPref('show_users_online', $ilSetting->get('show_users_online', 'y')); $obj_user->writePrefs(); // at the first login the user must complete profile $obj_user->setProfileIncomplete(true); $obj_user->create(); $obj_user->saveAsNew(); $user_role = ilObject::_exists(4, false); if (!$user_role) { include_once "./Services/AccessControl/classes/class.ilObjRole.php"; $reg_allowed = ilObjRole::_lookupRegisterAllowed(); $user_role = $reg_allowed[0]['id']; } else { $user_role = 4; } $rbacadmin->assignUser((int) $user_role, $obj_user->getId(), true); include_once "Services/Mail/classes/class.ilMimeMail.php"; global $ilias, $lng; $settings = $ilias->getAllSettings(); $mmail = new ilMimeMail(); $mmail->autoCheck(false); $mmail->From($settings["admin_email"]); $mmail->To($obj_user->getEmail()); // mail subject $subject = $lng->txt("reg_mail_subject"); // mail body $body = $lng->txt("reg_mail_body_salutation") . " " . $obj_user->getFullname() . ",\n\n" . $lng->txt("reg_mail_body_text1") . "\n\n" . $lng->txt("reg_mail_body_text2") . "\n" . ILIAS_HTTP_PATH . "/login.php?client_id=" . $ilias->client_id . "\n"; $body .= $lng->txt("login") . ": " . $obj_user->getLogin() . "\n"; $body .= $lng->txt("passwd") . ": " . $userLogin['passwd'][0] . "\n"; $body .= "\n"; $body .= $lng->txt("reg_mail_body_text3") . "\n\r"; $body .= $obj_user->getProfileAsString($lng); $mmail->Subject($subject); $mmail->Body($body); $mmail->Send(); $_SESSION['create_user_account'] = $obj_user->getId(); return $obj_user; } }
public function confirmRegistration() { global $lng, $ilias, $ilLog; ilUtil::setCookie('iltest', 'cookie', false); if (!isset($_GET['rh']) || !strlen(trim($_GET['rh']))) { ilUtil::redirect('./login.php?cmd=force_login®_confirmation_msg=reg_confirmation_hash_not_passed'); } try { require_once 'Services/Registration/classes/class.ilRegistrationSettings.php'; $oRegSettings = new ilRegistrationSettings(); $usr_id = ilObjUser::_verifyRegistrationHash(trim($_GET['rh'])); $oUser = ilObjectFactory::getInstanceByObjId($usr_id); $oUser->setActive(true); if ($oRegSettings->passwordGenerationEnabled()) { $passwd = ilUtil::generatePasswords(1); $password = $passwd[0]; $oUser->setPasswd($password, IL_PASSWD_PLAIN); $oUser->setLastPasswordChangeTS(time()); } $oUser->update(); $usr_lang = $oUser->getPref('language'); if ($lng->getLangKey() != $usr_lang) { $lng = new ilLanguage($usr_lang); } // send email // try individual account mail in user administration include_once "Services/Mail/classes/class.ilAccountMail.php"; include_once './Services/User/classes/class.ilObjUserFolder.php'; $amail = ilObjUserFolder::_lookupNewAccountMail($usr_lang); if (trim($amail["body"]) != "" && trim($amail["subject"]) != "") { $acc_mail = new ilAccountMail(); $acc_mail->setUser($oUser); if ($oRegSettings->passwordGenerationEnabled()) { $acc_mail->setUserPassword($password); } $acc_mail->send(); } else { include_once 'Services/Mail/classes/class.ilMail.php'; $mail_obj = new ilMail(ANONYMOUS_USER_ID); // mail subject $subject = $lng->txt("reg_mail_subject"); // mail body $body = $lng->txt("reg_mail_body_salutation") . " " . $oUser->getFullname() . ",\n\n" . $lng->txt("reg_mail_body_text1") . "\n\n" . $lng->txt("reg_mail_body_text2") . "\n" . ILIAS_HTTP_PATH . "/login.php?client_id=" . CLIENT_ID . "\n"; $body .= $lng->txt("login") . ": " . $oUser->getLogin() . "\n"; if ($oRegSettings->passwordGenerationEnabled()) { $body .= $lng->txt("passwd") . ": " . $password . "\n"; } $body .= "\n"; $body .= $lng->txt('reg_mail_body_forgot_password_info') . "\n"; $body .= "\n"; $body .= $lng->txt("reg_mail_body_text3") . "\n\r"; $body .= $oUser->getProfileAsString($lng); $mail_obj->enableSoap(false); $mail_obj->appendInstallationSignature(true); $mail_obj->sendMail($oUser->getEmail(), '', '', $subject, $body, array(), array('normal')); } ilUtil::redirect('./login.php?cmd=force_login®_confirmation_msg=reg_account_confirmation_successful&lang=' . $usr_lang); } catch (ilRegConfirmationLinkExpiredException $exception) { include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php'; $soap_client = new ilSoapClient(); $soap_client->setResponseTimeout(1); $soap_client->enableWSDL(true); $soap_client->init(); $ilLog->write(__METHOD__ . ': Triggered soap call (background process) for deletion of inactive user objects with expired confirmation hash values (dual opt in) ...'); $soap_client->call('deleteExpiredDualOptInUserObjects', array($_COOKIE['PHPSESSID'] . '::' . $_COOKIE['ilClientId'], $exception->getCode())); ilUtil::redirect('./login.php?cmd=force_login®_confirmation_msg=' . $exception->getMessage() . "&lang=" . $usr_lang); } catch (ilRegistrationHashNotFoundException $exception) { ilUtil::redirect('./login.php?cmd=force_login®_confirmation_msg=' . $exception->getMessage() . "&lang=" . $usr_lang); } }
/** * Insert property html */ function insert(&$a_tpl) { global $lng; $ptpl = new ilTemplate("tpl.prop_password.html", true, true, "Services/Form"); if (!$this->getPreSelection()) { if ($this->getRetype()) { $ptpl->setCurrentBlock("retype"); $ptpl->setVariable("RSIZE", $this->getSize()); $ptpl->setVariable("RID", $this->getFieldId()); $ptpl->setVariable("RMAXLENGTH", $this->getMaxLength()); $ptpl->setVariable("RPOST_VAR", $this->getPostVar()); if (!$this->getAutoComplete()) { $ptpl->setVariable("RAUTOCOMPLETE", "autocomplete=\"off\""); } // this is creating an "auto entry" in the setup, if the retype is missing /*$retype_value = ($this->getRetypeValue() != "") ? $this->getRetypeValue() : $this->getValue();*/ $retype_value = $this->getRetypeValue(); $ptpl->setVariable("PROPERTY_RETYPE_VALUE", ilUtil::prepareFormOutput($retype_value)); if ($this->getDisabled()) { $ptpl->setVariable("RDISABLED", " disabled=\"disabled\""); } $ptpl->setVariable("TXT_RETYPE", $lng->txt("form_retype_password")); $ptpl->parseCurrentBlock(); } if (strlen($this->getValue())) { $ptpl->setCurrentBlock("prop_password_propval"); $ptpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue())); $ptpl->parseCurrentBlock(); } $ptpl->setVariable("POST_VAR", $this->getPostVar()); $ptpl->setVariable("ID", $this->getFieldId()); $ptpl->setVariable("SIZE", $this->getSize()); $ptpl->setVariable("MAXLENGTH", $this->getMaxLength()); if ($this->getDisabled()) { $ptpl->setVariable("DISABLED", " disabled=\"disabled\""); } if (!$this->getAutoComplete()) { $ptpl->setVariable("AUTOCOMPLETE", "autocomplete=\"off\""); } } else { // preselection $passwd_list = ilUtil::generatePasswords(5); foreach ($passwd_list as $passwd) { $i++; $ptpl->setCurrentBlock("select_input"); $ptpl->setVariable("POST_VAR", $this->getPostVar()); $ptpl->setVariable("OP_ID", $this->getPostVar() . "_" . $i); $ptpl->setVariable("VAL_RADIO_OPTION", $passwd); $ptpl->setVariable("TXT_RADIO_OPTION", $passwd); $ptpl->parseCurrentBlock(); } } $a_tpl->setCurrentBlock("prop_generic"); $a_tpl->setVariable("PROP_GENERIC", $ptpl->get()); $a_tpl->parseCurrentBlock(); }
public function createFields() { $this->setFirstname($this->shibServerData->getFirstname()); $this->setLastname($this->shibServerData->getLastname()); $this->setLogin($this->returnNewLoginName()); $this->setPasswd(md5(end(ilUtil::generatePasswords(1))), IL_PASSWD_CRYPTED); $this->setGender($this->shibServerData->getGender()); $this->setExternalAccount($this->shibServerData->getLogin()); $this->setTitle($this->shibServerData->getTitle()); $this->setInstitution($this->shibServerData->getInstitution()); $this->setDepartment($this->shibServerData->getDepartment()); $this->setStreet($this->shibServerData->getStreet()); $this->setZipcode($this->shibServerData->getZipcode()); $this->setCountry($this->shibServerData->getCountry()); $this->setPhoneOffice($this->shibServerData->getPhoneOffice()); $this->setPhoneHome($this->shibServerData->getPhoneHome()); $this->setPhoneMobile($this->shibServerData->getPhoneMobile()); $this->setFax($this->shibServerData->getFax()); $this->setMatriculation($this->shibServerData->getMatriculation()); $this->setEmail($this->shibServerData->getEmail()); $this->setHobby($this->shibServerData->getHobby()); $this->setTitle($this->getFullname()); $this->setDescription($this->getEmail()); $this->setLanguage($this->shibServerData->getLanguage()); $this->setTimeLimitOwner(7); $this->setTimeLimitUnlimited(1); $this->setTimeLimitFrom(time()); $this->setTimeLimitUntil(time()); $this->setActive(true); }
protected function __createUser($a_role) { global $ilSetting, $rbacadmin; $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); $this->code_was_used = false; if ($this->code_enabled) { // #10853 - could be optional $code = $this->form->getInput('usr_registration_code'); if ($code) { // set code to used include_once './Services/Registration/classes/class.ilRegistrationCode.php'; ilRegistrationCode::useCode($code); $this->code_was_used = true; } } // 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); } if ($this->registration_settings->getAccessLimitation()) { include_once 'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php'; $access_limitations_obj = new ilRegistrationRoleAccessLimitations(); $access_limit_mode = $access_limitations_obj->getMode($a_role); if ($access_limit_mode == 'absolute') { $access_limit = $access_limitations_obj->getAbsolute($a_role); $this->userObj->setTimeLimitUnlimited(0); $this->userObj->setTimeLimitUntil($access_limit); } elseif ($access_limit_mode == '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(); $this->userObj->setTimeLimitUnlimited(0); $this->userObj->setTimeLimitUntil($access_limit); } else { $this->userObj->setTimeLimitUnlimited(1); $this->userObj->setTimeLimitUntil(time()); } } else { $this->userObj->setTimeLimitUnlimited(1); $this->userObj->setTimeLimitUntil(time()); } $this->userObj->setTimeLimitFrom(time()); $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 the ACCOUNT_SECURITY_MODE_CUSTOMIZED // in ilSecuritySettings $this->userObj->setLastPasswordChangeTS(time()); //insert user data in table user_data $this->userObj->saveAsNew(); // store acceptance of user agreement $this->userObj->writeAccepted(); // 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(), true); return $password; }
/** * Automatically generates the username/screenname of a Shibboleth user or returns * the user's already existing username * * @access private * @return String Generated username */ function generateLogin() { global $ilias, $ilDB; $shibID = $_SERVER[$ilias->getSetting('shib_login')]; $lastname = $this->getFirstString($_SERVER[$ilias->getSetting('shib_lastname')]); $firstname = $this->getFirstString($_SERVER[$ilias->getSetting('shib_firstname')]); if (trim($shibID) == "") { return; } //***********************************************// // For backwards compatibility with previous versions // We use the passwd field as mapping attribute for Shibboleth users // because they don't need a password $ilias->db->query("UPDATE usr_data SET auth_mode='shibboleth', passwd=" . $ilDB->quote(md5(end(ilUtil::generatePasswords(1)))) . ", ext_account=" . $ilDB->quote($shibID) . " WHERE passwd=" . $ilDB->quote($shibID)); //***********************************************// // Let's see if user already is registered $local_user = ilObjUser::_checkExternalAuthAccount("shibboleth", $shibID); if ($local_user) { return $local_user; } // Let's see if user already is registered but authenticates by ldap $local_user = ilObjUser::_checkExternalAuthAccount("ldap", $shibID); if ($local_user) { return $local_user; } // User doesn't seem to exist yet // Generate new username // This can be overruled by the data conversion API but you have // to do it yourself in that case // Generate the username out of the first character of firstname and the // first word in lastname (adding the second one if the login is too short, // avoiding meaningless last names like 'von' or 'd' and eliminating // non-ASCII-characters, spaces, dashes etc. $ln_arr = preg_split("/[ '-;]/", $lastname); $login = substr($this->toAscii($firstname), 0, 1) . "." . $this->toAscii($ln_arr[0]); if (strlen($login) < 6) { $login .= $this->toAscii($ln_arr[1]); } $prefix = strtolower($login); // If the user name didn't contain any ASCII characters, assign the // name 'shibboleth' followed by a number, starting with 1. if (strlen($prefix) == 0) { $prefix = 'shibboleth'; $number = 1; } else { // Try if the login name is not already taken if (!ilObjUser::getUserIdByLogin($prefix)) { return $prefix; } // If the login name is in use, append a number, starting with 2. $number = 2; } // Append a number, if the username is already taken while (ilObjUser::getUserIdByLogin($prefix . $number)) { $number++; } return $prefix . $number; }
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()); $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()); } } } return $password; }
/** * Called after login and successful call of fetch data * @return * @param object $a_username * @param object $a_auth */ public function loginObserver($a_username, $a_auth) { global $ilias, $rbacadmin, $lng, $ilSetting; $GLOBALS['ilLog']->write(__METHOD__ . ': SOAP login observer called'); // TODO: handle passed credentials via GET /* if (empty($_GET["ext_uid"]) || empty($_GET["soap_pw"])) { $this->status = AUTH_WRONG_LOGIN; return; } */ // Not required anymore /* $validation_data = $this->validateSoapUser($_GET["ext_uid"], $_GET["soap_pw"]); if (!$validation_data["valid"]) { $this->status = AUTH_WRONG_LOGIN; return; } */ $local_user = $this->response["local_user"]; if ($local_user != "") { // to do: handle update of user $a_auth->setAuth($local_user); return true; } if (!$ilSetting->get("soap_auth_create_users")) { $a_auth->status = AUTH_SOAP_NO_ILIAS_USER; $a_auth->logout(); return false; } //echo "1"; // try to map external user via e-mail to ILIAS user if ($this->response["email"] != "") { //echo "2"; //var_dump ($_POST); $email_user = ilObjUser::_getLocalAccountsForEmail($this->response["email"]); // check, if password has been provided in user mapping screen // (see ilStartUpGUI::showUserMappingSelection) // FIXME if ($_POST["LoginMappedUser"] != "") { if (count($email_user) > 0) { $user = ilObjectFactory::getInstanceByObjId($_POST["usr_id"]); require_once 'Services/User/classes/class.ilUserPasswordManager.php'; if (ilUserPasswordManager::getInstance()->verifyPassword($user, ilUtil::stripSlashes($_POST["password"]))) { // password is correct -> map user //$this->setAuth($local_user); (use login not id) ilObjUser::_writeExternalAccount($_POST["usr_id"], $_GET["ext_uid"]); ilObjUser::_writeAuthMode($_POST["usr_id"], "soap"); $_GET["cmd"] = $_POST["cmd"] = $_GET["auth_stat"] = ""; $local_user = ilObjUser::_lookupLogin($_POST["usr_id"]); $a_auth->status = ''; $a_auth->setAuth($local_user); return true; } else { //echo "6"; exit; $a_auth->status = AUTH_SOAP_NO_ILIAS_USER_BUT_EMAIL; $a_auth->setSubStatus(AUTH_WRONG_LOGIN); $a_auth->logout(); return false; } } } if (count($email_user) > 0 && $_POST["CreateUser"] == "") { $_GET["email"] = $this->response["email"]; $a_auth->status = AUTH_SOAP_NO_ILIAS_USER_BUT_EMAIL; $a_auth->logout(); return false; } } $userObj = new ilObjUser(); $local_user = ilAuthUtils::_generateLogin($a_username); $newUser["firstname"] = $this->response["firstname"]; $newUser["lastname"] = $this->response["lastname"]; $newUser["email"] = $this->response["email"]; $newUser["login"] = $local_user; // to do: set valid password and send mail $newUser["passwd"] = ""; $newUser["passwd_type"] = IL_PASSWD_CRYPTED; // generate password, if local authentication is allowed // and account mail is activated $pw = ""; if ($ilSetting->get("soap_auth_allow_local") && $ilSetting->get("soap_auth_account_mail")) { $pw = ilUtil::generatePasswords(1); $pw = $pw[0]; $newUser["passwd"] = $pw; $newUser["passwd_type"] = IL_PASSWD_PLAIN; } //$newUser["gender"] = "m"; $newUser["auth_mode"] = "soap"; $newUser["ext_account"] = $a_username; $newUser["profile_incomplete"] = 1; // system data $userObj->assignData($newUser); $userObj->setTitle($userObj->getFullname()); $userObj->setDescription($userObj->getEmail()); // set user language to system language $userObj->setLanguage($lng->lang_default); // Time limit $userObj->setTimeLimitOwner(7); $userObj->setTimeLimitUnlimited(1); $userObj->setTimeLimitFrom(time()); $userObj->setTimeLimitUntil(time()); // Create user in DB $userObj->setOwner(0); $userObj->create(); $userObj->setActive(1); $userObj->updateOwner(); //insert user data in table user_data $userObj->saveAsNew(false); // setup user preferences $userObj->writePrefs(); // to do: test this $rbacadmin->assignUser($ilSetting->get('soap_auth_user_default_role'), $userObj->getId(), true); // send account mail if ($ilSetting->get("soap_auth_account_mail")) { include_once './Services/User/classes/class.ilObjUserFolder.php'; $amail = ilObjUserFolder::_lookupNewAccountMail($ilSetting->get("language")); if (trim($amail["body"]) != "" && trim($amail["subject"]) != "") { include_once "Services/Mail/classes/class.ilAccountMail.php"; $acc_mail = new ilAccountMail(); if ($pw != "") { $acc_mail->setUserPassword($pw); } $acc_mail->setUser($userObj); $acc_mail->send(); } } unset($userObj); $a_auth->setAuth($local_user); return true; }