ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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)
 
 doProfileAutoComplete ()
 

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.

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 $tpl
Definition: ilias.php:8
Class ilObjAuthSettingsGUI.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17

References $ilCtrl, $lng, and $tpl.

Member Function Documentation

◆ __distributeMails()

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

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

707 {
708 global $ilSetting;
709
710 include_once './Services/Language/classes/class.ilLanguage.php';
711 include_once './Services/User/classes/class.ilObjUser.php';
712 include_once "Services/Mail/classes/class.ilFormatMail.php";
713 include_once './Services/Registration/classes/class.ilRegistrationMailNotification.php';
714
715 // Always send mail to approvers
716 if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE && !$this->code_was_used)
717 {
718 $mail = new ilRegistrationMailNotification();
720 $mail->setRecipients($this->registration_settings->getApproveRecipients());
721 $mail->setAdditionalInformation(array('usr' => $this->userObj));
722 $mail->send();
723 }
724 else
725 {
726 $mail = new ilRegistrationMailNotification();
728 $mail->setRecipients($this->registration_settings->getApproveRecipients());
729 $mail->setAdditionalInformation(array('usr' => $this->userObj));
730 $mail->send();
731
732 }
733 // Send mail to new user
734
735 // Registration with confirmation link ist enabled
736 if($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION && !$this->code_was_used)
737 {
738 include_once './Services/Registration/classes/class.ilRegistrationMimeMailNotification.php';
739
742 $mail->setRecipients(array($this->userObj));
743 $mail->setAdditionalInformation(
744 array(
745 'usr' => $this->userObj,
746 'hash_lifetime' => $this->registration_settings->getRegistrationHashLifetime()
747 )
748 );
749 $mail->send();
750 }
751 else
752 {
753 // try individual account mail in user administration
754 include_once("Services/Mail/classes/class.ilAccountMail.php");
755 include_once './Services/User/classes/class.ilObjUserFolder.php';
756
757 $amail = ilObjUserFolder::_lookupNewAccountMail($a_language);
758 if (trim($amail["body"]) == "" || trim($amail["subject"]) == "")
759 {
760 $amail = ilObjUserFolder::_lookupNewAccountMail($GLOBALS["lng"]->getDefaultLanguage());
761 }
762 if (trim($amail["body"]) != "" && trim($amail["subject"]) != "")
763 {
764 $acc_mail = new ilAccountMail();
765 $acc_mail->setUser($this->userObj);
766 if ($this->registration_settings->passwordGenerationEnabled())
767 {
768 $acc_mail->setUserPassword($password);
769 }
770
771 if($amail["att_file"])
772 {
773 include_once "Services/User/classes/class.ilFSStorageUserFolder.php";
775 $fs->create();
776 $path = $fs->getAbsolutePath()."/";
777
778 $acc_mail->addAttachment($path."/".$amail["lang"], $amail["att_file"]);
779 }
780
781 $acc_mail->send();
782 }
783 else // do default mail
784 {
785 include_once "Services/Mail/classes/class.ilMimeMail.php";
786
787 $mmail = new ilMimeMail();
788 $mmail->autoCheck(false);
789 $mmail->From($ilSetting->get("admin_email"));
790 $mmail->To($this->userObj->getEmail());
791
792 // mail subject
793 $subject = $this->lng->txt("reg_mail_subject");
794
795 // mail body
796 $body = $this->lng->txt("reg_mail_body_salutation")." ".$this->userObj->getFullname().",\n\n".
797 $this->lng->txt("reg_mail_body_text1")."\n\n".
798 $this->lng->txt("reg_mail_body_text2")."\n".
799 ILIAS_HTTP_PATH."/login.php?client_id=".CLIENT_ID."\n";
800 $body .= $this->lng->txt("login").": ".$this->userObj->getLogin()."\n";
801
802 if ($this->registration_settings->passwordGenerationEnabled())
803 {
804 $body.= $this->lng->txt("passwd").": ".$password."\n";
805 }
806 $body.= "\n";
807
808 // Info about necessary approvement
809 if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE && !$this->code_was_used)
810 {
811 $body .= ($this->lng->txt('reg_mail_body_pwd_generation')."\n\n");
812 }
813
814 $body .= ($this->lng->txt("reg_mail_body_text3")."\n\r");
815 $body .= $this->userObj->getProfileAsString($this->lng);
816 $mmail->Subject($subject);
817 $mmail->Body($body);
818 $mmail->Send();
819 }
820 }
821 }
$path
Definition: aliased.php:25
const USER_FOLDER_ID
Class ilObjUserFolder.
const IL_REG_ACTIVATION
Class ilAccountMail.
this class encapsulates the PHP mail() function.
static _lookupNewAccountMail($a_lang)
Class for mime mail registration notifications.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilSetting
Definition: privfeed.php:17

