ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
ilAccountRegistrationGUI Class Reference

Class ilAccountRegistrationGUI. More...

+ Collaboration diagram for ilAccountRegistrationGUI:

Public Member Functions

 __construct ()
 
 executeCommand ()
 
 saveForm ()
 

Protected Member Functions

 __initForm ()
 
 __distributeMails ($password, $a_language=null)
 

Protected Attributes

 $registration_settings
 
 $code_enabled
 
 $code_was_used
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAccountRegistrationGUI::__construct ( )

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

References $ilCtrl, $lng, and $tpl.

31  {
32  global $ilCtrl,$tpl,$lng;
33 
34  $this->tpl =& $tpl;
35 
36  $this->ctrl =& $ilCtrl;
37  $this->ctrl->saveParameter($this,'lang');
38 
39  $this->lng =& $lng;
40  $this->lng->loadLanguageModule('registration');
41 
42  $this->registration_settings = new ilRegistrationSettings();
43 
44  $this->code_enabled = ($this->registration_settings->registrationCodeRequired() ||
45  $this->registration_settings->getAllowCodes());
46  }
global $ilCtrl
Definition: ilias.php:18
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
Class ilObjAuthSettingsGUI.
global $lng
Definition: privfeed.php:40

Member Function Documentation

◆ __distributeMails()

ilAccountRegistrationGUI::__distributeMails (   $password,
  $a_language = null 
)
protected

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

References $_GET, $code_was_used, $GLOBALS, $ilSetting, $lng, $path, ilObjUserFolder\_lookupNewAccountMail(), ilSession\get(), IL_REG_ACTIVATION, IL_REG_APPROVE, IL_REG_CODES, IL_REG_DIRECT, ilUtil\stripSlashes(), ilRegistrationMimeMailNotification\TYPE_NOTIFICATION_ACTIVATION, ilRegistrationMailNotification\TYPE_NOTIFICATION_APPROVERS, ilRegistrationMailNotification\TYPE_NOTIFICATION_CONFIRMATION, and USER_FOLDER_ID.

Referenced by saveForm().

728  {
729  global $ilSetting;
730 
731  include_once './Services/Language/classes/class.ilLanguage.php';
732  include_once './Services/User/classes/class.ilObjUser.php';
733  include_once "Services/Mail/classes/class.ilFormatMail.php";
734  include_once './Services/Registration/classes/class.ilRegistrationMailNotification.php';
735 
736  // Always send mail to approvers
737  if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE && !$this->code_was_used)
738  {
739  $mail = new ilRegistrationMailNotification();
741  $mail->setRecipients($this->registration_settings->getApproveRecipients());
742  $mail->setAdditionalInformation(array('usr' => $this->userObj));
743  $mail->send();
744  }
745  else
746  {
747  $mail = new ilRegistrationMailNotification();
749  $mail->setRecipients($this->registration_settings->getApproveRecipients());
750  $mail->setAdditionalInformation(array('usr' => $this->userObj));
751  $mail->send();
752 
753  }
754  // Send mail to new user
755 
756  // Registration with confirmation link ist enabled
757  if($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION && !$this->code_was_used)
758  {
759  include_once './Services/Registration/classes/class.ilRegistrationMimeMailNotification.php';
760 
763  $mail->setRecipients(array($this->userObj));
764  $mail->setAdditionalInformation(
765  array(
766  'usr' => $this->userObj,
767  'hash_lifetime' => $this->registration_settings->getRegistrationHashLifetime()
768  )
769  );
770  $mail->send();
771  }
772  else
773  {
774  // try individual account mail in user administration
775  include_once("Services/Mail/classes/class.ilAccountMail.php");
776  include_once './Services/User/classes/class.ilObjUserFolder.php';
777 
778  $amail = ilObjUserFolder::_lookupNewAccountMail($a_language);
779  if (trim($amail["body"]) == "" || trim($amail["subject"]) == "")
780  {
781  $amail = ilObjUserFolder::_lookupNewAccountMail($GLOBALS["lng"]->getDefaultLanguage());
782  }
783  if (trim($amail["body"]) != "" && trim($amail["subject"]) != "")
784  {
785  $acc_mail = new ilAccountMail();
786  $acc_mail->setUser($this->userObj);
787  if ($this->registration_settings->passwordGenerationEnabled())
788  {
789  $acc_mail->setUserPassword($password);
790  }
791 
792  if($amail["att_file"])
793  {
794  include_once "Services/User/classes/class.ilFSStorageUserFolder.php";
796  $fs->create();
797  $path = $fs->getAbsolutePath()."/";
798 
799  $acc_mail->addAttachment($path."/".$amail["lang"], $amail["att_file"]);
800  }
801 
802  $acc_mail->send();
803  }
804  else // do default mail
805  {
806  include_once "Services/Mail/classes/class.ilMimeMail.php";
807 
808  $mmail = new ilMimeMail();
809  $mmail->autoCheck(false);
810  $mmail->From($ilSetting->get("admin_email"));
811  $mmail->To($this->userObj->getEmail());
812 
813  // mail subject
814  $subject = $this->lng->txt("reg_mail_subject");
815 
816  // mail body
817  $body = $this->lng->txt("reg_mail_body_salutation")." ".$this->userObj->getFullname().",\n\n".
818  $this->lng->txt("reg_mail_body_text1")."\n\n".
819  $this->lng->txt("reg_mail_body_text2")."\n".
820  ILIAS_HTTP_PATH."/login.php?client_id=".CLIENT_ID."\n";
821  $body .= $this->lng->txt("login").": ".$this->userObj->getLogin()."\n";
822 
823  if ($this->registration_settings->passwordGenerationEnabled())
824  {
825  $body.= $this->lng->txt("passwd").": ".$password."\n";
826  }
827  $body.= "\n";
828 
829  // Info about necessary approvement
830  if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE && !$this->code_was_used)
831  {
832  $body .= ($this->lng->txt('reg_mail_body_pwd_generation')."\n\n");
833  }
834 
835  $body .= ($this->lng->txt("reg_mail_body_text3")."\n\r");
836  $body .= $this->userObj->getProfileAsString($this->lng);
837  $mmail->Subject($subject);
838  $mmail->Body($body);
839  $mmail->Send();
840  }
841  }
842  }
Class for mime mail registration notifications.
this class encapsulates the PHP mail() function.
$GLOBALS['ct_recipient']
const IL_REG_ACTIVATION
global $ilSetting
Definition: privfeed.php:40
$path
Definition: index.php:22
Class ilAccountMail.
const USER_FOLDER_ID
Class ilObjUserFolder.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __initForm()

