ILIAS  trunk Revision v5.2.0beta1-34115-g3a2438be29
ilAccountRegistrationGUI Class Reference

Class ilAccountRegistrationGUI. More...

+ Collaboration diagram for ilAccountRegistrationGUI:

Public Member Functions

 __construct ()
 
 executeCommand ()
 
 displayForm ()
 
 saveForm ()
 
 login ()
 

Protected Member Functions

 initForm ()
 
 createUser (int $a_role)
 
 distributeMails (string $password)
 
 doProfileAutoComplete ()
 

Protected Attributes

ilRegistrationSettings $registration_settings
 
bool $code_enabled = false
 
bool $code_was_used
 
ilRecommendedContentManager $recommended_content_manager
 
ilUserProfile $user_profile
 
ilPropertyFormGUI $form = null
 
ilGlobalTemplateInterface $tpl
 
ilCtrlInterface $ctrl
 
ilLanguage $lng
 
ilErrorHandling $error
 
ilObjUser $userObj = null
 
ilObjUser $globalUser
 
ilSetting $settings
 
ilRbacReview $rbacreview
 
ilRbacAdmin $rbacadmin
 
ILIAS UI Factory $ui_factory
 
ILIAS UI Renderer $ui_renderer
 
ILIAS Refinery Factory $refinery
 
ILIAS HTTP Services $http
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAccountRegistrationGUI::__construct ( )

Definition at line 52 of file class.ilAccountRegistrationGUI.php.

References $DIC, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ILIAS\Repository\settings().

53  {
54  global $DIC;
55 
56  $this->tpl = $DIC->ui()->mainTemplate();
57 
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'];
63  $this->settings = $DIC->settings();
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();
69 
70  $this->registration_settings = new ilRegistrationSettings();
71  $this->code_enabled = ($this->registration_settings->registrationCodeRequired() ||
72  $this->registration_settings->getAllowCodes());
73 
74  $this->recommended_content_manager = new ilRecommendedContentManager();
75 
76  $this->user_profile = new ilUserProfile();
77 
78  $this->http = $DIC->http();
79  $this->refinery = $DIC->refinery();
80  }
Class ilUserProfile.
static http()
Fetches the global http state from ILIAS.
$DIC
Definition: xapitoken.php:62
Class ilObjAuthSettingsGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

Member Function Documentation

◆ createUser()

ilAccountRegistrationGUI::createUser ( int  $a_role)
protected

Definition at line 349 of file class.ilAccountRegistrationGUI.php.

References $_SERVER, $code_was_used, $DIC, Vendor\Package\$f, $GLOBALS, ilObject\_getAllReferences(), ilUserDefinedFields\_getInstance(), ilObject\_lookupType(), ilUserCreationContext\CONTEXT_REGISTRATION, ILIAS\Repository\form(), ilSecuritySettingsChecker\generatePasswords(), ilRegistrationCode\getCodeData(), ilUserCreationContext\getInstance(), ILIAS\FileDelivery\http(), ilRegistrationSettings\IL_REG_ACTIVATION, ilRegistrationSettings\IL_REG_CODES, ilRegistrationSettings\IL_REG_DIRECT, ILIAS\Repository\int(), ILIAS\Repository\refinery(), ILIAS\Repository\settings(), and ilRegistrationCode\useCode().

Referenced by saveForm().