References $GLOBALS, $ilSetting, $path, ilObjUserFolder\_lookupNewAccountMail(), IL_REG_ACTIVATION, IL_REG_APPROVE, ilRegistrationMimeMailNotification\TYPE_NOTIFICATION_ACTIVATION, ilRegistrationMailNotification\TYPE_NOTIFICATION_APPROVERS, ilRegistrationMailNotification\TYPE_NOTIFICATION_CONFIRMATION, and USER_FOLDER_ID.

Referenced by saveForm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __initForm()

ilAccountRegistrationGUI::__initForm ( )
protected

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

98 {
99 global $lng, $ilUser;
100
101 // needed for multi-text-fields (interests)
102 include_once 'Services/jQuery/classes/class.iljQueryUtil.php';
104
105 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
106 $this->form = new ilPropertyFormGUI();
107 $this->form->setFormAction($this->ctrl->getFormAction($this));
108
109
110 // code handling
111
112 if($this->code_enabled)
113 {
114 include_once 'Services/Registration/classes/class.ilRegistrationCode.php';
115 $code = new ilTextInputGUI($lng->txt("registration_code"), "usr_registration_code");
116 $code->setSize(40);
118 if((bool)$this->registration_settings->registrationCodeRequired())
119 {
120 $code->setRequired(true);
121 $code->setInfo($lng->txt("registration_code_required_info"));
122 }
123 else
124 {
125 $code->setInfo($lng->txt("registration_code_optional_info"));
126 }
127 $this->form->addItem($code);
128 }
129
130
131 // user defined fields
132
133 $user_defined_data = $ilUser->getUserDefinedData();
134
135 include_once './Services/User/classes/class.ilUserDefinedFields.php';
136 $user_defined_fields =& ilUserDefinedFields::_getInstance();
137 $custom_fields = array();
138 foreach($user_defined_fields->getRegistrationDefinitions() as $field_id => $definition)
139 {
140 if($definition['field_type'] == UDF_TYPE_TEXT)
141 {
142 $custom_fields["udf_".$definition['field_id']] =
143 new ilTextInputGUI($definition['field_name'], "udf_".$definition['field_id']);
144 $custom_fields["udf_".$definition['field_id']]->setValue($user_defined_data["f_".$field_id]);
145 $custom_fields["udf_".$definition['field_id']]->setMaxLength(255);
146 $custom_fields["udf_".$definition['field_id']]->setSize(40);
147 }
148 else if($definition['field_type'] == UDF_TYPE_WYSIWYG)
149 {
150 $custom_fields["udf_".$definition['field_id']] =
151 new ilTextAreaInputGUI($definition['field_name'], "udf_".$definition['field_id']);
152 $custom_fields["udf_".$definition['field_id']]->setValue($user_defined_data["f_".$field_id]);
153 $custom_fields["udf_".$definition['field_id']]->setUseRte(true);
154 }
155 else
156 {
157 $custom_fields["udf_".$definition['field_id']] =
158 new ilSelectInputGUI($definition['field_name'], "udf_".$definition['field_id']);
159 $custom_fields["udf_".$definition['field_id']]->setValue($user_defined_data["f_".$field_id]);
160 $custom_fields["udf_".$definition['field_id']]->setOptions(
161 $user_defined_fields->fieldValuesToSelectArray($definition['field_values']));
162 }
163 if($definition['required'])
164 {
165 $custom_fields["udf_".$definition['field_id']]->setRequired(true);
166 }
167
168 if($definition['field_type'] == UDF_TYPE_SELECT && !$user_defined_data["f_".$field_id])
169 {
170 $options = array(""=>$lng->txt("please_select")) + $custom_fields["udf_".$definition['field_id']]->getOptions();
171 $custom_fields["udf_".$definition['field_id']]->setOptions($options);
172 }
173 }
174
175 // standard fields
176 include_once("./Services/User/classes/class.ilUserProfile.php");
177 $up = new ilUserProfile();
179 $up->skipGroup("preferences");
180
181 $up->setAjaxCallback(
182 $this->ctrl->getLinkTarget($this, 'doProfileAutoComplete', '', true)
183 );
184
185 $lng->loadLanguageModule("user");
186
187 // add fields to form
188 $up->addStandardFieldsToForm($this->form, NULL, $custom_fields);
189 unset($custom_fields);
190
191
192 // set language selection to current display language
193 $flang = $this->form->getItemByPostVar("usr_language");
194 if($flang)
195 {
196 $flang->setValue($lng->getLangKey());
197 }
198
199 // add information to role selection (if not hidden)
200 if($this->code_enabled)
201 {
202 $role = $this->form->getItemByPostVar("usr_roles");
203 if($role && $role->getType() == "select")
204 {
205 $role->setInfo($lng->txt("registration_code_role_info"));
206 }
207 }
208
209 // #11407
210 $domains = array();
211 foreach($this->registration_settings->getAllowedDomains() as $item)
212 {
213 if(trim($item))
214 {
215 $domains[] = $item;
216 }
217 }
218 if(sizeof($domains))
219 {
220 $mail_obj = $this->form->getItemByPostVar('usr_email');
221 $mail_obj->setInfo(sprintf($lng->txt("reg_email_domains"),
222 implode(", ", $domains))."<br />".
223 ($this->code_enabled ? $lng->txt("reg_email_domains_code") : ""));
224 }
225
226 // #14272
227 if($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION)
228 {
229 $mail_obj = $this->form->getItemByPostVar('usr_email');
230 if($mail_obj) // #16087
231 {
232 $mail_obj->setRequired(true);
233 }
234 }
235
236 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceSignableDocumentFactory.php';
238 if(ilTermsOfServiceHelper::isEnabled() && $document->exists())
239 {
240 $field = new ilFormSectionHeaderGUI();
241 $field->setTitle($lng->txt('usr_agreement'));
242 $this->form->addItem($field);
243
244 $field = new ilCustomInputGUI();
245 $field->setHTML('<div id="agreement">' . $document->getContent() . '</div>');
246 $this->form->addItem($field);
247
248 $field = new ilCheckboxInputGUI($lng->txt('accept_usr_agreement'), 'accept_terms_of_service');
249 $field->setRequired(true);
250 $field->setValue(1);
251 $this->form->addItem($field);
252 }
253
254 require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php';
255 if(ilCaptchaUtil::isActiveForRegistration())
256 {
257 require_once 'Services/Captcha/classes/class.ilCaptchaInputGUI.php';
258 $captcha = new ilCaptchaInputGUI($lng->txt("captcha_code"), 'captcha_code');
259 $captcha->setRequired(true);
260 $this->form->addItem($captcha);
261 }
262
263 $this->form->addCommandButton("saveForm", $lng->txt("register"));
264 }
sprintf('%.4f', $callTime)
const UDF_TYPE_SELECT
const UDF_TYPE_WYSIWYG
const UDF_TYPE_TEXT
This class represents a captcha input in a property form.
This class represents a checkbox property in a property form.
This class represents a custom property in a property form.
This class represents a section header in a property form.
This class represents a property form user interface.
This class represents a selection list property in a property form.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static _getInstance()
Get instance.
Class ilUserProfile.
static initjQuery($a_tpl=null)
Init jQuery.
$code
Definition: example_050.php:99
if(!is_array($argv)) $options
$ilUser
Definition: imgupload.php:18

