ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilAccountRegistrationGUI Class Reference

Class ilAccountRegistrationGUI. More...

+ Collaboration diagram for ilAccountRegistrationGUI:

Public Member Functions

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

Protected Member Functions

 __initForm ()
 
 __distributeMails ($password)
 
 doProfileAutoComplete ()
 

Protected Attributes

 $registration_settings
 
 $code_enabled
 
 $code_was_used
 
 $userObj
 
 $termsOfServiceEvaluation
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAccountRegistrationGUI::__construct ( )

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

References $DIC, $ilCtrl, $lng, and $tpl.

34  {
35  global $DIC;
36 
37  $ilCtrl = $DIC->ctrl();
38  $tpl = $DIC['tpl'];
39  $lng = $DIC->language();
40 
41  $this->tpl = &$tpl;
42 
43  $this->ctrl = &$ilCtrl;
44  $this->ctrl->saveParameter($this, 'lang');
45 
46  $this->lng = &$lng;
47  $this->lng->loadLanguageModule('registration');
48 
49  $this->registration_settings = new ilRegistrationSettings();
50 
51  $this->code_enabled = ($this->registration_settings->registrationCodeRequired() ||
52  $this->registration_settings->getAllowCodes());
53 
54  $this->termsOfServiceEvaluation = $DIC['tos.document.evaluator'];
55  }
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
global $ilCtrl
Definition: ilias.php:18
$lng

Member Function Documentation

◆ __distributeMails()

ilAccountRegistrationGUI::__distributeMails (   $password)
protected

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

References $code_was_used, $password, ilLoggerFactory\getLogger(), IL_REG_ACTIVATION, IL_REG_APPROVE, ilRegistrationMimeMailNotification\TYPE_NOTIFICATION_ACTIVATION, ilRegistrationMailNotification\TYPE_NOTIFICATION_APPROVERS, and ilRegistrationMailNotification\TYPE_NOTIFICATION_CONFIRMATION.

Referenced by saveForm().

622  {
623 
624  // Always send mail to approvers
625  if ($this->registration_settings->getRegistrationType() == IL_REG_APPROVE && !$this->code_was_used) {
626  $mail = new ilRegistrationMailNotification();
628  $mail->setRecipients($this->registration_settings->getApproveRecipients());
629  $mail->setAdditionalInformation(array('usr' => $this->userObj));
630  $mail->send();
631  } else {
632  $mail = new ilRegistrationMailNotification();
634  $mail->setRecipients($this->registration_settings->getApproveRecipients());
635  $mail->setAdditionalInformation(array('usr' => $this->userObj));
636  $mail->send();
637  }
638 
639  // Send mail to new user
640  // Registration with confirmation link ist enabled
641  if ($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION && !$this->code_was_used) {
642 
645  $mail->setRecipients(array($this->userObj));
646  $mail->setAdditionalInformation(
647  array(
648  'usr' => $this->userObj,
649  'hash_lifetime' => $this->registration_settings->getRegistrationHashLifetime()
650  )
651  );
652  $mail->send();
653  } else {
654  $accountMail = new ilAccountRegistrationMail(
655  $this->registration_settings,
656  $this->lng,
658  );
659  $accountMail->withDirectRegistrationMode()->send($this->userObj, $password, $this->code_was_used);
660  }
661  }
Class for mime mail registration notifications.
Class ilAccountRegistrationMail.
const IL_REG_ACTIVATION
$password
Definition: cron.php:14
static getLogger($a_component_id)
Get component logger.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __initForm()

ilAccountRegistrationGUI::__initForm ( )
protected

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

References $code, $DIC, $ilUser, ilUserDefinedFields\_getInstance(), ilRegistrationCode\CODE_LENGTH, ilCustomUserFieldsHelper\getInstance(), IL_REG_ACTIVATION, iljQueryUtil\initjQuery(), ilTermsOfServiceHelper\isEnabled(), ilUserProfile\MODE_REGISTRATION, and ilFormPropertyGUI\setRequired().

Referenced by displayForm(), and saveForm().