ilAccountRegistrationGUI::__initForm ( )
protected

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

References $ilUser, $lng, $options, ilUserDefinedFields\_getInstance(), ilRegistrationCode\CODE_LENGTH, ilTermsOfServiceSignableDocumentFactory\getByLanguageObject(), IL_REG_ACTIVATION, ilUserProfile\MODE_REGISTRATION, ilFormPropertyGUI\setRequired(), ilTextInputGUI\setSize(), UDF_TYPE_SELECT, UDF_TYPE_TEXT, and UDF_TYPE_WYSIWYG.

Referenced by executeCommand(), and saveForm().

128  {
129  global $lng, $ilUser;
130 
131  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
132  $this->form = new ilPropertyFormGUI();
133  $this->form->setFormAction($this->ctrl->getFormAction($this));
134 
135 
136  // code handling
137 
138  if($this->code_enabled)
139  {
140  include_once 'Services/Registration/classes/class.ilRegistrationCode.php';
141  $code = new ilTextInputGUI($lng->txt("registration_code"), "usr_registration_code");
142  $code->setSize(40);
143  $code->setMaxLength(ilRegistrationCode::CODE_LENGTH);
144  if((bool)$this->registration_settings->registrationCodeRequired())
145  {
146  $code->setRequired(true);
147  $code->setInfo($lng->txt("registration_code_required_info"));
148  }
149  else
150  {
151  $code->setInfo($lng->txt("registration_code_optional_info"));
152  }
153  $this->form->addItem($code);
154  }
155 
156 
157  // user defined fields
158 
159  $user_defined_data = $ilUser->getUserDefinedData();
160 
161  include_once './Services/User/classes/class.ilUserDefinedFields.php';
162  $user_defined_fields =& ilUserDefinedFields::_getInstance();
163  $custom_fields = array();
164  foreach($user_defined_fields->getRegistrationDefinitions() as $field_id => $definition)
165  {
166  if($definition['field_type'] == UDF_TYPE_TEXT)
167  {
168  $custom_fields["udf_".$definition['field_id']] =
169  new ilTextInputGUI($definition['field_name'], "udf_".$definition['field_id']);
170  $custom_fields["udf_".$definition['field_id']]->setValue($user_defined_data["f_".$field_id]);
171  $custom_fields["udf_".$definition['field_id']]->setMaxLength(255);
172  $custom_fields["udf_".$definition['field_id']]->setSize(40);
173  }
174  else if($definition['field_type'] == UDF_TYPE_WYSIWYG)
175  {
176  $custom_fields["udf_".$definition['field_id']] =
177  new ilTextAreaInputGUI($definition['field_name'], "udf_".$definition['field_id']);
178  $custom_fields["udf_".$definition['field_id']]->setValue($user_defined_data["f_".$field_id]);
179  $custom_fields["udf_".$definition['field_id']]->setUseRte(true);
180  }
181  else
182  {
183  $custom_fields["udf_".$definition['field_id']] =
184  new ilSelectInputGUI($definition['field_name'], "udf_".$definition['field_id']);
185  $custom_fields["udf_".$definition['field_id']]->setValue($user_defined_data["f_".$field_id]);
186  $custom_fields["udf_".$definition['field_id']]->setOptions(
187  $user_defined_fields->fieldValuesToSelectArray($definition['field_values']));
188  }
189  if($definition['required'])
190  {
191  $custom_fields["udf_".$definition['field_id']]->setRequired(true);
192  }
193 
194  if($definition['field_type'] == UDF_TYPE_SELECT && !$user_defined_data["f_".$field_id])
195  {
196  $options = array(""=>$lng->txt("please_select")) + $custom_fields["udf_".$definition['field_id']]->getOptions();
197  $custom_fields["udf_".$definition['field_id']]->setOptions($options);
198  }
199  }
200 
201  // standard fields
202  include_once("./Services/User/classes/class.ilUserProfile.php");
203  $up = new ilUserProfile();
204  $up->setMode(ilUserProfile::MODE_REGISTRATION);
205  $up->skipGroup("preferences");
206 
207  // add fields to form
208  $up->addStandardFieldsToForm($this->form, NULL, $custom_fields);
209  unset($custom_fields);
210 
211 
212  // set language selection to current display language
213  $flang = $this->form->getItemByPostVar("usr_language");
214  if($flang)
215  {
216  $flang->setValue($lng->getLangKey());
217  }
218 
219  // add information to role selection (if not hidden)
220  if($this->code_enabled)
221  {
222  $role = $this->form->getItemByPostVar("usr_roles");
223  if($role && $role->getType() == "select")
224  {
225  $role->setInfo($lng->txt("registration_code_role_info"));
226  }
227  }
228 
229  // #11407
230  $domains = array();
231  foreach($this->registration_settings->getAllowedDomains() as $item)
232  {
233  if(trim($item))
234  {
235  $domains[] = $item;
236  }
237  }
238  if(sizeof($domains))
239  {
240  $mail_obj = $this->form->getItemByPostVar('usr_email');
241  $mail_obj->setInfo(sprintf($lng->txt("reg_email_domains"),
242  implode(", ", $domains))."<br />".
243  ($this->code_enabled ? $lng->txt("reg_email_domains_code") : ""));
244  }
245 
246  // #14272
247  if($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION)
248  {
249  $mail_obj = $this->form->getItemByPostVar('usr_email');
250  if($mail_obj) // #16087
251  {
252  $mail_obj->setRequired(true);
253  }
254  }
255 
256  if(ilTermsOfServiceHelper::isEnabled())
257  {
258  try
259  {
260  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceSignableDocumentFactory.php';
262  $field = new ilFormSectionHeaderGUI();
263  $field->setTitle($lng->txt('usr_agreement'));
264  $this->form->addItem($field);
265 
266  $field = new ilCustomInputGUI();
267  $field->setHTML('<div id="agreement">' . $document->getContent() . '</div>');
268  $this->form->addItem($field);
269 
270  $field = new ilCheckboxInputGUI($lng->txt('accept_usr_agreement'), 'accept_terms_of_service');
271  $field->setRequired(true);
272  $field->setValue(1);
273  $this->form->addItem($field);
274  }
276  {
277  }
278  }
279 
280  require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php';
281  if(ilCaptchaUtil::isActiveForRegistration())
282  {
283  require_once 'Services/Captcha/classes/class.ilCaptchaInputGUI.php';
284  $captcha = new ilCaptchaInputGUI($lng->txt("captcha_code"), 'captcha_code');
285  $captcha->setRequired(true);
286  $this->form->addItem($captcha);
287  }
288 
289  $this->form->addCommandButton("saveForm", $lng->txt("register"));
290  }
const UDF_TYPE_SELECT
static _getInstance()
Get instance.
This class represents a selection list property in a property form.
This class represents a property form user interface.
This class represents a captcha input in a property form.
This class represents a section header in a property form.
Class ilUserProfile.
This class represents a checkbox property in a property form.
if(!is_array($argv)) $options
setSize($a_size)
Set Size.
const UDF_TYPE_TEXT
const IL_REG_ACTIVATION
This class represents a text property in a property form.
const UDF_TYPE_WYSIWYG
This class represents a custom property in a property form.
global $ilUser
Definition: imgupload.php:15
global $lng
Definition: privfeed.php:40
This class represents a text area property in a property form.
setRequired($a_required)
Set Required.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilAccountRegistrationGUI::executeCommand ( )

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