349  : string
350  {
351  // something went wrong with the form validation
352  if (!$a_role) {
353  global $DIC;
354 
355  $ilias = $DIC['ilias'];
356  $ilias->raiseError("Invalid role selection in registration" .
357  ", IP: " . $_SERVER["REMOTE_ADDR"], $ilias->error_obj->FATAL);
358  }
359 
360  $this->userObj = new ilObjUser();
361 
362  $this->user_profile->skipGroup("preferences");
363  $this->user_profile->skipGroup("settings");
364  $this->user_profile->skipField("password");
365  $this->user_profile->skipField("birthday");
366  $this->user_profile->skipField("upload");
367  foreach ($this->user_profile->getStandardFields() as $k => $v) {
368  if ($v["method"]) {
369  $method = "set" . substr($v["method"], 3);
370  if (method_exists($this->userObj, $method)) {
371  if ($k !== "username") {
372  $k = "usr_" . $k;
373  }
374  $field_obj = $this->form->getItemByPostVar($k);
375  if ($field_obj) {
376  $this->userObj->$method($this->form->getInput($k));
377  }
378  }
379  }
380  }
381 
382  $this->userObj->setFullName();
383 
384  $birthday_obj = $this->form->getItemByPostVar("usr_birthday");
385  if ($birthday_obj) {
386  $birthday = $this->form->getInput("usr_birthday");
387  $this->userObj->setBirthday($birthday);
388  }
389 
390  $this->userObj->setTitle($this->userObj->getFullname());
391  $this->userObj->setDescription($this->userObj->getEmail());
392 
393  if ($this->registration_settings->passwordGenerationEnabled()) {
395  $password = $password[0];
396  } else {
397  $password = $this->form->getInput("usr_password");
398  }
399  $this->userObj->setPasswd($password);
400 
401  // Set user defined data
402  $user_defined_fields = ilUserDefinedFields::_getInstance();
403  $defs = $user_defined_fields->getRegistrationDefinitions();
404  $udf = [];
405  foreach ($defs as $definition) {
406  $f = "udf_" . $definition['field_id'];
407  $item = $this->form->getItemByPostVar($f);
408  if ($item && !$item->getDisabled()) {
409  $udf[$definition['field_id']] = $this->form->getInput($f);
410  }
411  }
412  $this->userObj->setUserDefinedData($udf);
413 
414  $this->userObj->setTimeLimitOwner(7);
415 
416  $access_limit = null;
417 
418  $this->code_was_used = false;
419  $code_has_access_limit = false;
420  $code_local_roles = [];
421  if ($this->code_enabled) {
422  $code_local_roles = $code_has_access_limit = null;
423 
424  // #10853 - could be optional
425  $code = $this->form->getInput('usr_registration_code');
426  if ($code) {
427  // set code to used
429  $this->code_was_used = true;
430 
431  // handle code attached local role(s) and access limitation
432  $code_data = ilRegistrationCode::getCodeData($code);
433  if ($code_data["role_local"]) {
434  // need user id before we can assign role(s)
435  $code_local_roles = explode(";", $code_data["role_local"]);
436  }
437  if ($code_data["alimit"]) {
438  // see below
439  $code_has_access_limit = true;
440 
441  switch ($code_data["alimit"]) {
442  case "absolute":
443  $abs = date_parse($code_data["alimitdt"]);
444  $access_limit = mktime(23, 59, 59, $abs['month'], $abs['day'], $abs['year']);
445  break;
446 
447  case "relative":
448  $rel = unserialize($code_data["alimitdt"], ['allowed_classes' => false]);
449  $access_limit = (int) ($rel["d"] * 86400 + $rel["m"] * 2592000 + $rel["y"] * 31536000 + time());
450  break;
451  }
452  }
453  }
454  }
455 
456  // code access limitation will override any other access limitation setting
457  if (!($this->code_was_used && $code_has_access_limit) &&
458  $this->registration_settings->getAccessLimitation()) {
459  $access_limitations_obj = new ilRegistrationRoleAccessLimitations();
460  switch ($access_limitations_obj->getMode($a_role)) {
461  case 'absolute':
462  $access_limit = $access_limitations_obj->getAbsolute($a_role);
463  break;
464 
465  case 'relative':
466  $rel_d = $access_limitations_obj->getRelative($a_role, 'd');
467  $rel_m = $access_limitations_obj->getRelative($a_role, 'm');
468  $access_limit = $rel_d * 86400 + $rel_m * 2592000 + time();
469  break;
470  }
471  }
472 
473  if ($access_limit) {
474  $this->userObj->setTimeLimitUnlimited(false);
475  $this->userObj->setTimeLimitUntil($access_limit);
476  } else {
477  $this->userObj->setTimeLimitUnlimited(true);
478  $this->userObj->setTimeLimitUntil(time());
479  }
480 
481  $this->userObj->setTimeLimitFrom(time());
482 
484 
485  $this->userObj->create();
486 
487  if ($this->registration_settings->getRegistrationType() === ilRegistrationSettings::IL_REG_DIRECT ||
488  $this->registration_settings->getRegistrationType() === ilRegistrationSettings::IL_REG_CODES ||
490  $this->userObj->setActive(true, 0);
491  } elseif ($this->registration_settings->getRegistrationType() === ilRegistrationSettings::IL_REG_ACTIVATION) {
492  $this->userObj->setActive(false, 0);
493  } else {
494  $this->userObj->setActive(false, 0);
495  }
496 
497  // set a timestamp for last_password_change
498  // this ts is needed by ilSecuritySettings
499  $this->userObj->setLastPasswordChangeTS(time());
500 
501  $this->userObj->setIsSelfRegistered(true);
502 
503  //insert user data in table user_data
504  $this->userObj->saveAsNew();
505 
506  // don't update owner before the first save. updateOwner rereads the object which fails if it not save before
507  $this->userObj->updateOwner();
508 
509  // setup user preferences
510  $this->userObj->setLanguage($this->form->getInput('usr_language'));
511 
512  global $DIC;
513  $DIC['legalDocuments']->selfRegistration()->userCreation($this->userObj);
514 
515  $hits_per_page = $this->settings->get("hits_per_page");
516  if ($hits_per_page < 10) {
517  $hits_per_page = 10;
518  }
519  $this->userObj->setPref("hits_per_page", $hits_per_page);
520  if ($this->http->wrapper()->query()->has('target')) {
521  $this->userObj->setPref(
522  'reg_target',
523  $this->http->wrapper()->query()->retrieve(
524  'target',
525  $this->refinery->kindlyTo()->string()
526  )
527  );
528  }
529  $this->userObj->setPref('bs_allow_to_contact_me', $this->settings->get('bs_allow_to_contact_me', 'n'));
530  $this->userObj->setPref('chat_osc_accept_msg', $this->settings->get('chat_osc_accept_msg', 'n'));
531  $this->userObj->setPref('chat_broadcast_typing', $this->settings->get('chat_broadcast_typing', 'n'));
532  $this->userObj->writePrefs();
533 
534  $this->rbacadmin->assignUser($a_role, $this->userObj->getId());
535 
536  // local roles from code
537  if ($this->code_was_used && is_array($code_local_roles)) {
538  foreach (array_unique($code_local_roles) as $local_role_obj_id) {
539  // is given role (still) valid?
540  if (ilObject::_lookupType($local_role_obj_id) === "role") {
541  $this->rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId());
542 
543  // patch to remove for 45 due to mantis 21953
544  $role_obj = $GLOBALS['DIC']['rbacreview']->getObjectOfRole($local_role_obj_id);
545  switch (ilObject::_lookupType($role_obj)) {
546  case 'crs':
547  case 'grp':
548  $role_refs = ilObject::_getAllReferences($role_obj);
549  $role_ref = end($role_refs);
550  // deactivated for now, see discussion at
551  // https://docu.ilias.de/goto_docu_wiki_wpage_5620_1357.html
552  // $this->recommended_content_manager->addObjectRecommendation($this->userObj->getId(), $role_ref);
553  break;
554  }
555  }
556  }
557  }
558 
559  return (string) $password;
560  }
static _getAllReferences(int $id)
get all reference ids for object ID
static getCodeData(string $code)
static http()
Fetches the global http state from ILIAS.
$GLOBALS["DIC"]
Definition: wac.php:31
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
$DIC
Definition: xapitoken.php:62
Class class.ilRegistrationAccessLimitation.
static generatePasswords(int $a_number)
Generate a number of passwords.
form( $class_path, string $cmd, string $submit_caption="")
static useCode(string $code)
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ displayForm()

