1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4/** @defgroup ServicesRegistration Services/Registration
5 */
6
7/**
8* Class ilAccountRegistrationGUI
9*
10* @author Stefan Meyer <smeyer.ilias@gmx.de>
11* @version $Id$
12*
13* @ilCtrl_Calls ilAccountRegistrationGUI:
14*
15* @ingroup ServicesRegistration
16*/
17
18
19/**
20 *
21 */
22class ilAccountRegistrationGUI
23{
24    protected $registration_settings; // [object]
25    protected $code_enabled; // [bool]
26    protected $code_was_used; // [bool]
27    /** @var \ilObjUser|null */
28    protected $userObj;
29
30    /** @var \ilTermsOfServiceDocumentEvaluation */
31    protected $termsOfServiceEvaluation;
32
33    /**
34     * @var ilRecommendedContentManager
35     */
36    protected $recommended_content_manager;
37
38    public function __construct()
39    {
40        global $DIC;
41
42        $ilCtrl = $DIC->ctrl();
43        $tpl = $DIC['tpl'];
44        $lng = $DIC->language();
45
46        $this->tpl = &$tpl;
47
48        $this->ctrl = &$ilCtrl;
49        $this->ctrl->saveParameter($this, 'lang');
50
51        $this->lng = &$lng;
52        $this->lng->loadLanguageModule('registration');
53
54        $this->registration_settings = new ilRegistrationSettings();
55
56        $this->code_enabled = ($this->registration_settings->registrationCodeRequired() ||
57            $this->registration_settings->getAllowCodes());
58
59        $this->termsOfServiceEvaluation = $DIC['tos.document.evaluator'];
60        $this->recommended_content_manager = new ilRecommendedContentManager();
61    }
62
63    public function executeCommand()
64    {
65        global $DIC;
66
67        if ($this->registration_settings->getRegistrationType() == IL_REG_DISABLED) {
68            $ilErr = $DIC['ilErr'];
69            $ilErr->raiseError($this->lng->txt('reg_disabled'), $ilErr->FATAL);
70        }
71
72        $cmd = $this->ctrl->getCmd();
73        switch ($cmd) {
74            case 'saveForm':
75                $tpl = $this->$cmd();
76                break;
77            default:
78                $tpl = $this->displayForm();
79        }
80
81        $gtpl = $this->tpl;
82        $gtpl->setPermanentLink('usr', null, 'registration');
83        ilStartUpGUI::printToGlobalTemplate($tpl);
84    }
85
86    /**
87     *
88     */
89    public function displayForm()
90    {
91
92        $tpl = ilStartUpGUI::initStartUpTemplate(array('tpl.usr_registration.html', 'Services/Registration'), true);
93        $tpl->setVariable('TXT_PAGEHEADLINE', $this->lng->txt('registration'));
94
95        if (!$this->form) {
96            $this->__initForm();
97        }
98        $tpl->setVariable('FORM', $this->form->getHTML());
99        return $tpl;
100    }
101
102    protected function __initForm()
103    {
104        global $DIC;
105
106        $ilUser = $DIC->user();
107
108        $ilUser->setLanguage($this->lng->getLangKey());
109        $ilUser->setId(ANONYMOUS_USER_ID);
110
111        // needed for multi-text-fields (interests)
112        iljQueryUtil::initjQuery();
113
114        $this->form = new ilPropertyFormGUI();
115        $this->form->setFormAction($this->ctrl->getFormAction($this));
116
117
118        // code handling
119
120        if ($this->code_enabled) {
121            $field = new ilFormSectionHeaderGUI();
122            $field->setTitle($this->lng->txt('registration_codes_type_reg'));
123            $this->form->addItem($field);
124            $code = new ilTextInputGUI($this->lng->txt("registration_code"), "usr_registration_code");
125            $code->setSize(40);
126            $code->setMaxLength(ilRegistrationCode::CODE_LENGTH);
127            if ((bool) $this->registration_settings->registrationCodeRequired()) {
128                $code->setRequired(true);
129                $code->setInfo($this->lng->txt("registration_code_required_info"));
130            } else {
131                $code->setInfo($this->lng->txt("registration_code_optional_info"));
132            }
133            $this->form->addItem($code);
134        }
135
136
137        // user defined fields
138        $user_defined_data = $ilUser->getUserDefinedData();
139
140        $user_defined_fields = ilUserDefinedFields::_getInstance();
141        $custom_fields = array();
142
143        foreach ($user_defined_fields->getRegistrationDefinitions() as $field_id => $definition) {
144            $fprop = ilCustomUserFieldsHelper::getInstance()->getFormPropertyForDefinition(
145                $definition,
146                true,
147                $user_defined_data['f_' . $field_id]
148            );
149            if ($fprop instanceof ilFormPropertyGUI) {
150                $custom_fields['udf_' . $definition['field_id']] = $fprop;
151            }
152        }
153
154        // standard fields
155        $up = new ilUserProfile();
156        $up->setMode(ilUserProfile::MODE_REGISTRATION);
157        $up->skipGroup("preferences");
158
159        $up->setAjaxCallback(
160            $this->ctrl->getLinkTarget($this, 'doProfileAutoComplete', '', true)
161        );
162
163        $this->lng->loadLanguageModule("user");
164
165        // add fields to form
166        $up->addStandardFieldsToForm($this->form, null, $custom_fields);
167        unset($custom_fields);
168
169
170        // set language selection to current display language
171        $flang = $this->form->getItemByPostVar("usr_language");
172        if ($flang) {
173            $flang->setValue($this->lng->getLangKey());
174        }
175
176        // add information to role selection (if not hidden)
177        if ($this->code_enabled) {
178            $role = $this->form->getItemByPostVar("usr_roles");
179            if ($role && $role->getType() == "select") {
180                $role->setInfo($this->lng->txt("registration_code_role_info"));
181            }
182        }
183
184        // #11407
185        $domains = array();
186        foreach ($this->registration_settings->getAllowedDomains() as $item) {
187            if (trim($item)) {
188                $domains[] = $item;
189            }
190        }
191        if (sizeof($domains)) {
192            $mail_obj = $this->form->getItemByPostVar('usr_email');
193            $mail_obj->setInfo(sprintf(
194                $this->lng->txt("reg_email_domains"),
195                implode(", ", $domains)
196            ) . "<br />" .
197                ($this->code_enabled ? $this->lng->txt("reg_email_domains_code") : ""));
198        }
199
200        // #14272
201        if ($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION) {
202            $mail_obj = $this->form->getItemByPostVar('usr_email');
203            if ($mail_obj) { // #16087
204                $mail_obj->setRequired(true);
205            }
206        }
207
208        if (\ilTermsOfServiceHelper::isEnabled() && $this->termsOfServiceEvaluation->hasDocument()) {
209            $document = $this->termsOfServiceEvaluation->document();
210
211            $field = new ilFormSectionHeaderGUI();
212            $field->setTitle($this->lng->txt('usr_agreement'));
213            $this->form->addItem($field);
214
215            $field = new ilCustomInputGUI();
216            $field->setHTML('<div id="agreement">' . $document->content() . '</div>');
217            $this->form->addItem($field);
218
219            $field = new ilCheckboxInputGUI($this->lng->txt('accept_usr_agreement'), 'accept_terms_of_service');
220            $field->setRequired(true);
221            $field->setValue(1);
222            $this->form->addItem($field);
223        }
224
225
226        if (ilCaptchaUtil::isActiveForRegistration()) {
227            $captcha = new ilCaptchaInputGUI($this->lng->txt("captcha_code"), 'captcha_code');
228            $captcha->setRequired(true);
229            $this->form->addItem($captcha);
230        }
231
232        $this->form->addCommandButton("saveForm", $this->lng->txt("register"));
233    }
234
235    public function saveForm()
236    {
237        global $DIC;
238
239        $ilSetting = $DIC->settings();
240        $rbacreview = $DIC->rbac()->review();
241
242        $this->__initForm();
243        $form_valid = $this->form->checkInput();
244
245        // custom validation
246        $valid_code = $valid_role = false;
247
248        // code
249        if ($this->code_enabled) {
250            $code = $this->form->getInput('usr_registration_code');
251            // could be optional
252            if (
253                $this->registration_settings->registrationCodeRequired() ||
254                strlen($code)
255            ) {
256                // code validation
257                if (!ilRegistrationCode::isValidRegistrationCode($code)) {
258                    $code_obj = $this->form->getItemByPostVar('usr_registration_code');
259                    $code_obj->setAlert($this->lng->txt('registration_code_not_valid'));
260                    $form_valid = false;
261                } else {
262                    $valid_code = true;
263
264                    // get role from code, check if (still) valid
265                    $role_id = (int) ilRegistrationCode::getCodeRole($code);
266                    if ($role_id && $rbacreview->isGlobalRole($role_id)) {
267                        $valid_role = $role_id;
268                    }
269                }
270            }
271        }
272
273        // valid codes override email domain check
274        if (!$valid_code) {
275            // validate email against restricted domains
276            $email = $this->form->getInput("usr_email");
277            if ($email) {
278                // #10366
279                $domains = array();
280                foreach ($this->registration_settings->getAllowedDomains() as $item) {
281                    if (trim($item)) {
282                        $domains[] = $item;
283                    }
284                }
285                if (sizeof($domains)) {
286                    $mail_valid = false;
287                    foreach ($domains as $domain) {
288                        $domain = str_replace("*", "~~~", $domain);
289                        $domain = preg_quote($domain);
290                        $domain = str_replace("~~~", ".+", $domain);
291                        if (preg_match("/^" . $domain . "$/", $email, $hit)) {
292                            $mail_valid = true;
293                            break;
294                        }
295                    }
296                    if (!$mail_valid) {
297                        $mail_obj = $this->form->getItemByPostVar('usr_email');
298                        $mail_obj->setAlert(sprintf(
299                            $this->lng->txt("reg_email_domains"),
300                            implode(", ", $domains)
301                        ));
302                        $form_valid = false;
303                    }
304                }
305            }
306        }
307
308        $error_lng_var = '';
309        if (
310            !$this->registration_settings->passwordGenerationEnabled() &&
311            !ilUtil::isPasswordValidForUserContext($this->form->getInput('usr_password'), $this->form->getInput('username'), $error_lng_var)
312        ) {
313            $passwd_obj = $this->form->getItemByPostVar('usr_password');
314            $passwd_obj->setAlert($this->lng->txt($error_lng_var));
315            $form_valid = false;
316        }
317
318        $showGlobalTermsOfServieFailure = false;
319        if (\ilTermsOfServiceHelper::isEnabled() && !$this->form->getInput('accept_terms_of_service')) {
320            $agr_obj = $this->form->getItemByPostVar('accept_terms_of_service');
321            if ($agr_obj) {
322                $agr_obj->setAlert($this->lng->txt('force_accept_usr_agreement'));
323                $form_valid = false;
324            } else {
325                $showGlobalTermsOfServieFailure = true;
326            }
327        }
328
329        // no need if role is attached to code
330        if (!$valid_role) {
331            // manual selection
332            if ($this->registration_settings->roleSelectionEnabled()) {
333                $selected_role = $this->form->getInput("usr_roles");
334                if ($selected_role && ilObjRole::_lookupAllowRegister($selected_role)) {
335                    $valid_role = (int) $selected_role;
336                }
337            }
338            // assign by email
339            else {
340                $registration_role_assignments = new ilRegistrationRoleAssignments();
341                $valid_role = (int) $registration_role_assignments->getRoleByEmail($this->form->getInput("usr_email"));
342            }
343        }
344
345        // no valid role could be determined
346        if (!$valid_role) {
347            ilUtil::sendInfo($this->lng->txt("registration_no_valid_role"));
348            $form_valid = false;
349        }
350
351        // validate username
352        $login_obj = $this->form->getItemByPostVar('username');
353        $login = $this->form->getInput("username");
354        $captcha = $this->form->getItemByPostVar("captcha_code");
355        if (!ilUtil::isLogin($login)) {
356            $login_obj->setAlert($this->lng->txt("login_invalid"));
357            $form_valid = false;
358        } elseif (ilObjUser::_loginExists($login)) {
359            if(!empty($captcha) && empty($captcha->getAlert()) || empty($captcha)) {
360                $login_obj->setAlert($this->lng->txt("login_exists"));
361            }
362            $form_valid = false;
363        } elseif ((int) $ilSetting->get('allow_change_loginname') &&
364            (int) $ilSetting->get('reuse_of_loginnames') == 0 &&
365            ilObjUser::_doesLoginnameExistInHistory($login)) {
366            if(!empty($captcha) && empty($captcha->getAlert()) || empty($captcha)) {
367                $login_obj->setAlert($this->lng->txt("login_exists"));
368            }
369            $form_valid = false;
370        }
371
372        if (!$form_valid) {
373            ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
374        } elseif ($showGlobalTermsOfServieFailure) {
375            $this->lng->loadLanguageModule('tos');
376            \ilUtil::sendFailure(sprintf(
377                $this->lng->txt('tos_account_reg_not_possible'),
378                'mailto:' . ilUtil::prepareFormOutput(ilSystemSupportContacts::getMailsToAddress())
379            ));
380        } else {
381            $password = $this->__createUser($valid_role);
382            $this->__distributeMails($password);
383            return $this->login();
384        }
385        $this->form->setValuesByPost();
386        return $this->displayForm();
387    }
388
389    protected function __createUser($a_role)
390    {
391        /**
392         * @var $ilSetting ilSetting
393         * @var $rbacadmin ilRbacAdmin
394         */
395        global $DIC;
396
397        $ilSetting = $DIC->settings();
398        $rbacadmin = $DIC->rbac()->admin();
399
400
401        // something went wrong with the form validation
402        if (!$a_role) {
403            global $DIC;
404
405            $ilias = $DIC['ilias'];
406            $ilias->raiseError("Invalid role selection in registration" .
407                ", IP: " . $_SERVER["REMOTE_ADDR"], $ilias->error_obj->FATAL);
408        }
409
410
411        $this->userObj = new ilObjUser();
412
413        $up = new ilUserProfile();
414        $up->setMode(ilUserProfile::MODE_REGISTRATION);
415
416        $map = array();
417        $up->skipGroup("preferences");
418        $up->skipGroup("settings");
419        $up->skipField("password");
420        $up->skipField("birthday");
421        $up->skipField("upload");
422        foreach ($up->getStandardFields() as $k => $v) {
423            if ($v["method"]) {
424                $method = "set" . substr($v["method"], 3);
425                if (method_exists($this->userObj, $method)) {
426                    if ($k != "username") {
427                        $k = "usr_" . $k;
428                    }
429                    $field_obj = $this->form->getItemByPostVar($k);
430                    if ($field_obj) {
431                        $this->userObj->$method($this->form->getInput($k));
432                    }
433                }
434            }
435        }
436
437        $this->userObj->setFullName();
438
439        $birthday_obj = $this->form->getItemByPostVar("usr_birthday");
440        if ($birthday_obj) {
441            $birthday = $this->form->getInput("usr_birthday");
442            $this->userObj->setBirthday($birthday);
443        }
444
445        $this->userObj->setTitle($this->userObj->getFullname());
446        $this->userObj->setDescription($this->userObj->getEmail());
447
448        if ($this->registration_settings->passwordGenerationEnabled()) {
449            $password = ilUtil::generatePasswords(1);
450            $password = $password[0];
451        } else {
452            $password = $this->form->getInput("usr_password");
453        }
454        $this->userObj->setPasswd($password);
455
456
457        // Set user defined data
458        $user_defined_fields = &ilUserDefinedFields::_getInstance();
459        $defs = $user_defined_fields->getRegistrationDefinitions();
460        $udf = array();
461        foreach ($_POST as $k => $v) {
462            if (substr($k, 0, 4) == "udf_") {
463                $f = substr($k, 4);
464                $udf[$f] = $v;
465            }
466        }
467        $this->userObj->setUserDefinedData($udf);
468
469        $this->userObj->setTimeLimitOwner(7);
470
471
472        $access_limit = null;
473
474        $this->code_was_used = false;
475        if ($this->code_enabled) {
476            $code_local_roles = $code_has_access_limit = null;
477
478            // #10853 - could be optional
479            $code = $this->form->getInput('usr_registration_code');
480            if ($code) {
481
482                // set code to used
483                ilRegistrationCode::useCode($code);
484                $this->code_was_used = true;
485
486                // handle code attached local role(s) and access limitation
487                $code_data = ilRegistrationCode::getCodeData($code);
488                if ($code_data["role_local"]) {
489                    // need user id before we can assign role(s)
490                    $code_local_roles = explode(";", $code_data["role_local"]);
491                }
492                if ($code_data["alimit"]) {
493                    // see below
494                    $code_has_access_limit = true;
495
496                    switch ($code_data["alimit"]) {
497                        case "absolute":
498                            $abs = date_parse($code_data["alimitdt"]);
499                            $access_limit = mktime(23, 59, 59, $abs['month'], $abs['day'], $abs['year']);
500                            break;
501
502                        case "relative":
503                            $rel = unserialize($code_data["alimitdt"]);
504                            $access_limit = $rel["d"] * 86400 + $rel["m"] * 2592000 +
505                                $rel["y"] * 31536000 + time();
506                            break;
507                    }
508                }
509            }
510        }
511
512        // code access limitation will override any other access limitation setting
513        if (!($this->code_was_used && $code_has_access_limit) &&
514            $this->registration_settings->getAccessLimitation()) {
515            $access_limitations_obj = new ilRegistrationRoleAccessLimitations();
516            switch ($access_limitations_obj->getMode($a_role)) {
517                case 'absolute':
518                    $access_limit = $access_limitations_obj->getAbsolute($a_role);
519                    break;
520
521                case 'relative':
522                    $rel_d = (int) $access_limitations_obj->getRelative($a_role, 'd');
523                    $rel_m = (int) $access_limitations_obj->getRelative($a_role, 'm');
524                    $rel_y = (int) $access_limitations_obj->getRelative($a_role, 'y');
525                    $access_limit = $rel_d * 86400 + $rel_m * 2592000 + $rel_y * 31536000 + time();
526                    break;
527            }
528        }
529
530        if ($access_limit) {
531            $this->userObj->setTimeLimitUnlimited(0);
532            $this->userObj->setTimeLimitUntil($access_limit);
533        } else {
534            $this->userObj->setTimeLimitUnlimited(1);
535            $this->userObj->setTimeLimitUntil(time());
536        }
537
538        $this->userObj->setTimeLimitFrom(time());
539
540        ilUserCreationContext::getInstance()->addContext(ilUserCreationContext::CONTEXT_REGISTRATION);
541
542        $this->userObj->create();
543
544
545        if ($this->registration_settings->getRegistrationType() == IL_REG_DIRECT ||
546            $this->registration_settings->getRegistrationType() == IL_REG_CODES ||
547            $this->code_was_used) {
548            $this->userObj->setActive(1, 0);
549        } elseif ($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION) {
550            $this->userObj->setActive(0, 0);
551        } else {
552            $this->userObj->setActive(0, 0);
553        }
554
555        $this->userObj->updateOwner();
556
557        // set a timestamp for last_password_change
558        // this ts is needed by ilSecuritySettings
559        $this->userObj->setLastPasswordChangeTS(time());
560
561        $this->userObj->setIsSelfRegistered(true);
562
563        //insert user data in table user_data
564        $this->userObj->saveAsNew();
565
566        // setup user preferences
567        $this->userObj->setLanguage($this->form->getInput('usr_language'));
568
569        $handleDocument = \ilTermsOfServiceHelper::isEnabled() && $this->termsOfServiceEvaluation->hasDocument();
570        if ($handleDocument) {
571            $helper = new \ilTermsOfServiceHelper();
572
573            $helper->trackAcceptance($this->userObj, $this->termsOfServiceEvaluation->document());
574        }
575
576        $hits_per_page = $ilSetting->get("hits_per_page");
577        if ($hits_per_page < 10) {
578            $hits_per_page = 10;
579        }
580        $this->userObj->setPref("hits_per_page", $hits_per_page);
581        if (strlen($_GET['target']) > 0) {
582            $this->userObj->setPref('reg_target', ilUtil::stripSlashes($_GET['target']));
583        }
584        /*$show_online = $ilSetting->get("show_users_online");
585        if ($show_online == "")
586        {
587            $show_online = "y";
588        }
589        $this->userObj->setPref("show_users_online", $show_online);*/
590        $this->userObj->setPref('bs_allow_to_contact_me', $ilSetting->get('bs_allow_to_contact_me', 'n'));
591        $this->userObj->setPref('chat_osc_accept_msg', $ilSetting->get('chat_osc_accept_msg', 'n'));
592        $this->userObj->writePrefs();
593
594
595        $rbacadmin->assignUser((int) $a_role, $this->userObj->getId());
596
597        // local roles from code
598        if ($this->code_was_used && is_array($code_local_roles)) {
599            foreach (array_unique($code_local_roles) as $local_role_obj_id) {
600                // is given role (still) valid?
601                if (ilObject::_lookupType($local_role_obj_id) == "role") {
602                    $rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId());
603
604                    // patch to remove for 45 due to mantis 21953
605                    $role_obj = $GLOBALS['DIC']['rbacreview']->getObjectOfRole($local_role_obj_id);
606                    switch (ilObject::_lookupType($role_obj)) {
607                        case 'crs':
608                        case 'grp':
609                            $role_refs = ilObject::_getAllReferences($role_obj);
610                            $role_ref = end($role_refs);
611                            // deactivated for now, see discussion at
612                            // https://docu.ilias.de/goto_docu_wiki_wpage_5620_1357.html
613                            // $this->recommended_content_manager->addObjectRecommendation($this->userObj->getId(), $role_ref);
614                            break;
615                    }
616                }
617            }
618        }
619
620        return $password;
621    }
622
623    protected function __distributeMails($password)
624    {
625
626        // Always send mail to approvers
627        if ($this->registration_settings->getRegistrationType() == IL_REG_APPROVE && !$this->code_was_used) {
628            $mail = new ilRegistrationMailNotification();
629            $mail->setType(ilRegistrationMailNotification::TYPE_NOTIFICATION_CONFIRMATION);
630            $mail->setRecipients($this->registration_settings->getApproveRecipients());
631            $mail->setAdditionalInformation(array('usr' => $this->userObj));
632            $mail->send();
633        } else {
634            $mail = new ilRegistrationMailNotification();
635            $mail->setType(ilRegistrationMailNotification::TYPE_NOTIFICATION_APPROVERS);
636            $mail->setRecipients($this->registration_settings->getApproveRecipients());
637            $mail->setAdditionalInformation(array('usr' => $this->userObj));
638            $mail->send();
639        }
640
641        // Send mail to new user
642        // Registration with confirmation link ist enabled
643        if ($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION && !$this->code_was_used) {
644
645            $mail = new ilRegistrationMimeMailNotification();
646            $mail->setType(ilRegistrationMimeMailNotification::TYPE_NOTIFICATION_ACTIVATION);
647            $mail->setRecipients(array($this->userObj));
648            $mail->setAdditionalInformation(
649                array(
650                     'usr' => $this->userObj,
651                     'hash_lifetime' => $this->registration_settings->getRegistrationHashLifetime()
652                )
653            );
654            $mail->send();
655        } else {
656            $accountMail = new ilAccountRegistrationMail(
657                $this->registration_settings,
658                $this->lng,
659                ilLoggerFactory::getLogger('user')
660            );
661            $accountMail->withDirectRegistrationMode()->send($this->userObj, $password, $this->code_was_used);
662        }
663    }
664
665    public function login()
666    {
667        global $DIC;
668        $f = $DIC->ui()->factory();
669        $renderer = $DIC->ui()->renderer();
670
671        $tpl = ilStartUpGUI::initStartUpTemplate(array('tpl.usr_registered.html', 'Services/Registration'), false);
672        $this->tpl->setVariable('TXT_PAGEHEADLINE', $this->lng->txt('registration'));
673
674        $tpl->setVariable("TXT_WELCOME", $this->lng->txt("welcome") . ", " . $this->userObj->getTitle() . "!");
675        if (
676            (
677                $this->registration_settings->getRegistrationType() == IL_REG_DIRECT ||
678                $this->registration_settings->getRegistrationType() == IL_REG_CODES ||
679                $this->code_was_used
680            ) &&
681            !$this->registration_settings->passwordGenerationEnabled()
682        ) {
683            $tpl->setVariable('TXT_REGISTERED', $this->lng->txt('txt_registered'));
684
685            $login_link = $renderer->render($f->link()->standard($this->lng->txt('login_to_ilias'), './login.php?cmd=force_login&lang=' . $this->userObj->getLanguage()));
686            $tpl->setVariable('LOGIN_LINK', $login_link);
687        } elseif ($this->registration_settings->getRegistrationType() == IL_REG_APPROVE) {
688            $tpl->setVariable('TXT_REGISTERED', $this->lng->txt('txt_submitted'));
689        } elseif ($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION) {
690            $tpl->setVariable('TXT_REGISTERED', $this->lng->txt('reg_confirmation_link_successful'));
691        } else {
692            $tpl->setVariable('TXT_REGISTERED', $this->lng->txt('txt_registered_passw_gen'));
693        }
694        return $tpl;
695    }
696
697    /**
698     * Do Login
699     * @todo refactor this method should be renamed, but i don't wanted to make changed in
700     * tpl.usr_registered.html in stable release.
701     */
702    protected function showLogin()
703    {
704        global $DIC;
705        /**
706         * @var ilAuthSession
707         */
708        $auth_session = $DIC['ilAuthSession'];
709        $auth_session->setAuthenticated(
710            true,
711            $DIC->user()->getId()
712        );
713        ilInitialisation::initUserAccount();
714        return ilInitialisation::redirectToStartingPage();
715    }
716
717    protected function doProfileAutoComplete()
718    {
719        $field_id = (string) $_REQUEST["f"];
720        $term = (string) $_REQUEST["term"];
721
722        $result = ilPublicUserProfileGUI::getAutocompleteResult($field_id, $term);
723        if (sizeof($result)) {
724            echo ilJsonUtil::encode($result);
725        }
726
727        exit();
728    }
729}
730