19 declare(strict_types=1);
    50     protected \ILIAS\HTTP\Services 
$http;
    56         $this->tpl = $DIC->ui()->mainTemplate();
    58         $this->
ctrl = $DIC->ctrl();
    59         $this->
ctrl->saveParameter($this, 
'lang');
    60         $this->
lng = $DIC->language();
    61         $this->
lng->loadLanguageModule(
'registration');
    62         $this->error = $DIC[
'ilErr'];
    64         $this->globalUser = $DIC->user();
    65         $this->rbacreview = $DIC->rbac()->review();
    66         $this->rbacadmin = $DIC->rbac()->admin();
    67         $this->ui_factory = $DIC->ui()->factory();
    68         $this->ui_renderer = $DIC->ui()->renderer();
    71         $this->code_enabled = ($this->registration_settings->registrationCodeRequired() ||
    72             $this->registration_settings->getAllowCodes());
    78         $this->
http = $DIC->http();
    85             $this->error->raiseError($this->
lng->txt(
'reg_disabled'), $this->error->FATAL);
    88         $cmd = $this->
ctrl->getCmd();
    97         $this->tpl->setPermanentLink(
'usr', null, 
'registration');
   104         $tpl->
setVariable(
'TXT_PAGEHEADLINE', $this->
lng->txt(
'registration'));
   115         $this->globalUser->setLanguage($this->
lng->getLangKey());
   122         $this->