References $cmd, $ilErr, $lng, $tpl, __initForm(), ilLanguage\_lookupEntry(), and IL_REG_DISABLED.

49  {
50  global $ilErr, $tpl;
51 
52  if($this->registration_settings->getRegistrationType() == IL_REG_DISABLED)
53  {
54  $ilErr->raiseError($this->lng->txt('reg_disabled'),$ilErr->FATAL);
55  }
56 
57  $next_class = $this->ctrl->getNextClass($this);
58  $cmd = $this->ctrl->getCmd();
59 
60  switch($next_class)
61  {
62  default:
63  if($cmd)
64  {
65  $this->$cmd();
66  }
67  else
68  {
69  $this->displayForm();
70  }
71  break;
72  }
73  $tpl->show();
74  return true;
75  }
$cmd
Definition: sahs_server.php:35
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
+ Here is the call graph for this function:

◆ saveForm()

ilAccountRegistrationGUI::saveForm ( )

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

References $_POST, $client, $code_was_used, $ilSetting, $lng, __distributeMails(), __initForm(), ilObjUser\_doesLoginnameExistInHistory(), ilUserDefinedFields\_getInstance(), ilObjUser\_loginExists(), ilObjRole\_lookupAllowRegister(), ilObject\_lookupType(), ilUtil\generatePasswords(), ilTermsOfServiceSignableDocumentFactory\getByLanguageObject(), ilRegistrationCode\getCodeData(), ilRegistrationCode\getCodeRole(), IL_REG_ACTIVATION, IL_REG_CODES, IL_REG_DIRECT, ilUtil\isLogin(), ilUtil\isPasswordValidForUserContext(), ilRegistrationCode\isUnusedCode(), ilUserProfile\MODE_REGISTRATION, ilUtil\sendFailure(), ilUtil\sendInfo(), ilTermsOfServiceHelper\trackAcceptance(), and ilRegistrationCode\useCode().

