19declare(strict_types=1);
61 protected \ILIAS\HTTP\Services
$http;
68 $this->tpl =
$DIC->ui()->mainTemplate();
70 $this->
ctrl = $DIC->ctrl();
71 $this->
ctrl->saveParameter($this,
'lang');
72 $this->
lng = $DIC->language();
73 $this->
lng->loadLanguageModule(
'registration');
74 $this->db =
$DIC->database();
75 $this->
error = $DIC[
'ilErr'];
77 $this->globalUser =
$DIC->user();
78 $this->rbacreview =
$DIC->rbac()->review();
79 $this->rbacadmin =
$DIC->rbac()->admin();
80 $this->ui_factory =
$DIC->ui()->factory();
81 $this->ui_renderer =
$DIC->ui()->renderer();
84 $this->code_enabled = ($this->registration_settings->registrationCodeRequired() ||
85 $this->registration_settings->getAllowCodes());
89 $this->user_profile =
$DIC[
'user']->getProfile();
90 $this->user_settings =
$DIC[
'user']->getSettings();
92 $this->
http = $DIC->http();
99 $this->
error->raiseError($this->
lng->txt(
'reg_disabled'), $this->error->MESSAGE);
102 $cmd = $this->
ctrl->getCmd();
105 $tpl = $this->$cmd();
111 $this->tpl->setPermanentLink(
'usr',
null,
'registration');
129 $this->globalUser->setLanguage($this->
lng->getLangKey());
136 $this->
form->setFormAction($this->
ctrl->getFormAction($this));
139 if ($this->code_enabled) {
141 $field->setTitle($this->
lng->txt(
'registration_codes_type_reg'));
142 $this->
form->addItem($field);
143 $code =
new ilTextInputGUI($this->
lng->txt(
'registration_code'),
'usr_registration_code');
146 if ($this->registration_settings->registrationCodeRequired()) {
147 $code->setRequired(
true);
148 $code->setInfo($this->
lng->txt(
'registration_code_required_info'));
150 $code->setInfo($this->
lng->txt(
'registration_code_optional_info'));
152 $this->
form->addItem($code);
157 $this->
lng->loadLanguageModule(
'user');
159 $this->user_profile->addFieldsToForm($this->
form, Context::Registration,
true,
null, [Alias::class]);
162 $field->setTitle($this->
lng->txt(
'settings'));
163 $this->
form->addItem($field);
165 $lang_setting = $this->user_settings->getSettingByDefinitionClass(LanguageSetting::class);
166 $flang = $lang_setting->getLegacyInput($this->
lng, $this->
settings);
167 $flang->setDisabled(!$lang_setting->isChangeableByUser());
169 $flang->setValue($this->
lng->getLangKey());
171 $this->
form->addItem($flang);
175 if ($role !==
null) {
176 if ($this->code_enabled) {
177 $role->setInfo($this->
lng->txt(
'registration_code_role_info'));
179 $this->
form->addItem($role);
184 foreach ($this->registration_settings->getAllowedDomains() as $item) {
189 if (count($domains)) {
190 $mail_obj = $this->
form->getItemByPostVar(
'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(
'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(
'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(
'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(
'password'),
285 $this->form->getInput(
'username'),
289 $passwd_obj = $this->
form->getItemByPostVar(
'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(
'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 ($this->user_profile->userFieldEditableByUser(Alias::class) &&
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'];
370 'Invalid role selection in registration' .
372 $ilias->error_obj->FATAL
378 $this->userObj->setAuthMode(
'local');
381 $this->userObj = $this->user_profile->addFormValuesToUser(
383 Context::Registration,
386 $this->userObj->setTitle($this->userObj->getFullname());
387 $this->userObj->setDescription($this->userObj->getEmail());
389 $this->userObj->setLogin(
390 $this->
form->getInput(
'username')
393 if ($this->registration_settings->passwordGenerationEnabled()) {
395 $password = $password[0];
397 $password = $this->
form->getInput(
'password');
400 $this->userObj->setLanguage(
401 $this->user_settings->getValueFromLegacyFormByDefinitionClass(
402 LanguageSetting::class,
407 $this->userObj->setPasswd($password);
409 $access_limit =
null;
411 $this->code_was_used =
false;
412 $code_has_access_limit =
false;
413 $code_local_roles = [];
414 if ($this->code_enabled) {
415 $code_local_roles = $code_has_access_limit =
null;
418 $code = $this->
form->getInput(
'usr_registration_code');
422 $this->code_was_used =
true;
426 if ($code_data[
'role_local']) {
428 $code_local_roles = explode(
';', $code_data[
'role_local']);
430 if ($code_data[
'alimit']) {
432 $code_has_access_limit =
true;
434 switch ($code_data[
'alimit']) {
436 $abs = date_parse($code_data[
'alimitdt']);
437 $access_limit = mktime(23, 59, 59, $abs[
'month'], $abs[
'day'], $abs[
'year']);
441 $rel = unserialize($code_data[
'alimitdt'], [
'allowed_classes' =>
false]);
442 $access_limit = (
int) ($rel[
'd'] * 86400 + $rel[
'm'] * 2592000 + $rel[
'y'] * 31536000 + time());
450 if (!($this->code_was_used && $code_has_access_limit) &&
451 $this->registration_settings->getAccessLimitation()) {
453 switch ($access_limitations_obj->getMode($a_role)) {
455 $access_limit = $access_limitations_obj->getAbsolute($a_role);
459 $rel_d = $access_limitations_obj->getRelative($a_role,
'd');
460 $rel_m = $access_limitations_obj->getRelative($a_role,
'm');
461 $access_limit = $rel_d * 86400 + $rel_m * 2592000 + time();
467 $this->userObj->setTimeLimitUnlimited(
false);
468 $this->userObj->setTimeLimitUntil($access_limit);
470 $this->userObj->setTimeLimitUnlimited(
true);
471 $this->userObj->setTimeLimitUntil(time());
474 $this->userObj->setTimeLimitFrom(time());
478 $this->userObj->create();
482 $this->code_was_used) {
483 $this->userObj->setActive(
true, 0);
485 $this->userObj->setActive(
false, 0);
487 $this->userObj->setActive(
false, 0);
492 $this->userObj->setLastPasswordChangeTS(time());
494 $this->userObj->setIsSelfRegistered(
true);
497 $this->userObj->saveAsNew();
500 $this->userObj->updateOwner();
503 $this->userObj->setLanguage($this->
form->getInput(
'usr_language'));
506 $DIC[
'legalDocuments']->selfRegistration()->userCreation($this->userObj);
508 if ($this->
http->wrapper()->query()->has(
'target')) {
509 $this->userObj->setPref(
511 $this->
http->wrapper()->query()->retrieve(
513 $this->refinery->kindlyTo()->string()
517 $this->userObj->setPref(
'bs_allow_to_contact_me', $this->
settings->get(
'bs_allow_to_contact_me',
'n'));
518 $this->userObj->setPref(
'chat_osc_accept_msg', $this->
settings->get(
'chat_osc_accept_msg',
'n'));
519 $this->userObj->setPref(
'chat_broadcast_typing', $this->
settings->get(
'chat_broadcast_typing',
'n'));
520 $this->userObj->writePrefs();
522 $this->rbacadmin->assignUser($a_role, $this->userObj->getId());
525 if ($this->code_was_used && is_array($code_local_roles)) {
526 $code_local_roles = array_map(intval(...), array_unique($code_local_roles));
527 foreach ($code_local_roles as $local_role_obj_id) {
530 $this->rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId());
533 $role_obj =
$GLOBALS[
'DIC'][
'rbacreview']->getObjectOfRole($local_role_obj_id);
538 $role_ref = end($role_refs);
548 return (
string) $password;
554 if ($this->registration_settings->getApproveRecipients()) {
557 if (!$this->code_was_used &&
563 $mail->setRecipients($this->registration_settings->getApproveRecipients());
564 $mail->setAdditionalInformation([
'usr' => $this->userObj]);
570 if (!$this->code_was_used && $is_dual_opt_in_reg_mode) {
572 $this->registration_settings,
574 $this->dic->database(),
575 $this->dic->logger()->user(),
578 $dual_opt_in_service->distributeMailsOnRegistration($this->userObj);
581 $this->registration_settings,
585 $accountMail->withDirectRegistrationMode()->send($this->userObj, $password, $this->code_was_used);
592 $this->tpl->setVariable(
'TXT_PAGEHEADLINE', $this->
lng->txt(
'registration'));
594 $tpl->
setVariable(
'TXT_WELCOME', $this->
lng->txt(
'welcome') .
', ' . $this->userObj->getTitle() .
'!');
601 !$this->registration_settings->passwordGenerationEnabled()
605 $login_link = $this->ui_renderer->render(
606 $this->ui_factory->link()->standard(
607 $this->lng->txt(
'login_to_ilias'),
608 './login.php?cmd=force_login&lang=' . $this->userObj->getLanguage()
615 $tpl->
setVariable(
'TXT_REGISTERED', $this->
lng->txt(
'reg_confirmation_link_successful'));
617 $tpl->
setVariable(
'TXT_REGISTERED', $this->
lng->txt(
'txt_registered_passw_gen'));
625 $field->setTitle($this->
lng->txt(
'login_data'));
626 $this->
form->addItem($field);
629 $login_input->setSize(255);
630 $login_input->setRequired(
true);
631 $this->
form->addItem($login_input);
633 if ($this->registration_settings->passwordGenerationEnabled()) {
635 $password_input->setValue($this->
lng->txt(
'reg_passwd_via_mail'));
636 $this->
form->addItem($password_input);
641 $password_input->setUseStripSlashes(
false);
642 $password_input->setRequired(
true);
644 $this->
form->addItem($password_input);
649 if (!$this->registration_settings->roleSelectionEnabled()) {
655 $options[$role[
'id']] = $role[
'title'];
665 $roles_input->setValue((
string) array_shift($keys));
669 $options_with_empty_value = [
'' => $this->
lng->txt(
'please_choose')] +
$options;
671 $roles_input->setOptions($options_with_empty_value);
672 $roles_input->setRequired(
true);
Customizing of pimple-DIC for ILIAS.
Builds a Color from either hex- or rgb values.
@phpstan-type PendingRegistrationRecord array{id: string, usr_id: int, reg_hash: string,...
@ilCtrl_Calls ilAccountRegistrationGUI:
ilRegistrationSettings $registration_settings
ILIAS UI Factory $ui_factory
ILIAS UI Renderer $ui_renderer
ILIAS HTTP Services $http
UserSettings $user_settings
ilRecommendedContentManager $recommended_content_manager
ILIAS Refinery Factory $refinery
ilGlobalTemplateInterface $tpl
distributeMails(string $password)
Class ilAccountRegistrationMail.
Error Handling & global info handling.
static getLogger(string $a_component_id)
Get component logger.
This class represents a non editable value in a property form.
static _lookupRegisterAllowed()
get all roles that are activated in user registration
static _lookupAllowRegister(int $a_role_id)
check whether role is allowed in user registration or not
static _loginExists(string $a_login, int $a_user_id=0)
static _doesLoginnameExistInHistory(string $a_login)
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
Class ilRbacAdmin Core functions for role based access control.
class ilRbacReview Contains Review functions of core Rbac.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static useCode(string $code)
static getCodeRole(string $code)
static getCodeData(string $code)
static isValidRegistrationCode(string $a_code)
const TYPE_NOTIFICATION_CONFIRMATION
const TYPE_NOTIFICATION_APPROVERS
Class class.ilRegistrationAccessLimitation.
Class class.ilregistrationEmailRoleAssignments.
Class ilObjAuthSettingsGUI.
static isPasswordValidForUserContext(string $clear_text_password, $user, ?string &$error_language_variable=null)
static getPasswordRequirementsInfo()
infotext for ilPasswordInputGUI setInfo()
static generatePasswords(int $a_number)
Generate a number of passwords.
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,...
static printToGlobalTemplate($tpl)
This class represents a text property in a property form.
const CONTEXT_REGISTRATION
static isLogin(string $a_login)
static initjQuery(?ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
setVariable(string $variable, $value='')
Sets the given variable to the given value.
An entity that renders components to a string output.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
form(?array $class_path, string $cmd, string $submit_caption="")
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.