ilAccountRegistrationGUI::displayForm ( )

Definition at line 101 of file class.ilAccountRegistrationGUI.php.

References $tpl, ILIAS\Repository\form(), initForm(), ilStartUpGUI\initStartUpTemplate(), ILIAS\Repository\lng(), and ilGlobalTemplateInterface\setVariable().

Referenced by executeCommand(), and saveForm().

102  {
103  $tpl = ilStartUpGUI::initStartUpTemplate(['tpl.usr_registration.html', 'components/ILIAS/Registration'], true);
104  $tpl->setVariable('TXT_PAGEHEADLINE', $this->lng->txt('registration'));
105 
106  if (!$this->form) {
107  $this->initForm();
108  }
109  $tpl->setVariable('FORM', $this->form->getHTML());
110  return $tpl;
111  }
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...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
form( $class_path, string $cmd, string $submit_caption="")
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ distributeMails()

ilAccountRegistrationGUI::distributeMails ( string  $password)
protected

Definition at line 562 of file class.ilAccountRegistrationGUI.php.

References ilLoggerFactory\getLogger(), ilRegistrationSettings\IL_REG_ACTIVATION, ilRegistrationSettings\IL_REG_APPROVE, ILIAS\Repository\lng(), ilRegistrationMimeMailNotification\TYPE_NOTIFICATION_ACTIVATION, ilRegistrationMailNotification\TYPE_NOTIFICATION_APPROVERS, and ilRegistrationMailNotification\TYPE_NOTIFICATION_CONFIRMATION.