References $code, $ilUser, $lng, $options, ilUserDefinedFields\_getInstance(), ilRegistrationCode\CODE_LENGTH, ilTermsOfServiceSignableDocumentFactory\getByLanguageObject(), IL_REG_ACTIVATION, iljQueryUtil\initjQuery(), ilTermsOfServiceHelper\isEnabled(), ilUserProfile\MODE_REGISTRATION, sprintf, UDF_TYPE_SELECT, UDF_TYPE_TEXT, and UDF_TYPE_WYSIWYG.

Referenced by saveForm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doProfileAutoComplete()

ilAccountRegistrationGUI::doProfileAutoComplete ( )
protected

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

894 {
895 $field_id = (string)$_REQUEST["f"];
896 $term = (string)$_REQUEST["term"];
897
898 include_once "Services/User/classes/class.ilPublicUserProfileGUI.php";
900 if(sizeof($result))
901 {
902 include_once 'Services/JSON/classes/class.ilJsonUtil.php';
904 }
905
906 exit();
907 }
$result
static encode($mixed, $suppress_native=false)
static getAutocompleteResult($a_field_id, $a_term)

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

+ Here is the call graph for this function:

◆ executeCommand()

ilAccountRegistrationGUI::executeCommand ( )

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

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 }
global $ilErr
Definition: raiseError.php:16
$cmd
Definition: sahs_server.php:35

References $cmd, $ilErr, $tpl, and IL_REG_DISABLED.

◆ saveForm()

ilAccountRegistrationGUI::saveForm ( )

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

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

References $code, $ilSetting, $lng, __distributeMails(), __initForm(), ilObjUser\_doesLoginnameExistInHistory(), ilObjUser\_loginExists(), ilObjRole\_lookupAllowRegister(), ilRegistrationCode\getCodeRole(), ilTermsOfServiceHelper\isEnabled(), ilUtil\isLogin(), ilUtil\isPasswordValidForUserContext(), ilRegistrationCode\isValidRegistrationCode(), ilUtil\sendFailure(), ilUtil\sendInfo(), and sprintf.

+ 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.

◆ $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: