ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAccountRegistrationGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
18 require_once './Services/Registration/classes/class.ilRegistrationSettings.php';
19 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
20 
25 {
26  protected $registration_settings; // [object]
27  protected $code_enabled; // [bool]
28  protected $code_was_used; // [bool]
29 
30  public function __construct()
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  }
47 
48  public function executeCommand()
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  }
76 
80  public function displayForm()
81  {
85  global $lng;
86 
87  ilStartUpGUI::initStartUpTemplate(array('tpl.usr_registration.html', 'Services/Registration'), true);
88  $this->tpl->setVariable('TXT_PAGEHEADLINE', $this->lng->txt('registration'));
89 
90  if(!$this->form)
91  {
92  $this->__initForm();
93  }
94  $this->tpl->setVariable('FORM', $this->form->getHTML());
95  }
96 
97  protected function __initForm()
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);
117  $code->setMaxLength(ilRegistrationCode::CODE_LENGTH);
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();
178  $up->setMode(ilUserProfile::MODE_REGISTRATION);
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  if(ilTermsOfServiceHelper::isEnabled())
237  {
238  try
239  {
240  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceSignableDocumentFactory.php';
242  $field = new ilFormSectionHeaderGUI();
243  $field->setTitle($lng->txt('usr_agreement'));
244  $this->form->addItem($field);
245 
246  $field = new ilCustomInputGUI();
247  $field->setHTML('<div id="agreement">' . $document->getContent() . '</div>');
248  $this->form->addItem($field);
249 
250  $field = new ilCheckboxInputGUI($lng->txt('accept_usr_agreement'), 'accept_terms_of_service');
251  $field->setRequired(true);
252  $field->setValue(1);
253  $this->form->addItem($field);
254  }
256  {
257  }
258  }
259 
260  require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php';
261  if(ilCaptchaUtil::isActiveForRegistration())
262  {
263  require_once 'Services/Captcha/classes/class.ilCaptchaInputGUI.php';
264  $captcha = new ilCaptchaInputGUI($lng->txt("captcha_code"), 'captcha_code');
265  $captcha->setRequired(true);
266  $this->form->addItem($captcha);
267  }
268 
269  $this->form->addCommandButton("saveForm", $lng->txt("register"));
270  }
271 
272  public function saveForm()
273  {
274  global $lng, $ilSetting, $rbacreview;
275 
276  $this->__initForm();
277  $form_valid = $this->form->checkInput();
278 
279  require_once 'Services/User/classes/class.ilObjUser.php';
280 
281 
282  // custom validation
283 
284  $valid_code = $valid_role = false;
285 
286  // code
287  if($this->code_enabled)
288  {
289  $code = $this->form->getInput('usr_registration_code');
290  // could be optional
291  if($code)
292  {
293  // code validation
294  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
296  {
297  $code_obj = $this->form->getItemByPostVar('usr_registration_code');
298  $code_obj->setAlert($lng->txt('registration_code_not_valid'));
299  $form_valid = false;
300  }
301  else
302  {
303  $valid_code = true;
304 
305  // get role from code, check if (still) valid
306  $role_id = (int)ilRegistrationCode::getCodeRole($code);
307  if($role_id && $rbacreview->isGlobalRole($role_id))
308  {
309  $valid_role = $role_id;
310  }
311  }
312  }
313  }
314 
315  // valid codes override email domain check
316  if(!$valid_code)
317  {
318  // validate email against restricted domains
319  $email = $this->form->getInput("usr_email");
320  if($email)
321  {
322  // #10366
323  $domains = array();
324  foreach($this->registration_settings->getAllowedDomains() as $item)
325  {
326  if(trim($item))
327  {
328  $domains[] = $item;
329  }
330  }
331  if(sizeof($domains))
332  {
333  $mail_valid = false;
334  foreach($domains as $domain)
335  {
336  $domain = str_replace("*", "~~~", $domain);
337  $domain = preg_quote($domain);
338  $domain = str_replace("~~~", ".+", $domain);
339  if(preg_match("/^".$domain."$/", $email, $hit))
340  {
341  $mail_valid = true;
342  break;
343  }
344  }
345  if(!$mail_valid)
346  {
347  $mail_obj = $this->form->getItemByPostVar('usr_email');
348  $mail_obj->setAlert(sprintf($lng->txt("reg_email_domains"),
349  implode(", ", $domains)));
350  $form_valid = false;
351  }
352  }
353  }
354  }
355 
356  $error_lng_var = '';
357  if(
358  !$this->registration_settings->passwordGenerationEnabled() &&
359  !ilUtil::isPasswordValidForUserContext($this->form->getInput('usr_password'), $this->form->getInput('username'), $error_lng_var)
360  )
361  {
362  $passwd_obj = $this->form->getItemByPostVar('usr_password');
363  $passwd_obj->setAlert($lng->txt($error_lng_var));
364  $form_valid = false;
365  }
366 
367  if(ilTermsOfServiceHelper::isEnabled() && !$this->form->getInput('accept_terms_of_service'))
368  {
369  $agr_obj = $this->form->getItemByPostVar('accept_terms_of_service');
370  if($agr_obj)
371  {
372  $agr_obj->setAlert($lng->txt('force_accept_usr_agreement'));
373  }
374  else
375  {
376  ilUtil::sendFailure($lng->txt('force_accept_usr_agreement'));
377  }
378  $form_valid = false;
379  }
380 
381  // no need if role is attached to code
382  if(!$valid_role)
383  {
384  // manual selection
385  if ($this->registration_settings->roleSelectionEnabled())
386  {
387  include_once "./Services/AccessControl/classes/class.ilObjRole.php";
388  $selected_role = $this->form->getInput("usr_roles");
389  if ($selected_role && ilObjRole::_lookupAllowRegister($selected_role))
390  {
391  $valid_role = (int)$selected_role;
392  }
393  }
394  // assign by email
395  else
396  {
397  include_once 'Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.php';
398  $registration_role_assignments = new ilRegistrationRoleAssignments();
399  $valid_role = (int)$registration_role_assignments->getRoleByEmail($this->form->getInput("usr_email"));
400  }
401  }
402 
403  // no valid role could be determined
404  if (!$valid_role)
405  {
406  ilUtil::sendInfo($lng->txt("registration_no_valid_role"));
407  $form_valid = false;
408  }
409 
410  // validate username
411  $login_obj = $this->form->getItemByPostVar('username');
412  $login = $this->form->getInput("username");
413  if (!ilUtil::isLogin($login))
414  {
415  $login_obj->setAlert($lng->txt("login_invalid"));
416  $form_valid = false;
417  }
418  else if (ilObjUser::_loginExists($login))
419  {
420  $login_obj->setAlert($lng->txt("login_exists"));
421  $form_valid = false;
422  }
423  else if ((int)$ilSetting->get('allow_change_loginname') &&
424  (int)$ilSetting->get('reuse_of_loginnames') == 0 &&
426  {
427  $login_obj->setAlert($lng->txt('login_exists'));
428  $form_valid = false;
429  }
430 
431  if(!$form_valid)
432  {
433  ilUtil::sendFailure($lng->txt('form_input_not_valid'));
434  }
435  else
436  {
437  $password = $this->__createUser($valid_role);
438  $this->__distributeMails($password, $this->form->getInput("usr_language"));
439  $this->login($password);
440  return true;
441  }
442 
443  $this->form->setValuesByPost();
444  $this->displayForm();
445  return false;
446  }
447 
448  protected function __createUser($a_role)
449  {
455  global $ilSetting, $rbacadmin, $lng;
456 
457 
458  // something went wrong with the form validation
459  if(!$a_role)
460  {
461  global $ilias;
462  $ilias->raiseError("Invalid role selection in registration".
463  ", IP: ".$_SERVER["REMOTE_ADDR"], $ilias->error_obj->FATAL);
464  }
465 
466 
467  $this->userObj = new ilObjUser();
468 
469  include_once("./Services/User/classes/class.ilUserProfile.php");
470  $up = new ilUserProfile();
471  $up->setMode(ilUserProfile::MODE_REGISTRATION);
472 
473  $map = array();
474  $up->skipGroup("preferences");
475  $up->skipGroup("settings");
476  $up->skipGroup("instant_messengers");
477  $up->skipField("password");
478  $up->skipField("birthday");
479  $up->skipField("upload");
480  foreach ($up->getStandardFields() as $k => $v)
481  {
482  if($v["method"])
483  {
484  $method = "set".substr($v["method"], 3);
485  if(method_exists($this->userObj, $method))
486  {
487  if ($k != "username")
488  {
489  $k = "usr_".$k;
490  }
491  $field_obj = $this->form->getItemByPostVar($k);
492  if($field_obj)
493  {
494 
495  $this->userObj->$method($this->form->getInput($k));
496  }
497  }
498  }
499  }
500 
501  $this->userObj->setFullName();
502 
503  $birthday_obj = $this->form->getItemByPostVar("usr_birthday");
504  if ($birthday_obj)
505  {
506  $birthday = $this->form->getInput("usr_birthday");
507  $birthday = $birthday["date"];
508 
509  // when birthday was not set, array will not be substituted with string by ilBirthdayInputGui
510  if(!is_array($birthday))
511  {
512  $this->userObj->setBirthday($birthday);
513  }
514  }
515 
516  // messenger
517  $map = array("icq", "yahoo", "msn", "aim", "skype", "jabber", "voip");
518  foreach($map as $client)
519  {
520  $field = "usr_im_".$client;
521  $field_obj = $this->form->getItemByPostVar($field);
522  if($field_obj)
523  {
524  $this->userObj->setInstantMessengerId($client, $this->form->getInput($field));
525  }
526  }
527 
528  $this->userObj->setTitle($this->userObj->getFullname());
529  $this->userObj->setDescription($this->userObj->getEmail());
530 
531  if ($this->registration_settings->passwordGenerationEnabled())
532  {
533  $password = ilUtil::generatePasswords(1);
534  $password = $password[0];
535  }
536  else
537  {
538  $password = $this->form->getInput("usr_password");
539  }
540  $this->userObj->setPasswd($password);
541 
542 
543  // Set user defined data
544  include_once './Services/User/classes/class.ilUserDefinedFields.php';
545  $user_defined_fields =& ilUserDefinedFields::_getInstance();
546  $defs = $user_defined_fields->getRegistrationDefinitions();
547  $udf = array();
548  foreach ($_POST as $k => $v)
549  {
550  if (substr($k, 0, 4) == "udf_")
551  {
552  $f = substr($k, 4);
553  $udf[$f] = $v;
554  }
555  }
556  $this->userObj->setUserDefinedData($udf);
557 
558  $this->userObj->setTimeLimitOwner(7);
559 
560 
561  $access_limit = null;
562 
563  $this->code_was_used = false;
564  if($this->code_enabled)
565  {
566  $code_local_roles = $code_has_access_limit = null;
567 
568  // #10853 - could be optional
569  $code = $this->form->getInput('usr_registration_code');
570  if($code)
571  {
572  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
573 
574  // set code to used
576  $this->code_was_used = true;
577 
578  // handle code attached local role(s) and access limitation
579  $code_data = ilRegistrationCode::getCodeData($code);
580  if($code_data["role_local"])
581  {
582  // need user id before we can assign role(s)
583  $code_local_roles = explode(";", $code_data["role_local"]);
584  }
585  if($code_data["alimit"])
586  {
587  // see below
588  $code_has_access_limit = true;
589 
590  switch($code_data["alimit"])
591  {
592  case "absolute":
593  $abs = date_parse($code_data["alimitdt"]);
594  $access_limit = mktime(23, 59, 59, $abs['month'], $abs['day'], $abs['year']);
595  break;
596 
597  case "relative":
598  $rel = unserialize($code_data["alimitdt"]);
599  $access_limit = $rel["d"] * 86400 + $rel["m"] * 2592000 +
600  $rel["y"] * 31536000 + time();
601  break;
602  }
603  }
604  }
605  }
606 
607  // code access limitation will override any other access limitation setting
608  if (!($this->code_was_used && $code_has_access_limit) &&
609  $this->registration_settings->getAccessLimitation())
610  {
611  include_once 'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php';
612  $access_limitations_obj = new ilRegistrationRoleAccessLimitations();
613  switch($access_limitations_obj->getMode($a_role))
614  {
615  case 'absolute':
616  $access_limit = $access_limitations_obj->getAbsolute($a_role);
617  break;
618 
619  case 'relative':
620  $rel_d = (int) $access_limitations_obj->getRelative($a_role,'d');
621  $rel_m = (int) $access_limitations_obj->getRelative($a_role,'m');
622  $rel_y = (int) $access_limitations_obj->getRelative($a_role,'y');
623  $access_limit = $rel_d * 86400 + $rel_m * 2592000 + $rel_y * 31536000 + time();
624  break;
625  }
626  }
627 
628  if($access_limit)
629  {
630  $this->userObj->setTimeLimitUnlimited(0);
631  $this->userObj->setTimeLimitUntil($access_limit);
632  }
633  else
634  {
635  $this->userObj->setTimeLimitUnlimited(1);
636  $this->userObj->setTimeLimitUntil(time());
637  }
638 
639  $this->userObj->setTimeLimitFrom(time());
640 
641  include_once './Services/User/classes/class.ilUserCreationContext.php';
643 
644  $this->userObj->create();
645 
646 
647  if($this->registration_settings->getRegistrationType() == IL_REG_DIRECT ||
648  $this->registration_settings->getRegistrationType() == IL_REG_CODES ||
650  {
651  $this->userObj->setActive(1,0);
652  }
653  else if($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION)
654  {
655  $this->userObj->setActive(0,0);
656  }
657  else
658  {
659  $this->userObj->setActive(0,0);
660  }
661 
662  $this->userObj->updateOwner();
663 
664  // set a timestamp for last_password_change
665  // this ts is needed by ilSecuritySettings
666  $this->userObj->setLastPasswordChangeTS( time() );
667 
668  $this->userObj->setIsSelfRegistered(true);
669 
670  //insert user data in table user_data
671  $this->userObj->saveAsNew();
672 
673  try
674  {
675  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceSignableDocumentFactory.php';
677  }
679  {
680  }
681 
682  // setup user preferences
683  $this->userObj->setLanguage($this->form->getInput('usr_language'));
684  $hits_per_page = $ilSetting->get("hits_per_page");
685  if ($hits_per_page < 10)
686  {
687  $hits_per_page = 10;
688  }
689  $this->userObj->setPref("hits_per_page", $hits_per_page);
690  $show_online = $ilSetting->get("show_users_online");
691  if ($show_online == "")
692  {
693  $show_online = "y";
694  }
695  $this->userObj->setPref("show_users_online", $show_online);
696  $this->userObj->writePrefs();
697 
698 
699  $rbacadmin->assignUser((int)$a_role, $this->userObj->getId());
700 
701  // local roles from code
702  if($this->code_was_used && is_array($code_local_roles))
703  {
704  foreach(array_unique($code_local_roles) as $local_role_obj_id)
705  {
706  // is given role (still) valid?
707  if(ilObject::_lookupType($local_role_obj_id) == "role")
708  {
709  $rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId());
710 
711  // patch to remove for 45 due to mantis 21953
712  $role_obj = $GLOBALS['rbacreview']->getObjectOfRole($local_role_obj_id);
713  switch(ilObject::_lookupType($role_obj))
714  {
715  case 'crs':
716  case 'grp':
717  $role_refs = ilObject::_getAllReferences($role_obj);
718  $role_ref = end($role_refs);
719  ilObjUser::_addDesktopItem($this->userObj->getId(),$role_ref,ilObject::_lookupType($role_obj));
720  break;
721  }
722  }
723  }
724  }
725 
726  return $password;
727  }
728 
729  protected function __distributeMails($password, $a_language = null)
730  {
731  global $ilSetting;
732 
733  include_once './Services/Language/classes/class.ilLanguage.php';
734  include_once './Services/User/classes/class.ilObjUser.php';
735  include_once "Services/Mail/classes/class.ilFormatMail.php";
736  include_once './Services/Registration/classes/class.ilRegistrationMailNotification.php';
737 
738  // Always send mail to approvers
739  if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE && !$this->code_was_used)
740  {
741  $mail = new ilRegistrationMailNotification();
743  $mail->setRecipients($this->registration_settings->getApproveRecipients());
744  $mail->setAdditionalInformation(array('usr' => $this->userObj));
745  $mail->send();
746  }
747  else
748  {
749  $mail = new ilRegistrationMailNotification();
751  $mail->setRecipients($this->registration_settings->getApproveRecipients());
752  $mail->setAdditionalInformation(array('usr' => $this->userObj));
753  $mail->send();
754 
755  }
756  // Send mail to new user
757 
758  // Registration with confirmation link ist enabled
759  if($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION && !$this->code_was_used)
760  {
761  include_once './Services/Registration/classes/class.ilRegistrationMimeMailNotification.php';
762 
765  $mail->setRecipients(array($this->userObj));
766  $mail->setAdditionalInformation(
767  array(
768  'usr' => $this->userObj,
769  'hash_lifetime' => $this->registration_settings->getRegistrationHashLifetime()
770  )
771  );
772  $mail->send();
773  }
774  else
775  {
776  // try individual account mail in user administration
777  include_once("Services/Mail/classes/class.ilAccountMail.php");
778  include_once './Services/User/classes/class.ilObjUserFolder.php';
779 
780  $amail = ilObjUserFolder::_lookupNewAccountMail($a_language);
781  if (trim($amail["body"]) == "" || trim($amail["subject"]) == "")
782  {
783  $amail = ilObjUserFolder::_lookupNewAccountMail($GLOBALS["lng"]->getDefaultLanguage());
784  }
785  if (trim($amail["body"]) != "" && trim($amail["subject"]) != "")
786  {
787  $acc_mail = new ilAccountMail();
788  $acc_mail->setUser($this->userObj);
789  if ($this->registration_settings->passwordGenerationEnabled())
790  {
791  $acc_mail->setUserPassword($password);
792  }
793 
794  if($amail["att_file"])
795  {
796  include_once "Services/User/classes/class.ilFSStorageUserFolder.php";
798  $fs->create();
799  $path = $fs->getAbsolutePath()."/";
800 
801  $acc_mail->addAttachment($path."/".$amail["lang"], $amail["att_file"]);
802  }
803 
804  $acc_mail->send();
805  }
806  else // do default mail
807  {
808  include_once "Services/Mail/classes/class.ilMimeMail.php";
809 
810  $mmail = new ilMimeMail();
811  $mmail->autoCheck(false);
812  $mmail->From($ilSetting->get("admin_email"));
813  $mmail->To($this->userObj->getEmail());
814 
815  // mail subject
816  $subject = $this->lng->txt("reg_mail_subject");
817 
818  // mail body
819  $body = $this->lng->txt("reg_mail_body_salutation")." ".$this->userObj->getFullname().",\n\n".
820  $this->lng->txt("reg_mail_body_text1")."\n\n".
821  $this->lng->txt("reg_mail_body_text2")."\n".
822  ILIAS_HTTP_PATH."/login.php?client_id=".CLIENT_ID."\n";
823  $body .= $this->lng->txt("login").": ".$this->userObj->getLogin()."\n";
824 
825  if ($this->registration_settings->passwordGenerationEnabled())
826  {
827  $body.= $this->lng->txt("passwd").": ".$password."\n";
828  }
829  $body.= "\n";
830 
831  // Info about necessary approvement
832  if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE && !$this->code_was_used)
833  {
834  $body .= ($this->lng->txt('reg_mail_body_pwd_generation')."\n\n");
835  }
836 
837  $body .= ($this->lng->txt("reg_mail_body_text3")."\n\r");
838  $body .= $this->userObj->getProfileAsString($this->lng);
839  $mmail->Subject($subject);
840  $mmail->Body($body);
841  $mmail->Send();
842  }
843  }
844  }
845 
849  public function login($password)
850  {
854  global $lng;
855 
856  ilStartUpGUI::initStartUpTemplate(array('tpl.usr_registered.html', 'Services/Registration'), false);
857  $this->tpl->setVariable('TXT_PAGEHEADLINE', $this->lng->txt('registration'));
858 
859  $this->tpl->setVariable("TXT_WELCOME", $lng->txt("welcome") . ", " . $this->userObj->getTitle() . "!");
860  if(
861  (
862  $this->registration_settings->getRegistrationType() == IL_REG_DIRECT ||
863  $this->registration_settings->getRegistrationType() == IL_REG_CODES ||
865  ) &&
866  !$this->registration_settings->passwordGenerationEnabled()
867  )
868  {
869  $this->tpl->setCurrentBlock('activation');
870  $this->tpl->setVariable('TXT_REGISTERED', $lng->txt('txt_registered'));
871  $this->tpl->setVariable('FORMACTION', 'login.php?cmd=post&target=' . ilUtil::stripSlashes($_GET['target']));
872  if(ilSession::get('forceShoppingCartRedirect'))
873  {
874  $this->tpl->setVariable('FORMACTION', './login.php?forceShoppingCartRedirect=1');
875  }
876  $this->tpl->setVariable('TARGET', 'target="_parent"');
877  $this->tpl->setVariable('TXT_LOGIN', $lng->txt('login_to_ilias'));
878  $this->tpl->setVariable('USERNAME', $this->userObj->getLogin());
879  $this->tpl->setVariable('PASSWORD', $password);
880  $this->tpl->parseCurrentBlock();
881  }
882  else if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE)
883  {
884  $this->tpl->setVariable('TXT_REGISTERED', $lng->txt('txt_submitted'));
885 
886  if(IS_PAYMENT_ENABLED == true)
887  {
888  if(ilSession::get('forceShoppingCartRedirect'))
889  {
890  $this->tpl->setCurrentBlock('activation');
891  include_once 'Services/Payment/classes/class.ilShopLinkBuilder.php';
892  $shop_link = new ilShopLinkBuilder();
893  $this->tpl->setVariable('FORMACTION', $shop_link->buildLink('ilshopshoppingcartgui', '_forceShoppingCartRedirect_user=' . $this->userObj->getId()));
894  $this->tpl->setVariable('TARGET', 'target=\'_parent\'');
895 
896  $this->lng->loadLanguageModule('payment');
897  $this->tpl->setVariable('TXT_LOGIN', $lng->txt('pay_goto_shopping_cart'));
898  $this->tpl->parseCurrentBlock();
899  $this->lng->loadLanguageModule('registration');
900  }
901  }
902  }
903  else if($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION)
904  {
905  $login_url = './login.php?cmd=force_login&lang=' . $this->userObj->getLanguage();
906  $this->tpl->setVariable('TXT_REGISTERED', sprintf($lng->txt('reg_confirmation_link_successful'), $login_url));
907  $this->tpl->setVariable('REDIRECT_URL', $login_url);
908  }
909  else
910  {
911  $this->tpl->setVariable('TXT_REGISTERED', $lng->txt('txt_registered_passw_gen'));
912  }
913  }
914 
915  protected function doProfileAutoComplete()
916  {
917  $field_id = (string)$_REQUEST["f"];
918  $term = (string)$_REQUEST["term"];
919 
920  include_once "Services/User/classes/class.ilPublicUserProfileGUI.php";
922  if(sizeof($result))
923  {
924  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
926  }
927 
928  exit();
929  }
930 }