Referenced by saveForm().

562  : void
563  {
564  // Send mail to approvers, if they are defined
565  if ($this->registration_settings->getApproveRecipients()) {
566  $mail = new ilRegistrationMailNotification();
567 
568  if (!$this->code_was_used &&
569  $this->registration_settings->getRegistrationType() === ilRegistrationSettings::IL_REG_APPROVE) {
571  } else {
573  }
574  $mail->setRecipients($this->registration_settings->getApproveRecipients());
575  $mail->setAdditionalInformation(['usr' => $this->userObj]);
576  $mail->send();
577  }
578  // Send mail to new user
579  // Registration with confirmation link ist enabled
580  if (!$this->code_was_used &&
581  $this->registration_settings->getRegistrationType() === ilRegistrationSettings::IL_REG_ACTIVATION) {
584  $mail->setRecipients([$this->userObj]);
585  $mail->setAdditionalInformation(
586  [
587  'usr' => $this->userObj,
588  'hash_lifetime' => $this->registration_settings->getRegistrationHashLifetime()
589  ]
590  );
591  $mail->send();
592  } else {
593  $accountMail = new ilAccountRegistrationMail(
594  $this->registration_settings,
595  $this->lng,
597  );
598  $accountMail->withDirectRegistrationMode()->send($this->userObj, $password, $this->code_was_used);
599  }
600  }
Class for mime mail registration notifications.
static getLogger(string $a_component_id)
Get component logger.
Class ilAccountRegistrationMail.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doProfileAutoComplete()

ilAccountRegistrationGUI::doProfileAutoComplete ( )
protected

Definition at line 635 of file class.ilAccountRegistrationGUI.php.

References exit, and ilPublicUserProfileGUI\getAutocompleteResult().

635  : void
636  {
637  $field_id = (string) $_REQUEST["f"];
638  $term = (string) $_REQUEST["term"];
639 
640  $result = ilPublicUserProfileGUI::getAutocompleteResult($field_id, $term);
641  if (count($result)) {
642  echo json_encode($result, JSON_THROW_ON_ERROR);
643  }
644 
645  exit();
646  }
static getAutocompleteResult(string $a_field_id, string $a_term)
+ Here is the call graph for this function:

◆ executeCommand()

ilAccountRegistrationGUI::executeCommand ( )

Definition at line 82 of file class.ilAccountRegistrationGUI.php.

