19declare(strict_types=1);
59 protected \ILIAS\HTTP\Services
$http;
65 $this->tpl =
$DIC->ui()->mainTemplate();
67 $this->
ctrl = $DIC->ctrl();
68 $this->
ctrl->saveParameter($this,
'lang');
69 $this->
lng = $DIC->language();
70 $this->
lng->loadLanguageModule(
'registration');
71 $this->db =
$DIC->database();
72 $this->
error = $DIC[
'ilErr'];
74 $this->globalUser =
$DIC->user();
75 $this->rbacreview =
$DIC->rbac()->review();
76 $this->rbacadmin =
$DIC->rbac()->admin();
77 $this->ui_factory =
$DIC->ui()->factory();
78 $this->ui_renderer =
$DIC->ui()->renderer();
81 $this->code_enabled = ($this->registration_settings->registrationCodeRequired() ||
82 $this->registration_settings->getAllowCodes());
86 $this->user_profile =
$DIC[
'user']->getProfile();
87 $this->user_settings =
$DIC[
'user']->getSettings();
89 $this->
http = $DIC->http();
96 $this->
error->raiseError($this->
lng->txt(
'reg_disabled'), $this->error->FATAL);
99 $cmd = $this->
ctrl->getCmd();
102 $tpl = $this->$cmd();
108 $this->tpl->setPermanentLink(
'usr',
null,
'registration');
126 $this->globalUser->setLanguage($this->
lng->getLangKey());
133 $this->
form->setFormAction($this->
ctrl->getFormAction($this));
136 if ($this->code_enabled) {
138 $field->setTitle($this->
lng->txt(
'registration_codes_type_reg'));
139 $this->
form->addItem($field);
140 $code =
new ilTextInputGUI($this->
lng->txt(
"registration_code"),
"usr_registration_code");
143 if ($this->registration_settings->registrationCodeRequired()) {
144 $code->setRequired(
true);
145 $code->setInfo($this->
lng->txt(
"registration_code_required_info"));
147 $code->setInfo($this->
lng->txt(
"registration_code_optional_info"));
149 $this->
form->addItem($code);
154 $this->
lng->loadLanguageModule(
"user");
156 $this->user_profile->addFieldsToForm($this->
form, Context::Registration,
true,
null, [Alias::class]);
159 $field->setTitle($this->
lng->txt(
'settings'));
160 $this->
form->addItem($field);
162 $lang_setting = $this->user_settings->getSettingByDefinitionClass(LanguageSetting::class);
163 $flang = $lang_setting->getLegacyInput($this->
lng, $this->
settings);
164 $flang->setDisabled(!$lang_setting->isChangeableByUser());
166 $flang->setValue($this->
lng->getLangKey());
168 $this->
form->addItem($flang);
172 if ($this->code_enabled) {
173 $role->setInfo($this->
lng->txt(
"registration_code_role_info"));
175 $this->
form->addItem($role);
179 foreach ($this->registration_settings->getAllowedDomains() as $item) {
184 if (count($domains)) {
185 $mail_obj = $this->
form->getItemByPostVar(
'usr_email');
186 $mail_obj->setInfo(sprintf(
187 $this->
lng->txt(
"reg_email_domains"),
188 implode(
", ", $domains)
190 ($this->code_enabled ? $this->
lng->txt(
"reg_email_domains_code") :
""));
195 $mail_obj = $this->
form->getItemByPostVar(
'usr_email');
197 $mail_obj->setRequired(
true);
202 array_map($this->
form->addItem(...), $DIC[
'legalDocuments']->selfRegistration()->legacyInputGUIs());
204 $this->
form->addCommandButton(
"saveForm", $this->
lng->txt(
"register"));
210 $form_valid = $this->
form->checkInput();
213 $valid_code = $valid_role =
false;
216 if ($this->code_enabled) {
217 $code = $this->
form->getInput(
'usr_registration_code');
221 $this->registration_settings->registrationCodeRequired()
225 $code_obj = $this->
form->getItemByPostVar(
'usr_registration_code');
226 $code_obj->setAlert($this->
lng->txt(
'registration_code_not_valid'));
233 if ($role_id && $this->rbacreview->isGlobalRole($role_id)) {
234 $valid_role = $role_id;
243 $email = $this->
form->getInput(
"usr_email");
247 foreach ($this->registration_settings->getAllowedDomains() as $item) {
252 if (count($domains)) {
254 foreach ($domains as $domain) {
255 $domain = str_replace(
"*",
"~~~", $domain);
256 $domain = preg_quote($domain,
'/');
257 $domain = str_replace(
"~~~",
".+", $domain);
258 if (preg_match(
"/^" . $domain .
"$/", $email, $hit)) {
264 $mail_obj = $this->
form->getItemByPostVar(
'usr_email');
265 $mail_obj->setAlert(sprintf(
266 $this->
lng->txt(
"reg_email_domains"),
267 implode(
", ", $domains)
277 !$this->registration_settings->passwordGenerationEnabled() &&
279 $this->form->getInput(
'password'),
280 $this->form->getInput(
'username'),
284 $passwd_obj = $this->
form->getItemByPostVar(
'password');
285 $passwd_obj->setAlert($this->
lng->txt($error_lng_var));
290 $form_valid =
$DIC[
'legalDocuments']->selfRegistration()->saveLegacyForm($this->
form) && $form_valid;
295 if ($this->registration_settings->roleSelectionEnabled()) {
296 $selected_role = $this->
form->getInput(
"usr_roles");
298 $valid_role = (
int) $selected_role;
303 $valid_role = $registration_role_assignments->getRoleByEmail($this->
form->getInput(
"usr_email"));
308 if (!$valid_role && (!isset($selected_role) || $selected_role !==
'')) {
309 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"registration_no_valid_role"));
314 $login_obj = $this->
form->getItemByPostVar(
'username');
315 $login = $this->
form->getInput(
"username");
317 $login_obj->setAlert($this->
lng->txt(
"login_invalid"));
322 $username_checked_and_register_callback =
function () use (&$form_valid, $login, $login_obj, $valid_role) {
325 $login_obj->setAlert($this->
lng->txt(
'login_exists'));
327 } elseif ($this->user_profile->userFieldEditableByUser(Alias::class) &&
328 (
int) $this->settings->get(
'reuse_of_loginnames') === 0 &&
330 $login_obj->setAlert($this->
lng->txt(
'login_exists'));
341 if (($register_duration = $this->
settings->get(
'registration_duration')) !==
null) {
342 $duration = $this->
http->durations()->callbackDuration((
int) $register_duration);
343 $duration->stretch($username_checked_and_register_callback);
345 $username_checked_and_register_callback();
349 return $this->
login();
352 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
353 $this->
form->setValuesByPost();
363 $ilias =
$DIC[
'ilias'];
364 $ilias->raiseError(
"Invalid role selection in registration" .
365 ", IP: " .
$_SERVER[
"REMOTE_ADDR"], $ilias->error_obj->FATAL);
370 $this->userObj->setAuthMode(
'local');
373 $this->userObj = $this->user_profile->addFormValuesToUser(
375 Context::Registration,
378 $this->userObj->setTitle($this->userObj->getFullname());
379 $this->userObj->setDescription($this->userObj->getEmail());
381 $this->userObj->setLogin(
382 $this->
form->getInput(
'username')
385 if ($this->registration_settings->passwordGenerationEnabled()) {
387 $password = $password[0];
389 $password = $this->
form->getInput(
"password");
392 $this->userObj->setLanguage(
393 $this->user_settings->getValueFromLegacyFormByDefinitionClass(
394 LanguageSetting::class,
399 $this->userObj->setPasswd($password);
401 $access_limit =
null;
403 $this->code_was_used =
false;
404 $code_has_access_limit =
false;
405 $code_local_roles = [];
406 if ($this->code_enabled) {
407 $code_local_roles = $code_has_access_limit =
null;
410 $code = $this->
form->getInput(
'usr_registration_code');
414 $this->code_was_used =
true;
418 if ($code_data[
"role_local"]) {
420 $code_local_roles = explode(
";", $code_data[
"role_local"]);
422 if ($code_data[
"alimit"]) {
424 $code_has_access_limit =
true;
426 switch ($code_data[
"alimit"]) {
428 $abs = date_parse($code_data[
"alimitdt"]);
429 $access_limit = mktime(23, 59, 59, $abs[
'month'], $abs[
'day'], $abs[
'year']);
433 $rel = unserialize($code_data[
"alimitdt"], [
'allowed_classes' =>
false]);
434 $access_limit = (
int) ($rel[
"d"] * 86400 + $rel[
"m"] * 2592000 + $rel[
"y"] * 31536000 + time());
442 if (!($this->code_was_used && $code_has_access_limit) &&
443 $this->registration_settings->getAccessLimitation()) {
445 switch ($access_limitations_obj->getMode($a_role)) {
447 $access_limit = $access_limitations_obj->getAbsolute($a_role);
451 $rel_d = $access_limitations_obj->getRelative($a_role,
'd');
452 $rel_m = $access_limitations_obj->getRelative($a_role,
'm');
453 $access_limit = $rel_d * 86400 + $rel_m * 2592000 + time();
459 $this->userObj->setTimeLimitUnlimited(
false);
460 $this->userObj->setTimeLimitUntil($access_limit);
462 $this->userObj->setTimeLimitUnlimited(
true);
463 $this->userObj->setTimeLimitUntil(time());
466 $this->userObj->setTimeLimitFrom(time());
470 $this->userObj->create();
474 $this->code_was_used) {
475 $this->userObj->setActive(
true, 0);
477 $this->userObj->setActive(
false, 0);
479 $this->userObj->setActive(
false, 0);
484 $this->userObj->setLastPasswordChangeTS(time());
486 $this->userObj->setIsSelfRegistered(
true);
489 $this->userObj->saveAsNew();
492 $this->userObj->updateOwner();
495 $this->userObj->setLanguage($this->
form->getInput(
'usr_language'));
498 $DIC[
'legalDocuments']->selfRegistration()->userCreation($this->userObj);
500 if ($this->
http->wrapper()->query()->has(
'target')) {
501 $this->userObj->setPref(
503 $this->
http->wrapper()->query()->retrieve(
505 $this->refinery->kindlyTo()->string()
509 $this->userObj->setPref(
'bs_allow_to_contact_me', $this->
settings->get(
'bs_allow_to_contact_me',
'n'));
510 $this->userObj->setPref(
'chat_osc_accept_msg', $this->
settings->get(
'chat_osc_accept_msg',
'n'));
511 $this->userObj->setPref(
'chat_broadcast_typing', $this->
settings->get(
'chat_broadcast_typing',
'n'));
512 $this->userObj->writePrefs();
514 $this->rbacadmin->assignUser($a_role, $this->userObj->getId());
517 if ($this->code_was_used && is_array($code_local_roles)) {
518 $code_local_roles = array_map(intval(...), array_unique($code_local_roles));
519 foreach ($code_local_roles as $local_role_obj_id) {
522 $this->rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId());
525 $role_obj =
$GLOBALS[
'DIC'][
'rbacreview']->getObjectOfRole($local_role_obj_id);
530 $role_ref = end($role_refs);
540 return (
string) $password;
546 if ($this->registration_settings->getApproveRecipients()) {
549 if (!$this->code_was_used &&
555 $mail->setRecipients($this->registration_settings->getApproveRecipients());
556 $mail->setAdditionalInformation([
'usr' => $this->userObj]);
561 if (!$this->code_was_used &&
565 $mail->setRecipients([$this->userObj]);
566 $mail->setAdditionalInformation(
568 'usr' => $this->userObj,
569 'hash_lifetime' => $this->registration_settings->getRegistrationHashLifetime()
575 $this->registration_settings,
577 new NewAccountMailRepository($this->db)
579 $accountMail->withDirectRegistrationMode()->send($this->userObj, $password, $this->code_was_used);
586 $this->tpl->setVariable(
'TXT_PAGEHEADLINE', $this->
lng->txt(
'registration'));
588 $tpl->
setVariable(
"TXT_WELCOME", $this->
lng->txt(
"welcome") .
", " . $this->userObj->getTitle() .
"!");
595 !$this->registration_settings->passwordGenerationEnabled()
599 $login_link = $this->ui_renderer->render(
600 $this->ui_factory->link()->standard(
601 $this->lng->txt(
'login_to_ilias'),
602 './login.php?cmd=force_login&lang=' . $this->userObj->getLanguage()
609 $tpl->
setVariable(
'TXT_REGISTERED', $this->
lng->txt(
'reg_confirmation_link_successful'));
611 $tpl->
setVariable(
'TXT_REGISTERED', $this->
lng->txt(
'txt_registered_passw_gen'));
619 $field->setTitle($this->
lng->txt(
'login_data'));
620 $this->
form->addItem($field);
623 $login_input->setSize(255);
624 $login_input->setRequired(
true);
625 $this->
form->addItem($login_input);
627 if ($this->registration_settings->passwordGenerationEnabled()) {
629 $password_input->setValue($this->
lng->txt(
'reg_passwd_via_mail'));
630 $this->
form->addItem($password_input);
635 $password_input->setUseStripSlashes(
false);
636 $password_input->setRequired(
true);
638 $this->
form->addItem($password_input);
645 $options[$role[
'id']] = $role[
'title'];
648 if ($options === []) {
652 if (count($options) === 1) {
654 $keys = array_keys($options);
655 $roles_input->setValue((
string) array_shift($keys));
659 $options_with_empty_value = [
'' => $this->
lng->txt(
'please_choose')] + $options;
661 $roles_input->setOptions($options_with_empty_value);
662 $roles_input->setRequired(
true);
Builds a Color from either hex- or rgb values.
Class 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 for mime mail registration notifications.
const TYPE_NOTIFICATION_ACTIVATION
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( $class_path, string $cmd, string $submit_caption="")