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"));
328 $login_obj->setAlert($this->
lng->txt(
"login_exists"));
330 } elseif ((
int) $this->
settings->get(
'allow_change_loginname') &&
331 (
int) $this->
settings->get(
'reuse_of_loginnames') === 0 &&
333 $login_obj->setAlert($this->
lng->txt(
'login_exists'));
339 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
343 return $this->
login();
345 $this->
form->setValuesByPost();
355 $ilias = $DIC[
'ilias'];
356 $ilias->raiseError(
"Invalid role selection in registration" .
357 ", IP: " .
$_SERVER[
"REMOTE_ADDR"], $ilias->error_obj->FATAL);
362 $this->userObj->setAuthMode(
'local');
365 $this->user_profile->skipGroup(
"preferences");
366 $this->user_profile->skipGroup(
"settings");
367 $this->user_profile->skipField(
"password");
368 $this->user_profile->skipField(
"birthday");
369 $this->user_profile->skipField(
"upload");
370 foreach ($this->user_profile->getStandardFields() as $k => $v) {
372 $method =
"set" . substr($v[
"method"], 3);
373 if (method_exists($this->userObj, $method)) {
374 if ($k !==
"username") {
377 $field_obj = $this->
form->getItemByPostVar($k);
379 $this->userObj->$method($this->
form->getInput($k));
385 $this->userObj->setFullName();
387 $birthday_obj = $this->
form->getItemByPostVar(
"usr_birthday");
389 $birthday = $this->
form->getInput(
"usr_birthday");
390 $this->userObj->setBirthday($birthday);
393 $this->userObj->setTitle($this->userObj->getFullname());
394 $this->userObj->setDescription($this->userObj->getEmail());
396 if ($this->registration_settings->passwordGenerationEnabled()) {
398 $password = $password[0];
400 $password = $this->
form->getInput(
"usr_password");
402 $this->userObj->setPasswd($password);
406 $defs = $user_defined_fields->getRegistrationDefinitions();
408 foreach ($defs as $definition) {
409 $f =
"udf_" . $definition[
'field_id'];
410 $item = $this->
form->getItemByPostVar(
$f);
411 if ($item && !$item->getDisabled()) {
412 $udf[$definition[
'field_id']] = $this->
form->getInput(
$f);
415 $this->userObj->setUserDefinedData($udf);
417 $this->userObj->setTimeLimitOwner(7);
419 $access_limit = null;
421 $this->code_was_used =
false;
422 $code_has_access_limit =
false;
423 $code_local_roles = [];
424 if ($this->code_enabled) {
425 $code_local_roles = $code_has_access_limit = null;
428 $code = $this->
form->getInput(
'usr_registration_code');
432 $this->code_was_used =
true;
436 if ($code_data[
"role_local"]) {
438 $code_local_roles = explode(
";", $code_data[
"role_local"]);
440 if ($code_data[
"alimit"]) {
442 $code_has_access_limit =
true;
444 switch ($code_data[
"alimit"]) {
446 $abs = date_parse($code_data[
"alimitdt"]);
447 $access_limit = mktime(23, 59, 59, $abs[
'month'], $abs[
'day'], $abs[
'year']);
451 $rel = unserialize($code_data[
"alimitdt"], [
'allowed_classes' =>
false]);
452 $access_limit = (
int) ($rel[
"d"] * 86400 + $rel[
"m"] * 2592000 + $rel[
"y"] * 31536000 + time());
460 if (!($this->code_was_used && $code_has_access_limit) &&
461 $this->registration_settings->getAccessLimitation()) {
463 switch ($access_limitations_obj->getMode($a_role)) {
465 $access_limit = $access_limitations_obj->getAbsolute($a_role);
469 $rel_d = $access_limitations_obj->getRelative($a_role,
'd');
470 $rel_m = $access_limitations_obj->getRelative($a_role,
'm');
471 $access_limit = $rel_d * 86400 + $rel_m * 2592000 + time();
477 $this->userObj->setTimeLimitUnlimited(
false);
478 $this->userObj->setTimeLimitUntil($access_limit);
480 $this->userObj->setTimeLimitUnlimited(
true);
481 $this->userObj->setTimeLimitUntil(time());
484 $this->userObj->setTimeLimitFrom(time());
488 $this->userObj->create();
493 $this->userObj->setActive(
true, 0);
495 $this->userObj->setActive(
false, 0);
497 $this->userObj->setActive(
false, 0);
502 $this->userObj->setLastPasswordChangeTS(time());
504 $this->userObj->setIsSelfRegistered(
true);
507 $this->userObj->saveAsNew();
510 $this->userObj->updateOwner();
513 $this->userObj->setLanguage($this->
form->getInput(
'usr_language'));
516 $DIC[
'legalDocuments']->selfRegistration()->userCreation($this->userObj);
518 $hits_per_page = $this->
settings->get(
"hits_per_page");
519 if ($hits_per_page < 10) {
522 $this->userObj->setPref(
"hits_per_page", $hits_per_page);
523 if ($this->
http->wrapper()->query()->has(
'target')) {
524 $this->userObj->setPref(
526 $this->
http->wrapper()->query()->retrieve(
528 $this->
refinery->kindlyTo()->string()
532 $this->userObj->setPref(
'bs_allow_to_contact_me', $this->
settings->get(
'bs_allow_to_contact_me',
'n'));
533 $this->userObj->setPref(
'chat_osc_accept_msg', $this->
settings->get(
'chat_osc_accept_msg',
'n'));
534 $this->userObj->setPref(
'chat_broadcast_typing', $this->
settings->get(
'chat_broadcast_typing',
'n'));
535 $this->userObj->writePrefs();
537 $this->rbacadmin->assignUser($a_role, $this->userObj->getId());
540 if ($this->code_was_used && is_array($code_local_roles)) {
541 $code_local_roles = array_map(intval(...), array_unique($code_local_roles));
542 foreach ($code_local_roles as $local_role_obj_id) {
545 $this->rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId());
548 $role_obj =
$GLOBALS[
'DIC'][
'rbacreview']->getObjectOfRole($local_role_obj_id);
553 $role_ref = end($role_refs);
563 return (
string) $password;
569 if ($this->registration_settings->getApproveRecipients()) {
572 if (!$this->code_was_used &&
578 $mail->setRecipients($this->registration_settings->getApproveRecipients());
579 $mail->setAdditionalInformation([
'usr' => $this->userObj]);
584 if (!$this->code_was_used &&
588 $mail->setRecipients([$this->userObj]);
589 $mail->setAdditionalInformation(
591 'usr' => $this->userObj,
592 'hash_lifetime' => $this->registration_settings->getRegistrationHashLifetime()
598 $this->registration_settings,
602 $accountMail->withDirectRegistrationMode()->send($this->userObj, $password, $this->code_was_used);
609 $this->tpl->setVariable(
'TXT_PAGEHEADLINE', $this->
lng->txt(
'registration'));
611 $tpl->
setVariable(
"TXT_WELCOME", $this->
lng->txt(
"welcome") .
", " . $this->userObj->getTitle() .
"!");
618 !$this->registration_settings->passwordGenerationEnabled()
620 $tpl->
setVariable(
'TXT_REGISTERED', $this->
lng->txt(
'txt_registered'));
622 $login_link = $this->ui_renderer->render(
623 $this->ui_factory->link()->standard(
624 $this->
lng->txt(
'login_to_ilias'),
625 './login.php?cmd=force_login&lang=' . $this->userObj->getLanguage()
630 $tpl->
setVariable(
'TXT_REGISTERED', $this->
lng->txt(
'txt_submitted'));
632 $tpl->
setVariable(
'TXT_REGISTERED', $this->
lng->txt(
'reg_confirmation_link_successful'));
634 $tpl->
setVariable(
'TXT_REGISTERED', $this->
lng->txt(
'txt_registered_passw_gen'));
641 $field_id = (string) $_REQUEST[
"f"];
642 $term = (string) $_REQUEST[
"term"];
645 if (count($result)) {
646 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="")
Error Handling & global info handling.
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