References ILIAS\Repository\ctrl(), displayForm(), ilRegistrationSettings\IL_REG_DISABLED, ILIAS\Repository\lng(), and ilStartUpGUI\printToGlobalTemplate().

82  : void
83  {
84  if ($this->registration_settings->getRegistrationType() === ilRegistrationSettings::IL_REG_DISABLED) {
85  $this->error->raiseError($this->lng->txt('reg_disabled'), $this->error->FATAL);
86  }
87 
88  $cmd = $this->ctrl->getCmd();
89  switch ($cmd) {
90  case 'saveForm':
91  $tpl = $this->$cmd();
92  break;
93  default:
94  $tpl = $this->displayForm();
95  }
96 
97  $this->tpl->setPermanentLink('usr', null, 'registration');
99  }
static printToGlobalTemplate($tpl)
+ Here is the call graph for this function:

◆ initForm()

ilAccountRegistrationGUI::initForm ( )
protected

Definition at line 113 of file class.ilAccountRegistrationGUI.php.

References $DIC, ilUserDefinedFields\_getInstance(), ANONYMOUS_USER_ID, ilRegistrationCode\CODE_LENGTH, ILIAS\Repository\ctrl(), ILIAS\Repository\form(), ilCustomUserFieldsHelper\getInstance(), ilRegistrationSettings\IL_REG_ACTIVATION, iljQueryUtil\initjQuery(), ILIAS\Repository\lng(), and ilUserProfile\MODE_REGISTRATION.

Referenced by displayForm(), and saveForm().

113  : void
114  {
115  $this->globalUser->setLanguage($this->lng->getLangKey());
116  $this->globalUser->setId(ANONYMOUS_USER_ID);
117 
118  // needed for multi-text-fields (interests)
120 
121  $this->form = new ilPropertyFormGUI();
122  $this->form->setFormAction($this->ctrl->getFormAction($this));
123 
124  // code handling
125  if ($this->code_enabled) {
126  $field = new ilFormSectionHeaderGUI();
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");
130  $code->setSize(40);
131  $code->setMaxLength(ilRegistrationCode::CODE_LENGTH);
132  if ($this->registration_settings->registrationCodeRequired()) {
133  $code->setRequired(true);
134  $code->setInfo($this->lng->txt("registration_code_required_info"));
135  } else {
136  $code->setInfo($this->lng->txt("registration_code_optional_info"));
137  }
138  $this->form->addItem($code);
139  }
140 
141  // user defined fields
142  $user_defined_data = $this->globalUser->getUserDefinedData();
143  $user_defined_fields = ilUserDefinedFields::_getInstance();
144  $custom_fields = [];
145 
146  foreach ($user_defined_fields->getRegistrationDefinitions() as $field_id => $definition) {
147  $fprop = ilCustomUserFieldsHelper::getInstance()->getFormPropertyForDefinition(
148  $definition,
149  true,
150  $user_defined_data['f_' . $field_id] ?? ''
151  );
152  if ($fprop instanceof ilFormPropertyGUI) {
153  $custom_fields['udf_' . $definition['field_id']] = $fprop;
154  }
155  }
156 
157  $this->user_profile->setMode(ilUserProfile::MODE_REGISTRATION);
158  $this->user_profile->skipGroup("preferences");
159 
160  $this->user_profile->setAjaxCallback(
161  $this->ctrl->getLinkTarget($this, 'doProfileAutoComplete', '', true)
162  );
163  $this->lng->loadLanguageModule("user");
164  // add fields to form
165  $this->user_profile->addStandardFieldsToForm($this->form, null, $custom_fields);
166  unset($custom_fields);
167 
168  // set language selection to current display language
169  $flang = $this->form->getItemByPostVar("usr_language");
170  if ($flang) {
171  $flang->setValue($this->lng->getLangKey());
172  }
173 
174  // add information to role selection (if not hidden)
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"));
179  }
180  }
181 
182  // #11407
183  $domains = [];
184  foreach ($this->registration_settings->getAllowedDomains() as $item) {
185  if (trim($item)) {
186  $domains[] = $item;
187  }
188  }
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)
194  ) . "<br />" .
195  ($this->code_enabled ? $this->lng->txt("reg_email_domains_code") : ""));
196  }
197 
198  // #14272
199  if ($this->registration_settings->getRegistrationType() === ilRegistrationSettings::IL_REG_ACTIVATION) {
200  $mail_obj = $this->form->getItemByPostVar('usr_email');
201  if ($mail_obj) { // #16087
202  $mail_obj->setRequired(true);
203  }
204  }
205 
206  global $DIC;
207  array_map($this->form->addItem(...), $DIC['legalDocuments']->selfRegistration()->legacyInputGUIs());
208 
209  $this->form->addCommandButton("saveForm", $this->lng->txt("register"));
210  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
$DIC
Definition: xapitoken.php:62
form( $class_path, string $cmd, string $submit_caption="")
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ login()