293  {
294  global $lng, $ilSetting, $rbacreview;
295 
296  $this->__initForm();
297  $form_valid = $this->form->checkInput();
298 
299  require_once 'Services/User/classes/class.ilObjUser.php';
300 
301 
302  // custom validation
303 
304  $valid_code = $valid_role = false;
305 
306  // code
307  if($this->code_enabled)
308  {
309  $code = $this->form->getInput('usr_registration_code');
310  // could be optional
311  if($code)
312  {
313  // code validation
314  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
316  {
317  $code_obj = $this->form->getItemByPostVar('usr_registration_code');
318  $code_obj->setAlert($lng->txt('registration_code_not_valid'));
319  $form_valid = false;
320  }
321  else
322  {
323  $valid_code = true;
324 
325  // get role from code, check if (still) valid
326  $role_id = (int)ilRegistrationCode::getCodeRole($code);
327  if($role_id && $rbacreview->isGlobalRole($role_id))
328  {
329  $valid_role = $role_id;
330  }
331  }
332  }
333  }
334 
335  // valid codes override email domain check
336  if(!$valid_code)
337  {
338  // validate email against restricted domains
339  $email = $this->form->getInput("usr_email");
340  if($email)
341  {
342  // #10366
343  $domains = array();
344  foreach($this->registration_settings->getAllowedDomains() as $item)
345  {
346  if(trim($item))
347  {
348  $domains[] = $item;
349  }
350  }
351  if(sizeof($domains))
352  {
353  $mail_valid = false;
354  foreach($domains as $domain)
355  {
356  $domain = str_replace("*", "~~~", $domain);
357  $domain = preg_quote($domain);
358  $domain = str_replace("~~~", ".+", $domain);
359  if(preg_match("/^".$domain."$/", $email, $hit))
360  {
361  $mail_valid = true;
362  break;
363  }
364  }
365  if(!$mail_valid)
366  {
367  $mail_obj = $this->form->getItemByPostVar('usr_email');
368  $mail_obj->setAlert(sprintf($lng->txt("reg_email_domains"),
369  implode(", ", $domains)));
370  $form_valid = false;
371  }
372  }
373  }
374  }
375 
376  $error_lng_var = '';
377  if(
378  !$this->registration_settings->passwordGenerationEnabled() &&
379  !ilUtil::isPasswordValidForUserContext($this->form->getInput('usr_password'), $this->form->getInput('username'), $error_lng_var)
380  )
381  {
382  $passwd_obj = $this->form->getItemByPostVar('usr_password');
383  $passwd_obj->setAlert($lng->txt($error_lng_var));
384  $form_valid = false;
385  }
386 
387  if(ilTermsOfServiceHelper::isEnabled() && !$this->form->getInput('accept_terms_of_service'))
388  {
389  $agr_obj = $this->form->getItemByPostVar('accept_terms_of_service');
390  $agr_obj->setAlert($lng->txt('force_accept_usr_agreement'));
391  $form_valid = false;
392  }
393 
394  // no need if role is attached to code
395  if(!$valid_role)
396  {
397  // manual selection
398  if ($this->registration_settings->roleSelectionEnabled())
399  {
400  include_once "./Services/AccessControl/classes/class.ilObjRole.php";
401  $selected_role = $this->form->getInput("usr_roles");
402  if ($selected_role && ilObjRole::_lookupAllowRegister($selected_role))
403  {
404  $valid_role = (int)$selected_role;
405  }
406  }
407  // assign by email
408  else
409  {
410  include_once 'Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.php';
411  $registration_role_assignments = new ilRegistrationRoleAssignments();
412  $valid_role = (int)$registration_role_assignments->getRoleByEmail($this->form->getInput("usr_email"));
413  }
414  }
415 
416  // no valid role could be determined
417  if (!$valid_role)
418  {
419  ilUtil::sendInfo($lng->txt("registration_no_valid_role"));
420  $form_valid = false;
421  }
422 
423  // validate username
424  $login_obj = $this->form->getItemByPostVar('username');
425  $login = $this->form->getInput("username");
426  if (!ilUtil::isLogin($login))
427  {
428  $login_obj->setAlert($lng->txt("login_invalid"));
429  $form_valid = false;
430  }
431  else if (ilObjUser::_loginExists($login))
432  {
433  $login_obj->setAlert($lng->txt("login_exists"));
434  $form_valid = false;
435  }
436  else if ((int)$ilSetting->get('allow_change_loginname') &&
437  (int)$ilSetting->get('reuse_of_loginnames') == 0 &&
439  {
440  $login_obj->setAlert($lng->txt('login_exists'));
441  $form_valid = false;
442  }
443 
444  if(!$form_valid)
445  {
446  ilUtil::sendFailure($lng->txt('form_input_not_valid'));
447  }
448  else
449  {
450  $password = $this->__createUser($valid_role);
451  $this->__distributeMails($password, $this->form->getInput("usr_language"));
452  $this->login($password);
453  return true;
454  }
455 
456  $this->form->setValuesByPost();
457  $this->displayForm();
458  return false;
459  }
static isPasswordValidForUserContext($clear_text_password, $user, &$error_language_variable=null)
__distributeMails($password, $a_language=null)
_lookupAllowRegister($a_role_id)
check whether role is allowed in user registration or not
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 sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
isLogin($a_login)
global $ilSetting
Definition: privfeed.php:40
global $lng
Definition: privfeed.php:40
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 27 of file class.ilAccountRegistrationGUI.php.

◆ $code_was_used

ilAccountRegistrationGUI::$code_was_used
protected

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

Referenced by __distributeMails(), and saveForm().

◆ $registration_settings

ilAccountRegistrationGUI::$registration_settings
protected

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


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