101  {
102  global $DIC;
103 
104  $ilUser = $DIC->user();
105 
106  $ilUser->setLanguage($this->lng->getLangKey());
107  $ilUser->setId(ANONYMOUS_USER_ID);
108 
109  // needed for multi-text-fields (interests)
111 
112  $this->form = new ilPropertyFormGUI();
113  $this->form->setFormAction($this->ctrl->getFormAction($this));
114 
115 
116  // code handling
117 
118  if ($this->code_enabled) {
119  $field = new ilFormSectionHeaderGUI();
120  $field->setTitle($this->lng->txt('registration_codes_type_reg'));
121  $this->form->addItem($field);
122  $code = new ilTextInputGUI($this->lng->txt("registration_code"), "usr_registration_code");
123  $code->setSize(40);
124  $code->setMaxLength(ilRegistrationCode::CODE_LENGTH);
125  if ((bool) $this->registration_settings->registrationCodeRequired()) {
126  $code->setRequired(true);
127  $code->setInfo($this->lng->txt("registration_code_required_info"));
128  } else {
129  $code->setInfo($this->lng->txt("registration_code_optional_info"));
130  }
131  $this->form->addItem($code);
132  }
133 
134 
135  // user defined fields
136  $user_defined_data = $ilUser->getUserDefinedData();
137 
138  $user_defined_fields = ilUserDefinedFields::_getInstance();
139  $custom_fields = array();
140 
141  foreach ($user_defined_fields->getRegistrationDefinitions() as $field_id => $definition) {
142  $fprop = ilCustomUserFieldsHelper::getInstance()->getFormPropertyForDefinition(
143  $definition,
144  true,
145  $user_defined_data['f_' . $field_id]
146  );
147  if ($fprop instanceof ilFormPropertyGUI) {
148  $custom_fields['udf_' . $definition['field_id']] = $fprop;
149  }
150  }
151 
152  // standard fields
153  $up = new ilUserProfile();
154  $up->setMode(ilUserProfile::MODE_REGISTRATION);
155  $up->skipGroup("preferences");
156 
157  $up->setAjaxCallback(
158  $this->ctrl->getLinkTarget($this, 'doProfileAutoComplete', '', true)
159  );
160 
161  $this->lng->loadLanguageModule("user");
162 
163  // add fields to form
164  $up->addStandardFieldsToForm($this->form, null, $custom_fields);
165  unset($custom_fields);
166 
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 = array();
184  foreach ($this->registration_settings->getAllowedDomains() as $item) {
185  if (trim($item)) {
186  $domains[] = $item;
187  }
188  }
189  if (sizeof($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() == 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  if (\ilTermsOfServiceHelper::isEnabled() && $this->termsOfServiceEvaluation->hasDocument()) {
207  $document = $this->termsOfServiceEvaluation->document();
208 
209  $field = new ilFormSectionHeaderGUI();
210  $field->setTitle($this->lng->txt('usr_agreement'));
211  $this->form->addItem($field);
212 
213  $field = new ilCustomInputGUI();
214  $field->setHTML('<div id="agreement">' . $document->content() . '</div>');
215  $this->form->addItem($field);
216 
217  $field = new ilCheckboxInputGUI($this->lng->txt('accept_usr_agreement'), 'accept_terms_of_service');
218  $field->setRequired(true);
219  $field->setValue(1);
220  $this->form->addItem($field);
221  }
222 
223 
224  if (ilCaptchaUtil::isActiveForRegistration()) {
225  $captcha = new ilCaptchaInputGUI($this->lng->txt("captcha_code"), 'captcha_code');
226  $captcha->setRequired(true);
227  $this->form->addItem($captcha);
228  }
229 
230  $this->form->addCommandButton("saveForm", $this->lng->txt("register"));
231  }
static _getInstance()
Get instance.
This class represents a property form user interface.
This class represents a captcha input in a property form.
global $DIC
Definition: saml.php:7
This class represents a section header in a property form.
$code
Definition: example_050.php:99
Class ilUserProfile.
This class represents a checkbox property in a property form.
const IL_REG_ACTIVATION
This class represents a text property in a property form.
$ilUser
Definition: imgupload.php:18
This class represents a custom property in a property form.
This class represents a property in a property form.
static initjQuery($a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
setRequired($a_required)
Set Required.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ displayForm()

ilAccountRegistrationGUI::displayForm ( )

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

References __initForm().

Referenced by executeCommand(), and saveForm().

89  {
90 
91  ilStartUpGUI::initStartUpTemplate(array('tpl.usr_registration.html', 'Services/Registration'), true);
92  $this->tpl->setVariable('TXT_PAGEHEADLINE', $this->lng->txt('registration'));
93 
94  if (!$this->form) {
95  $this->__initForm();
96  }
97  $this->tpl->setVariable('FORM', $this->form->getHTML());
98  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doProfileAutoComplete()

ilAccountRegistrationGUI::doProfileAutoComplete ( )
protected

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

References $result, ilJsonUtil\encode(), exit, and ilPublicUserProfileGUI\getAutocompleteResult().

715  {
716  $field_id = (string) $_REQUEST["f"];
717  $term = (string) $_REQUEST["term"];
718 
720  if (sizeof($result)) {
722  }
723 
724  exit();
725  }
$result
static getAutocompleteResult($a_field_id, $a_term)
static encode($mixed, $suppress_native=false)
exit
Definition: backend.php:16
+ Here is the call graph for this function:

◆ executeCommand()

ilAccountRegistrationGUI::executeCommand ( )

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

References $DIC, $ilErr, $tpl, displayForm(), and IL_REG_DISABLED.

58  {
59  global $DIC;
60 
61  $ilErr = $DIC['ilErr'];
62  $tpl = $DIC['tpl'];
63 
64  if ($this->registration_settings->getRegistrationType() == IL_REG_DISABLED) {
65  $ilErr->raiseError($this->lng->txt('reg_disabled'), $ilErr->FATAL);
66  }
67 
68  $next_class = $this->ctrl->getNextClass($this);
69  $cmd = $this->ctrl->getCmd();
70 
71  switch ($next_class) {
72  default:
73  if ($cmd) {
74  $this->$cmd();
75  } else {
76  $this->displayForm();
77  }
78  break;
79  }
80  $tpl->setPermanentLink('usr', null, 'registration');
81  $tpl->show();
82  return true;
83  }
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
$ilErr
Definition: raiseError.php:18
+ Here is the call graph for this function:

◆ login()

ilAccountRegistrationGUI::login ( )

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

References $code_was_used, $DIC, $f, IL_REG_ACTIVATION, IL_REG_APPROVE, IL_REG_CODES, and IL_REG_DIRECT.

Referenced by saveForm().

664  {
665  global $DIC;
666  $f = $DIC->ui()->factory();
667  $renderer = $DIC->ui()->renderer();
668 
669  ilStartUpGUI::initStartUpTemplate(array('tpl.usr_registered.html', 'Services/Registration'), false);
670  $this->tpl->setVariable('TXT_PAGEHEADLINE', $this->lng->txt('registration'));
671 
672  $this->tpl->setVariable("TXT_WELCOME", $this->lng->txt("welcome") . ", " . $this->userObj->getTitle() . "!");
673  if (
674  (
675  $this->registration_settings->getRegistrationType() == IL_REG_DIRECT ||
676  $this->registration_settings->getRegistrationType() == IL_REG_CODES ||
678  ) &&
679  !$this->registration_settings->passwordGenerationEnabled()
680  ) {
681  $this->tpl->setVariable('TXT_REGISTERED', $this->lng->txt('txt_registered'));
682 
683  $login_link = $renderer->render($f->link()->standard($this->lng->txt('login_to_ilias'), './login.php?cmd=force_login&lang=' . $this->userObj->getLanguage()));
684  $this->tpl->setVariable('LOGIN_LINK', $login_link);
685  } elseif ($this->registration_settings->getRegistrationType() == IL_REG_APPROVE) {
686  $this->tpl->setVariable('TXT_REGISTERED', $this->lng->txt('txt_submitted'));
687  } elseif ($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION) {
688  $this->tpl->setVariable('TXT_REGISTERED', $this->lng->txt('reg_confirmation_link_successful'));
689  } else {
690  $this->tpl->setVariable('TXT_REGISTERED', $this->lng->txt('txt_registered_passw_gen'));
691  }
692  }
global $DIC
Definition: saml.php:7
const IL_REG_ACTIVATION
+ Here is the caller graph for this function:

◆ saveForm()

ilAccountRegistrationGUI::saveForm ( )

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

References $_GET, $_POST, $_SERVER, $code, $code_was_used, $DIC, $domain, $email, $f, $GLOBALS, $ilSetting, $login, $map, $password, __distributeMails(), __initForm(), ilObjUser\_addDesktopItem(), ilObjUser\_doesLoginnameExistInHistory(), ilObject\_getAllReferences(), ilUserDefinedFields\_getInstance(), ilObjUser\_loginExists(), ilObjRole\_lookupAllowRegister(), ilObject\_lookupType(), ilUserCreationContext\CONTEXT_REGISTRATION, displayForm(), ilUtil\generatePasswords(), ilRegistrationCode\getCodeData(), ilRegistrationCode\getCodeRole(), ilUserCreationContext\getInstance(), ilSystemSupportContacts\getMailToAddress(), IL_REG_ACTIVATION, IL_REG_CODES, IL_REG_DIRECT, ilTermsOfServiceHelper\isEnabled(), ilUtil\isLogin(), ilUtil\isPasswordValidForUserContext(), ilRegistrationCode\isValidRegistrationCode(), login(), ilUserProfile\MODE_REGISTRATION, ilUtil\prepareFormOutput(), ilUtil\sendFailure(), ilUtil\sendInfo(), ilUtil\stripSlashes(), and ilRegistrationCode\useCode().

234  {
235  global $DIC;
236 
237  $ilSetting = $DIC->settings();
238  $rbacreview = $DIC->rbac()->review();
239 
240  $this->__initForm();
241  $form_valid = $this->form->checkInput();
242 
243  // custom validation
244  $valid_code = $valid_role = false;
245 
246  // code
247  if ($this->code_enabled) {
248  $code = $this->form->getInput('usr_registration_code');
249  // could be optional
250  if (
251  $this->registration_settings->registrationCodeRequired() ||
252  strlen($code)
253  ) {
254  // code validation
256  $code_obj = $this->form->getItemByPostVar('usr_registration_code');
257  $code_obj->setAlert($this->lng->txt('registration_code_not_valid'));
258  $form_valid = false;
259  } else {
260  $valid_code = true;
261 
262  // get role from code, check if (still) valid
263  $role_id = (int) ilRegistrationCode::getCodeRole($code);
264  if ($role_id && $rbacreview->isGlobalRole($role_id)) {
265  $valid_role = $role_id;
266  }
267  }
268  }
269  }
270 
271  // valid codes override email domain check
272  if (!$valid_code) {
273  // validate email against restricted domains
274  $email = $this->form->getInput("usr_email");
275  if ($email) {
276  // #10366
277  $domains = array();
278  foreach ($this->registration_settings->getAllowedDomains() as $item) {
279  if (trim($item)) {
280  $domains[] = $item;
281  }
282  }
283  if (sizeof($domains)) {
284  $mail_valid = false;
285  foreach ($domains as $domain) {
286  $domain = str_replace("*", "~~~", $domain);
287  $domain = preg_quote($domain);
288  $domain = str_replace("~~~", ".+", $domain);
289  if (preg_match("/^" . $domain . "$/", $email, $hit)) {
290  $mail_valid = true;
291  break;
292  }
293  }
294  if (!$mail_valid) {
295  $mail_obj = $this->form->getItemByPostVar('usr_email');
296  $mail_obj->setAlert(sprintf(
297  $this->lng->txt("reg_email_domains"),
298  implode(", ", $domains)
299  ));
300  $form_valid = false;
301  }
302  }
303  }
304  }
305 
306  $error_lng_var = '';
307  if (
308  !$this->registration_settings->passwordGenerationEnabled() &&
309  !ilUtil::isPasswordValidForUserContext($this->form->getInput('usr_password'), $this->form->getInput('username'), $error_lng_var)
310  ) {
311  $passwd_obj = $this->form->getItemByPostVar('usr_password');
312  $passwd_obj->setAlert($this->lng->txt($error_lng_var));
313  $form_valid = false;
314  }
315 
316  $showGlobalTermsOfServieFailure = false;
317  if (\ilTermsOfServiceHelper::isEnabled() && !$this->form->getInput('accept_terms_of_service')) {
318  $agr_obj = $this->form->getItemByPostVar('accept_terms_of_service');
319  if ($agr_obj) {
320  $agr_obj->setAlert($this->lng->txt('force_accept_usr_agreement'));
321  $form_valid = false;
322  } else {
323  $showGlobalTermsOfServieFailure = true;
324  }
325  }
326 
327  // no need if role is attached to code
328  if (!$valid_role) {
329  // manual selection
330  if ($this->registration_settings->roleSelectionEnabled()) {
331  $selected_role = $this->form->getInput("usr_roles");
332  if ($selected_role && ilObjRole::_lookupAllowRegister($selected_role)) {
333  $valid_role = (int) $selected_role;
334  }
335  }
336  // assign by email
337  else {
338  $registration_role_assignments = new ilRegistrationRoleAssignments();
339  $valid_role = (int) $registration_role_assignments->getRoleByEmail($this->form->getInput("usr_email"));
340  }
341  }
342 
343  // no valid role could be determined
344  if (!$valid_role) {
345  ilUtil::sendInfo($this->lng->txt("registration_no_valid_role"));
346  $form_valid = false;
347  }
348 
349  // validate username
350  $login_obj = $this->form->getItemByPostVar('username');
351  $login = $this->form->getInput("username");
352  $captcha = $this->form->getItemByPostVar("captcha_code");
353  if (!ilUtil::isLogin($login)) {
354  $login_obj->setAlert($this->lng->txt("login_invalid"));
355  $form_valid = false;
356  } elseif (ilObjUser::_loginExists($login)) {
357  if(!empty($captcha) && empty($captcha->getAlert()) || empty($captcha)) {
358  $login_obj->setAlert($this->lng->txt("login_exists"));
359  }
360  $form_valid = false;
361  } elseif ((int) $ilSetting->get('allow_change_loginname') &&
362  (int) $ilSetting->get('reuse_of_loginnames') == 0 &&
364  if(!empty($captcha) && empty($captcha->getAlert()) || empty($captcha)) {
365  $login_obj->setAlert($this->lng->txt("login_exists"));
366  }
367  $form_valid = false;
368  }
369 
370  if (!$form_valid) {
371  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
372  } elseif ($showGlobalTermsOfServieFailure) {
373  $this->lng->loadLanguageModule('tos');
374  \ilUtil::sendFailure(sprintf(
375  $this->lng->txt('tos_account_reg_not_possible'),
377  ));
378  } else {
379  $password = $this->__createUser($valid_role);
381  return $this->login();
382  }
383 
384  $this->form->setValuesByPost();
385  $this->displayForm();
386  return false;
387  }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
if($orgName !==null) if($spconfig->hasValue('contacts')) $email
Definition: metadata.php:201
global $DIC
Definition: saml.php:7
static isPasswordValidForUserContext($clear_text_password, $user, &$error_language_variable=null)
$code
Definition: example_050.php:99
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static _loginExists($a_login, $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 getMailToAddress()
Get mailto: email.
static isValidRegistrationCode($a_code)
Check if given code is a valid registration code.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$password
Definition: cron.php:14
static isLogin($a_login)
global $ilSetting
Definition: privfeed.php:17
$login
Definition: cron.php:13
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8
static _lookupAllowRegister($a_role_id)
check whether role is allowed in user registration or not
static _doesLoginnameExistInHistory($a_login)
Checks wether the passed loginname already exists in history.
+ Here is the call graph for this function:

Field Documentation

◆ $code_enabled

ilAccountRegistrationGUI::$code_enabled
protected

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

◆ $code_was_used

ilAccountRegistrationGUI::$code_was_used
protected

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

Referenced by __distributeMails(), login(), and saveForm().

◆ $registration_settings

ilAccountRegistrationGUI::$registration_settings
protected

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

◆ $termsOfServiceEvaluation

ilAccountRegistrationGUI::$termsOfServiceEvaluation
protected

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

◆ $userObj

ilAccountRegistrationGUI::$userObj
protected

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


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