ilAccountRegistrationGUI::login ( )

Definition at line 602 of file class.ilAccountRegistrationGUI.php.

References $code_was_used, $tpl, ilRegistrationSettings\IL_REG_ACTIVATION, ilRegistrationSettings\IL_REG_APPROVE, ilRegistrationSettings\IL_REG_CODES, ilRegistrationSettings\IL_REG_DIRECT, ilStartUpGUI\initStartUpTemplate(), ILIAS\Repository\lng(), and ilGlobalTemplateInterface\setVariable().

Referenced by saveForm().

603  {
604  $tpl = ilStartUpGUI::initStartUpTemplate(['tpl.usr_registered.html', 'components/ILIAS/Registration'], false);
605  $this->tpl->setVariable('TXT_PAGEHEADLINE', $this->lng->txt('registration'));
606 
607  $tpl->setVariable("TXT_WELCOME", $this->lng->txt("welcome") . ", " . $this->userObj->getTitle() . "!");
608  if (
609  (
610  $this->registration_settings->getRegistrationType() === ilRegistrationSettings::IL_REG_DIRECT ||
611  $this->registration_settings->getRegistrationType() === ilRegistrationSettings::IL_REG_CODES ||
613  ) &&
614  !$this->registration_settings->passwordGenerationEnabled()
615  ) {
616  $tpl->setVariable('TXT_REGISTERED', $this->lng->txt('txt_registered'));
617 
618  $login_link = $this->ui_renderer->render(
619  $this->ui_factory->link()->standard(
620  $this->lng->txt('login_to_ilias'),
621  './login.php?cmd=force_login&lang=' . $this->userObj->getLanguage()
622  )
623  );
624  $tpl->setVariable('LOGIN_LINK', $login_link);
625  } elseif ($this->registration_settings->getRegistrationType() === ilRegistrationSettings::IL_REG_APPROVE) {
626  $tpl->setVariable('TXT_REGISTERED', $this->lng->txt('txt_submitted'));
627  } elseif ($this->registration_settings->getRegistrationType() === ilRegistrationSettings::IL_REG_ACTIVATION) {
628  $tpl->setVariable('TXT_REGISTERED', $this->lng->txt('reg_confirmation_link_successful'));
629  } else {
630  $tpl->setVariable('TXT_REGISTERED', $this->lng->txt('txt_registered_passw_gen'));
631  }
632  return $tpl;
633  }
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...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveForm()

ilAccountRegistrationGUI::saveForm ( )

Definition at line 212 of file class.ilAccountRegistrationGUI.php.

References $DIC, ilObjUser\_doesLoginnameExistInHistory(), ilObjUser\_loginExists(), ilObjRole\_lookupAllowRegister(), createUser(), displayForm(), distributeMails(), ILIAS\Repository\form(), ilRegistrationCode\getCodeRole(), initForm(), ILIAS\Repository\int(), ilUtil\isLogin(), ilSecuritySettingsChecker\isPasswordValidForUserContext(), ilRegistrationCode\isValidRegistrationCode(), ILIAS\Repository\lng(), login(), and ILIAS\Repository\settings().