form->setFormAction($this->
ctrl->getFormAction($this));
   125         if ($this->code_enabled) {
   127             $field->setTitle($this->
lng->txt(
'registration_codes_type_reg'));
   128             $this->
form->addItem($field);
   129             $code = 
new ilTextInputGUI($this->
lng->txt(
"registration_code"), 
"usr_registration_code");
   132             if ($this->registration_settings->registrationCodeRequired()) {
   133                 $code->setRequired(
true);
   134                 $code->setInfo($this->
lng->txt(
"registration_code_required_info"));
   136                 $code->setInfo($this->
lng->txt(
"registration_code_optional_info"));
   138             $this->
form->addItem($code);
   142         $user_defined_data = $this->globalUser->getUserDefinedData();
   146         foreach ($user_defined_fields->getRegistrationDefinitions() as $field_id => $definition) {
   150                 $user_defined_data[
'f_' . $field_id] ?? 
''   153                 $custom_fields[
'udf_' . $definition[
'field_id']] = $fprop;
   158         $this->user_profile->skipGroup(
"preferences");
   160         $this->user_profile->setAjaxCallback(
   161             $this->
ctrl->getLinkTarget($this, 
'doProfileAutoComplete', 
'', 
true)
   163         $this->
lng->loadLanguageModule(
"user");
   165         $this->user_profile->addStandardFieldsToForm($this->
form, null, $custom_fields);
   166         unset($custom_fields);
   169         $flang = $this->
form->getItemByPostVar(
"usr_language");
   171             $flang->setValue($this->
lng->getLangKey());
   175         if ($this->code_enabled) {
   176             $role = $this->
form->getItemByPostVar(
"usr_roles");
   177             if ($role && $role->getType() === 
"select") {
   178                 $role->setInfo($this->
lng->txt(
"registration_code_role_info"));
   184         foreach ($this->registration_settings->getAllowedDomains() as $item) {
   189         if (count($domains)) {
   190             $mail_obj = $this->
form->getItemByPostVar(
'usr_email');
   191             $mail_obj->setInfo(sprintf(
   192                 $this->
lng->txt(
"reg_email_domains"),
   193                 implode(
", ", $domains)
   195                 ($this->code_enabled ? $this->
lng->txt(
"reg_email_domains_code") : 
""));
   200             $mail_obj = $this->
form->getItemByPostVar(
'usr_email');
   202                 $mail_obj->setRequired(
true);
   207         array_map($this->
form->addItem(...), $DIC[
'legalDocuments']->selfRegistration()->legacyInputGUIs());
   209         $this->
form->addCommandButton(
"saveForm", $this->
lng->txt(
"register"));
   215         $form_valid = $this->
form->checkInput();
   218         $valid_code = $valid_role = 
false;
   221         if ($this->code_enabled) {
   222             $code = $this->
form->getInput(
'usr_registration_code');
   226                 $this->registration_settings->registrationCodeRequired()
   230                     $code_obj = $this->
form->getItemByPostVar(
'usr_registration_code');
   231                     $code_obj->setAlert($this->
lng->txt(
'registration_code_not_valid'));
   238                     if ($role_id && $this->rbacreview->isGlobalRole($role_id)) {
   239                         $valid_role = $role_id;
   248             $email = $this->
form->getInput(
"usr_email");
   252                 foreach ($this->registration_settings->getAllowedDomains() as $item) {
   257                 if (count($domains)) {
   259                     foreach ($domains as $domain) {
   260                         $domain = str_replace(
"*", 
"~~~", $domain);
   261                         $domain = preg_quote($domain, 
'/');
   262                         $domain = str_replace(
"~~~", 
".+", $domain);
   263                         if (preg_match(
"/^" . $domain . 
"$/", $email, $hit)) {
   269                         $mail_obj = $this->
form->getItemByPostVar(
'usr_email');
   270                         $mail_obj->setAlert(sprintf(
   271                             $this->
lng->txt(
"reg_email_domains"),
   272                             implode(
", ", $domains)
   282             !$this->registration_settings->passwordGenerationEnabled() &&
   284                 $this->
form->getInput(
'usr_password'),
   285                 $this->
form->getInput(
'username'),
   289             $passwd_obj = $this->
form->getItemByPostVar(
'usr_password');
   290             $passwd_obj->setAlert($this->
lng->txt($error_lng_var));
   295         $form_valid = $DIC[
'legalDocuments']->selfRegistration()->saveLegacyForm($this->
form) && $form_valid;
   300             if ($this->registration_settings->roleSelectionEnabled()) {
   301                 $selected_role = $this->
form->getInput(
"usr_roles");
   303                     $valid_role = (
int) $selected_role;
   308                 $valid_role = $registration_role_assignments->getRoleByEmail($this->
form->getInput(
"usr_email"));
   313         if (!$valid_role && (!isset($selected_role) || $selected_role !== 
'')) {
   314             $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"registration_no_valid_role"));
   319         $login_obj = $this->
form->getItemByPostVar(
'username');
   320         $login = $this->
form->getInput(
"username");
   322             $login_obj->setAlert($this->
lng->txt(
"login_invalid"));
   327         $username_checked_and_register_callback = 
function () use (&$form_valid, $login, $login_obj, $valid_role) {
   330                     $login_obj->setAlert($this->
lng->txt(
'login_exists'));
   332                 } elseif ((
int) $this->
settings->get(
'allow_change_loginname') &&
   333                     (
int) $this->
settings->get(
'reuse_of_loginnames') === 0 &&
   335                     $login_obj->setAlert($this->
lng->txt(
'login_exists'));
   346         if (($register_duration = $this->
settings->get(
'registration_duration')) !== null) {
   347             $duration = $this->
http->durations()->callbackDuration((
int) $register_duration);
   348             $duration->stretch($username_checked_and_register_callback);
   350             $username_checked_and_register_callback();
   354             return $this->
login();
   357         $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
   358         $this->
form->setValuesByPost();
   368             $ilias = $DIC[
'ilias'];
   369             $ilias->raiseError(
"Invalid role selection in registration" .
   370                 ", IP: " . 
$_SERVER[
"REMOTE_ADDR"], $ilias->error_obj->FATAL);
   375             $this->userObj->setAuthMode(
'local');
   378         $this->user_profile->skipGroup(
"preferences");
   379         $this->user_profile->skipGroup(
"settings");
   380         $this->user_profile->skipField(
"password");
   381         $this->user_profile->skipField(
"birthday");
   382         $this->user_profile->skipField(
"upload");
   383         foreach ($this->user_profile->getStandardFields() as $k => $v) {
   385                 $method = 
"set" . substr($v[
"method"], 3);
   386                 if (method_exists($this->userObj, $method)) {
   387                     if ($k !== 
"username") {
   390                     $field_obj = $this->
form->getItemByPostVar($k);
   392                         $this->userObj->$method($this->
form->getInput($k));
   398         $this->userObj->setFullName();
   400         $birthday_obj = $this->
form->getItemByPostVar(
"usr_birthday");
   402             $birthday = $this->
form->getInput(
"usr_birthday");
   403             $this->userObj->setBirthday($birthday);
   406         $this->userObj->setTitle($this->userObj->getFullname());
   407         $this->userObj->setDescription($this->userObj->getEmail());
   409         if ($this->registration_settings->passwordGenerationEnabled()) {
   411             $password = $password[0];
   413             $password = $this->
form->getInput(
"usr_password");
   415         $this->userObj->setPasswd($password);
   419         $defs = $user_defined_fields->getRegistrationDefinitions();
   421         foreach ($defs as $definition) {
   422             $f = 
"udf_" . $definition[
'field_id'];
   423             $item = $this->
form->getItemByPostVar(
$f);
   424             if ($item && !$item->getDisabled()) {
   425                 $udf[$definition[
'field_id']] = $this->
form->getInput(
$f);
   428         $this->userObj->setUserDefinedData($udf);
   430         $this->userObj->setTimeLimitOwner(7);
   432         $access_limit = null;
   434         $this->code_was_used = 
false;
   435         $code_has_access_limit = 
false;
   436         $code_local_roles = [];
   437         if ($this->code_enabled) {
   438             $code_local_roles = $code_has_access_limit = null;
   441             $code = $this->
form->getInput(
'usr_registration_code');
   445                 $this->code_was_used = 
true;
   449                 if ($code_data[
"role_local"]) {
   451                     $code_local_roles = explode(
";", $code_data[
"role_local"]);
   453                 if ($code_data[
"alimit"]) {
   455                     $code_has_access_limit = 
true;
   457                     switch ($code_data[
"alimit"]) {
   459                             $abs = date_parse($code_data[
"alimitdt"]);
   460                             $access_limit = mktime(23, 59, 59, $abs[
'month'], $abs[
'day'], $abs[
'year']);
   464                             $rel = unserialize($code_data[
"alimitdt"], [
'allowed_classes' => 
false]);
   465                             $access_limit = (
int) ($rel[
"d"] * 86400 + $rel[
"m"] * 2592000 + $rel[
"y"] * 31536000 + time());
   473         if (!($this->code_was_used && $code_has_access_limit) &&
   474             $this->registration_settings->getAccessLimitation()) {
   476             switch ($access_limitations_obj->getMode($a_role)) {
   478                     $access_limit = $access_limitations_obj->getAbsolute($a_role);
   482                     $rel_d = $access_limitations_obj->getRelative($a_role, 
'd');
   483                     $rel_m = $access_limitations_obj->getRelative($a_role, 
'm');
   484                     $access_limit = $rel_d * 86400 + $rel_m * 2592000 + time();
   490             $this->userObj->setTimeLimitUnlimited(
false);
   491             $this->userObj->setTimeLimitUntil($access_limit);
   493             $this->userObj->setTimeLimitUnlimited(
true);
   494             $this->userObj->setTimeLimitUntil(time());
   497         $this->userObj->setTimeLimitFrom(time());
   501         $this->userObj->create();
   506             $this->userObj->setActive(
true, 0);
   508             $this->userObj->setActive(
false, 0);
   510             $this->userObj->setActive(
false, 0);
   515         $this->userObj->setLastPasswordChangeTS(time());
   517         $this->userObj->setIsSelfRegistered(
true);
   520         $this->userObj->saveAsNew();
   523         $this->userObj->updateOwner();
   526         $this->userObj->setLanguage($this->
form->getInput(
'usr_language'));
   529         $DIC[
'legalDocuments']->selfRegistration()->userCreation($this->userObj);
   531         if ($this->
http->wrapper()->query()->has(
'target')) {
   532             $this->userObj->setPref(
   534                 $this->
http->wrapper()->query()->retrieve(
   536                     $this->
refinery->kindlyTo()->string()
   540         $this->userObj->setPref(
'bs_allow_to_contact_me', $this->
settings->get(
'bs_allow_to_contact_me', 
'n'));
   541         $this->userObj->setPref(
'chat_osc_accept_msg', $this->
settings->get(
'chat_osc_accept_msg', 
'n'));
   542         $this->userObj->setPref(
'chat_broadcast_typing', $this->
settings->get(
'chat_broadcast_typing', 
'n'));
   543         $this->userObj->writePrefs();
   545         $this->rbacadmin->assignUser($a_role, $this->userObj->getId());
   548         if ($this->code_was_used && is_array($code_local_roles)) {
   549             $code_local_roles = 
array_map(intval(...), array_unique($code_local_roles));
   550             foreach ($code_local_roles as $local_role_obj_id) {
   553                     $this->rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId());
   556                     $role_obj = 
$GLOBALS[
'DIC'][
'rbacreview']->getObjectOfRole($local_role_obj_id);
   561                             $role_ref = end($role_refs);
   571         return (
string) $password;
   577         if ($this->registration_settings->getApproveRecipients()) {
   580             if (!$this->code_was_used &&
   586             $mail->setRecipients($this->registration_settings->getApproveRecipients());
   587             $mail->setAdditionalInformation([
'usr' => $this->userObj]);
   592         if (!$this->code_was_used &&
   596             $mail->setRecipients([$this->userObj]);
   597             $mail->setAdditionalInformation(
   599                     'usr' => $this->userObj,
   600                     'hash_lifetime' => $this->registration_settings->getRegistrationHashLifetime()
   606                 $this->registration_settings,
   610             $accountMail->withDirectRegistrationMode()->send($this->userObj, $password, $this->code_was_used);
   617         $this->tpl->setVariable(
'TXT_PAGEHEADLINE', $this->
lng->txt(
'registration'));
   619         $tpl->
setVariable(
"TXT_WELCOME", $this->
lng->txt(
"welcome") . 
", " . $this->userObj->getTitle() . 
"!");
   626             !$this->registration_settings->passwordGenerationEnabled()
   628             $tpl->
setVariable(
'TXT_REGISTERED', $this->
lng->txt(
'txt_registered'));
   630             $login_link = $this->ui_renderer->render(
   631                 $this->ui_factory->link()->standard(
   632                     $this->
lng->txt(
'login_to_ilias'),
   633                     './login.php?cmd=force_login&lang=' . $this->userObj->getLanguage()
   638             $tpl->
setVariable(
'TXT_REGISTERED', $this->
lng->txt(
'txt_submitted'));
   640             $tpl->
setVariable(
'TXT_REGISTERED', $this->
lng->txt(
'reg_confirmation_link_successful'));
   642             $tpl->
setVariable(
'TXT_REGISTERED', $this->
lng->txt(
'txt_registered_passw_gen'));
   649         $field_id = (string) $_REQUEST[
"f"];
   650         $term = (string) $_REQUEST[
"term"];
   653         if (count($result)) {
   654             echo json_encode($result, JSON_THROW_ON_ERROR);
 
static getCodeRole(string $code)
 
static initStartUpTemplate( $a_tmpl, bool $a_show_back=false, bool $a_show_logout=false)
This method enriches the global template with some user interface elements (language selection...
 
Class for mime mail registration notifications. 
 
static getLogger(string $a_component_id)
Get component logger. 
 
Class ilAccountRegistrationGUI. 
 
const TYPE_NOTIFICATION_ACTIVATION
 
static getAutocompleteResult(string $a_field_id, string $a_term)
 
static _getAllReferences(int $id)
get all reference ids for object ID 
 
ILIAS Refinery Factory $refinery
 
Class class.ilregistrationEmailRoleAssignments. 
 
setVariable(string $variable, $value='')
Sets the given variable to the given value. 
 
ILIAS HTTP Services $http
 
static printToGlobalTemplate($tpl)
 
static getCodeData(string $code)
 
const TYPE_NOTIFICATION_APPROVERS
 
static http()
Fetches the global http state from ILIAS. 
 
Class ilAccountRegistrationMail. 
 
ilRecommendedContentManager $recommended_content_manager
 
static isValidRegistrationCode(string $a_code)
 
static _loginExists(string $a_login, int $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
 
static isLogin(string $a_login)
 
static isPasswordValidForUserContext(string $clear_text_password, $user, ?string &$error_language_variable=null)
 
Class class.ilRegistrationAccessLimitation. 
 
static generatePasswords(int $a_number)
Generate a number of passwords. 
 
static _doesLoginnameExistInHistory(string $a_login)
Checks whether the passed loginname already exists in history. 
 
Class ilObjAuthSettingsGUI. 
 
form( $class_path, string $cmd, string $submit_caption="")
 
static useCode(string $code)
 
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template 
 
ILIAS UI Factory $ui_factory
 
ilRegistrationSettings $registration_settings
 
distributeMails(string $password)
 
Class ilRbacAdmin Core functions for role based access control. 
 
static _lookupType(int $id, bool $reference=false)
 
ilGlobalTemplateInterface $tpl
 
const CONTEXT_REGISTRATION
 
static _lookupAllowRegister(int $a_role_id)
check whether role is allowed in user registration or not 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
ILIAS UI Renderer $ui_renderer
 
const TYPE_NOTIFICATION_CONFIRMATION
 
ilUserProfile $user_profile