213  {
214  $this->initForm();
215  $form_valid = $this->form->checkInput();
216 
217  // custom validation
218  $valid_code = $valid_role = false;
219 
220  // code
221  if ($this->code_enabled) {
222  $code = $this->form->getInput('usr_registration_code');
223  // could be optional
224  if (
225  $code !== '' ||
226  $this->registration_settings->registrationCodeRequired()
227  ) {
228  // code validation
230  $code_obj = $this->form->getItemByPostVar('usr_registration_code');
231  $code_obj->setAlert($this->lng->txt('registration_code_not_valid'));
232  $form_valid = false;
233  } else {
234  $valid_code = true;
235 
236  // get role from code, check if (still) valid
237  $role_id = ilRegistrationCode::getCodeRole($code);
238  if ($role_id && $this->rbacreview->isGlobalRole($role_id)) {
239  $valid_role = $role_id;
240  }
241  }
242  }
243  }
244 
245  // valid codes override email domain check
246  if (!$valid_code) {
247  // validate email against restricted domains
248  $email = $this->form->getInput("usr_email");
249  if ($email) {
250  // #10366
251  $domains = [];
252  foreach ($this->registration_settings->getAllowedDomains() as $item) {
253  if (trim($item)) {
254  $domains[] = $item;
255  }
256  }
257  if (count($domains)) {
258  $mail_valid = false;
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)) {
264  $mail_valid = true;
265  break;
266  }
267  }
268  if (!$mail_valid) {
269  $mail_obj = $this->form->getItemByPostVar('usr_email');
270  $mail_obj->setAlert(sprintf(
271  $this->lng->txt("reg_email_domains"),
272  implode(", ", $domains)
273  ));
274  $form_valid = false;
275  }
276  }
277  }
278  }
279 
280  $error_lng_var = '';
281  if (
282  !$this->registration_settings->passwordGenerationEnabled() &&
284  $this->form->getInput('usr_password'),
285  $this->form->getInput('username'),
286  $error_lng_var
287  )
288  ) {
289  $passwd_obj = $this->form->getItemByPostVar('usr_password');
290  $passwd_obj->setAlert($this->lng->txt($error_lng_var));
291  $form_valid = false;
292  }
293 
294  global $DIC;
295  $form_valid = $DIC['legalDocuments']->selfRegistration()->saveLegacyForm($this->form) && $form_valid;
296 
297  // no need if role is attached to code
298  if (!$valid_role) {
299  // manual selection
300  if ($this->registration_settings->roleSelectionEnabled()) {
301  $selected_role = $this->form->getInput("usr_roles");
302  if ($selected_role && ilObjRole::_lookupAllowRegister((int) $selected_role)) {
303  $valid_role = (int) $selected_role;
304  }
305  } // assign by email
306  else {
307  $registration_role_assignments = new ilRegistrationRoleAssignments();
308  $valid_role = $registration_role_assignments->getRoleByEmail($this->form->getInput("usr_email"));
309  }
310  }
311 
312  // no valid role could be determined
313  if (!$valid_role && (!isset($selected_role) || $selected_role !== '')) {
314  $this->tpl->setOnScreenMessage('info', $this->lng->txt("registration_no_valid_role"));
315  $form_valid = false;
316  }
317 
318  // validate username
319  $login_obj = $this->form->getItemByPostVar('username');
320  $login = $this->form->getInput("username");
321  if (!ilUtil::isLogin($login)) {
322  $login_obj->setAlert($this->lng->txt("login_invalid"));
323  $form_valid = false;
324  }
325 
326  if ($form_valid) {
327  if (ilObjUser::_loginExists($login)) {
328  $login_obj->setAlert($this->lng->txt("login_exists"));
329  $form_valid = false;
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'));
334  $form_valid = false;
335  }
336  }
337 
338  if (!$form_valid) {
339  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
340  } else {
341  $password = $this->createUser($valid_role);
342  $this->distributeMails($password);
343  return $this->login();
344  }
345  $this->form->setValuesByPost();
346  return $this->displayForm();
347  }
static getCodeRole(string $code)
Class class.ilregistrationEmailRoleAssignments.
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)
$DIC
Definition: xapitoken.php:62
static _doesLoginnameExistInHistory(string $a_login)
Checks whether the passed loginname already exists in history.
form( $class_path, string $cmd, string $submit_caption="")
static _lookupAllowRegister(int $a_role_id)
check whether role is allowed in user registration or not
+ Here is the call graph for this function:

Field Documentation

◆ $code_enabled

bool ilAccountRegistrationGUI::$code_enabled = false
protected

Definition at line 29 of file class.ilAccountRegistrationGUI.php.

◆ $code_was_used

bool ilAccountRegistrationGUI::$code_was_used
protected

Definition at line 30 of file class.ilAccountRegistrationGUI.php.

Referenced by createUser(), and login().

◆ $ctrl

ilCtrlInterface ilAccountRegistrationGUI::$ctrl
protected

Definition at line 38 of file class.ilAccountRegistrationGUI.php.

◆ $error

ilErrorHandling ilAccountRegistrationGUI::$error
protected

Definition at line 40 of file class.ilAccountRegistrationGUI.php.

◆ $form

ilPropertyFormGUI ilAccountRegistrationGUI::$form = null
protected

Definition at line 35 of file class.ilAccountRegistrationGUI.php.

◆ $globalUser

ilObjUser ilAccountRegistrationGUI::$globalUser
protected

Definition at line 42 of file class.ilAccountRegistrationGUI.php.

◆ $http

ILIAS HTTP Services ilAccountRegistrationGUI::$http
protected

Definition at line 50 of file class.ilAccountRegistrationGUI.php.

◆ $lng

ilLanguage ilAccountRegistrationGUI::$lng
protected

Definition at line 39 of file class.ilAccountRegistrationGUI.php.

◆ $rbacadmin

ilRbacAdmin ilAccountRegistrationGUI::$rbacadmin
protected

Definition at line 45 of file class.ilAccountRegistrationGUI.php.

◆ $rbacreview

ilRbacReview ilAccountRegistrationGUI::$rbacreview
protected

Definition at line 44 of file class.ilAccountRegistrationGUI.php.

◆ $recommended_content_manager

ilRecommendedContentManager ilAccountRegistrationGUI::$recommended_content_manager
protected

Definition at line 31 of file class.ilAccountRegistrationGUI.php.

◆ $refinery

ILIAS Refinery Factory ilAccountRegistrationGUI::$refinery
protected

Definition at line 49 of file class.ilAccountRegistrationGUI.php.

◆ $registration_settings

ilRegistrationSettings ilAccountRegistrationGUI::$registration_settings
protected

Definition at line 28 of file class.ilAccountRegistrationGUI.php.

◆ $settings

ilSetting ilAccountRegistrationGUI::$settings
protected

Definition at line 43 of file class.ilAccountRegistrationGUI.php.

◆ $tpl

ilGlobalTemplateInterface ilAccountRegistrationGUI::$tpl
protected

Definition at line 37 of file class.ilAccountRegistrationGUI.php.

Referenced by displayForm(), and login().

◆ $ui_factory

ILIAS UI Factory ilAccountRegistrationGUI::$ui_factory
protected

Definition at line 46 of file class.ilAccountRegistrationGUI.php.

◆ $ui_renderer

ILIAS UI Renderer ilAccountRegistrationGUI::$ui_renderer
protected

Definition at line 47 of file class.ilAccountRegistrationGUI.php.

◆ $user_profile

ilUserProfile ilAccountRegistrationGUI::$user_profile
protected

Definition at line 33 of file class.ilAccountRegistrationGUI.php.

◆ $userObj

ilObjUser ilAccountRegistrationGUI::$userObj = null
protected

Definition at line 41 of file class.ilAccountRegistrationGUI.php.


The documentation for this class was generated from the following file: