18 require_once
'./Services/Registration/classes/class.ilRegistrationSettings.php';
19 require_once
'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
44 $ilCtrl = $DIC->ctrl();
46 $lng = $DIC->language();
50 $this->ctrl =&$ilCtrl;
51 $this->ctrl->saveParameter($this,
'lang');
54 $this->lng->loadLanguageModule(
'registration');
58 $this->code_enabled = ($this->registration_settings->registrationCodeRequired() ||
59 $this->registration_settings->getAllowCodes());
61 $this->termsOfServiceEvaluation = $DIC[
'tos.document.evaluator'];
69 if ($this->registration_settings->getRegistrationType() ==
IL_REG_DISABLED) {
71 $ilErr->raiseError($this->lng->txt(
'reg_disabled'),
$ilErr->FATAL);
74 $cmd = $this->ctrl->getCmd();
80 $tpl = $this->displayForm();
84 $gtpl->setPermanentLink(
'usr', null,
'registration');
91 public function displayForm()
97 $tpl = ilStartUpGUI::initStartUpTemplate(array(
'tpl.usr_registration.html',
'Services/Registration'),
true);
98 $tpl->setVariable(
'TXT_PAGEHEADLINE', $this->lng->txt(
'registration'));
103 $tpl->setVariable(
'FORM', $this->form->getHTML());
113 $ilUser->setLanguage($this->lng->getLangKey());
120 $this->form->setFormAction($this->ctrl->getFormAction($this));
125 if ($this->code_enabled) {
127 $field->setTitle($this->lng->txt(
'registration_codes_type_reg'));
128 $this->form->addItem($field);
129 $code =
new ilTextInputGUI($this->lng->txt(
"registration_code"),
"usr_registration_code");
132 if ((
bool) $this->registration_settings->registrationCodeRequired()) {
133 $code->setRequired(
true);
134 $code->setInfo($this->lng->txt(
"registration_code_required_info"));
136 $code->setInfo($this->lng->txt(
"registration_code_optional_info"));
138 $this->form->addItem($code);
143 $user_defined_data =
$ilUser->getUserDefinedData();
146 $custom_fields = array();
148 foreach ($user_defined_fields->getRegistrationDefinitions() as $field_id => $definition) {
152 $user_defined_data[
'f_' . $field_id]
155 $custom_fields[
'udf_' . $definition[
'field_id']] = $fprop;
162 $up->skipGroup(
"preferences");
164 $up->setAjaxCallback(
165 $this->ctrl->getLinkTarget($this,
'doProfileAutoComplete',
'',
true)
168 $this->lng->loadLanguageModule(
"user");
171 $up->addStandardFieldsToForm($this->form, null, $custom_fields);
172 unset($custom_fields);
176 $flang = $this->form->getItemByPostVar(
"usr_language");
178 $flang->setValue($this->lng->getLangKey());
182 if ($this->code_enabled) {
183 $role = $this->form->getItemByPostVar(
"usr_roles");
184 if ($role && $role->getType() ==
"select") {
185 $role->setInfo($this->lng->txt(
"registration_code_role_info"));
191 foreach ($this->registration_settings->getAllowedDomains() as $item) {
196 if (
sizeof($domains)) {
197 $mail_obj = $this->form->getItemByPostVar(
'usr_email');
198 $mail_obj->setInfo(sprintf(
199 $this->lng->txt(
"reg_email_domains"),
200 implode(
", ", $domains)
202 ($this->code_enabled ? $this->lng->txt(
"reg_email_domains_code") :
""));
207 $mail_obj = $this->form->getItemByPostVar(
'usr_email');
209 $mail_obj->setRequired(
true);
214 $document = $this->termsOfServiceEvaluation->document();
217 $field->setTitle($this->lng->txt(
'usr_agreement'));
218 $this->form->addItem($field);
221 $field->setHTML(
'<div id="agreement">' . $document->content() .
'</div>');
222 $this->form->addItem($field);
224 $field =
new ilCheckboxInputGUI($this->lng->txt(
'accept_usr_agreement'),
'accept_terms_of_service');
227 $this->form->addItem($field);
230 require_once
'Services/Captcha/classes/class.ilCaptchaUtil.php';
231 if (ilCaptchaUtil::isActiveForRegistration()) {
232 require_once
'Services/Captcha/classes/class.ilCaptchaInputGUI.php';
233 $captcha =
new ilCaptchaInputGUI($this->lng->txt(
"captcha_code"),
'captcha_code');
235 $this->form->addItem($captcha);
238 $this->form->addCommandButton(
"saveForm", $this->lng->txt(
"register"));
246 $rbacreview = $DIC->rbac()->review();
249 $form_valid = $this->form->checkInput();
254 $valid_code = $valid_role =
false;
257 if ($this->code_enabled) {
258 $code = $this->form->getInput(
'usr_registration_code');
261 $this->registration_settings->registrationCodeRequired() ||
266 $code_obj = $this->form->getItemByPostVar(
'usr_registration_code');
267 $code_obj->setAlert($this->lng->txt(
'registration_code_not_valid'));
274 if ($role_id && $rbacreview->isGlobalRole($role_id)) {
275 $valid_role = $role_id;
284 $email = $this->form->getInput(
"usr_email");
288 foreach ($this->registration_settings->getAllowedDomains() as $item) {
293 if (
sizeof($domains)) {
295 foreach ($domains as $domain) {
296 $domain = str_replace(
"*",
"~~~", $domain);
297 $domain = preg_quote($domain);
298 $domain = str_replace(
"~~~",
".+", $domain);
299 if (preg_match(
"/^" . $domain .
"$/",
$email, $hit)) {
305 $mail_obj = $this->form->getItemByPostVar(
'usr_email');
306 $mail_obj->setAlert(sprintf(
307 $this->lng->txt(
"reg_email_domains"),
308 implode(
", ", $domains)
318 !$this->registration_settings->passwordGenerationEnabled() &&
321 $passwd_obj = $this->form->getItemByPostVar(
'usr_password');
322 $passwd_obj->setAlert($this->lng->txt($error_lng_var));
326 $showGlobalTermsOfServieFailure =
false;
328 $agr_obj = $this->form->getItemByPostVar(
'accept_terms_of_service');
330 $agr_obj->setAlert($this->lng->txt(
'force_accept_usr_agreement'));
333 $showGlobalTermsOfServieFailure =
true;
340 if ($this->registration_settings->roleSelectionEnabled()) {
341 $selected_role = $this->form->getInput(
"usr_roles");
343 $valid_role = (int) $selected_role;
349 $valid_role = (int) $registration_role_assignments->getRoleByEmail($this->form->getInput(
"usr_email"));
360 $login_obj = $this->form->getItemByPostVar(
'username');
361 $login = $this->form->getInput(
"username");
363 $login_obj->setAlert($this->lng->txt(
"login_invalid"));
369 $login_obj->setAlert($this->lng->txt(
"login_exists"));
371 } elseif ((
int)
$ilSetting->get(
'allow_change_loginname') &&
372 (int)
$ilSetting->get(
'reuse_of_loginnames') == 0 &&
374 $login_obj->setAlert($this->lng->txt(
"login_exists"));
381 } elseif ($showGlobalTermsOfServieFailure) {
382 $this->lng->loadLanguageModule(
'tos');
384 $this->lng->txt(
'tos_account_reg_not_possible'),
388 $password = $this->__createUser($valid_role);
390 return $this->
login();
392 $this->form->setValuesByPost();
393 return $this->displayForm();
396 protected function __createUser($a_role)
406 $rbacadmin = $DIC->rbac()->admin();
413 $ilias = $DIC[
'ilias'];
414 $ilias->raiseError(
"Invalid role selection in registration" .
415 ", IP: " .
$_SERVER[
"REMOTE_ADDR"], $ilias->error_obj->FATAL);
425 $up->skipGroup(
"preferences");
426 $up->skipGroup(
"settings");
427 $up->skipField(
"password");
428 $up->skipField(
"birthday");
429 $up->skipField(
"upload");
430 foreach ($up->getStandardFields() as $k => $v) {
432 $method =
"set" . substr($v[
"method"], 3);
433 if (method_exists($this->userObj, $method)) {
434 if ($k !=
"username") {
437 $field_obj = $this->form->getItemByPostVar($k);
439 $this->userObj->$method($this->form->getInput($k));
445 $this->userObj->setFullName();
447 $birthday_obj = $this->form->getItemByPostVar(
"usr_birthday");
449 $birthday = $this->form->getInput(
"usr_birthday");
450 $this->userObj->setBirthday($birthday);
453 $this->userObj->setTitle($this->userObj->getFullname());
454 $this->userObj->setDescription($this->userObj->getEmail());
456 if ($this->registration_settings->passwordGenerationEnabled()) {
460 $password = $this->form->getInput(
"usr_password");
467 $defs = $user_defined_fields->getRegistrationDefinitions();
469 foreach (
$_POST as $k => $v) {
470 if (substr($k, 0, 4) ==
"udf_") {
475 $this->userObj->setUserDefinedData($udf);
477 $this->userObj->setTimeLimitOwner(7);
480 $access_limit = null;
482 $this->code_was_used =
false;
483 if ($this->code_enabled) {
484 $code_local_roles = $code_has_access_limit = null;
487 $code = $this->form->getInput(
'usr_registration_code');
492 $this->code_was_used =
true;
496 if ($code_data[
"role_local"]) {
498 $code_local_roles = explode(
";", $code_data[
"role_local"]);
500 if ($code_data[
"alimit"]) {
502 $code_has_access_limit =
true;
504 switch ($code_data[
"alimit"]) {
506 $abs = date_parse($code_data[
"alimitdt"]);
507 $access_limit = mktime(23, 59, 59, $abs[
'month'], $abs[
'day'], $abs[
'year']);
511 $rel = unserialize($code_data[
"alimitdt"]);
512 $access_limit = $rel[
"d"] * 86400 + $rel[
"m"] * 2592000 + $rel[
"y"] * 31536000 + time();
520 if (!($this->code_was_used && $code_has_access_limit) &&
521 $this->registration_settings->getAccessLimitation()) {
523 switch ($access_limitations_obj->getMode($a_role)) {
525 $access_limit = $access_limitations_obj->getAbsolute($a_role);
529 $rel_d = (int) $access_limitations_obj->getRelative($a_role,
'd');
530 $rel_m = (int) $access_limitations_obj->getRelative($a_role,
'm');
531 $access_limit = $rel_d * 86400 + $rel_m * 2592000 + time();
537 $this->userObj->setTimeLimitUnlimited(0);
538 $this->userObj->setTimeLimitUntil($access_limit);
540 $this->userObj->setTimeLimitUnlimited(1);
541 $this->userObj->setTimeLimitUntil(time());
544 $this->userObj->setTimeLimitFrom(time());
548 $this->userObj->create();
551 if ($this->registration_settings->getRegistrationType() ==
IL_REG_DIRECT ||
552 $this->registration_settings->getRegistrationType() ==
IL_REG_CODES ||
554 $this->userObj->setActive(1, 0);
555 } elseif ($this->registration_settings->getRegistrationType() ==
IL_REG_ACTIVATION) {
556 $this->userObj->setActive(0, 0);
558 $this->userObj->setActive(0, 0);
561 $this->userObj->updateOwner();
565 $this->userObj->setLastPasswordChangeTS(time());
567 $this->userObj->setIsSelfRegistered(
true);
570 $this->userObj->saveAsNew();
573 $this->userObj->setLanguage($this->form->getInput(
'usr_language'));
576 if ($handleDocument) {
577 $helper = new \ilTermsOfServiceHelper();
579 $helper->trackAcceptance($this->userObj, $this->termsOfServiceEvaluation->document());
582 $hits_per_page =
$ilSetting->get(
"hits_per_page");
583 if ($hits_per_page < 10) {
586 $this->userObj->setPref(
"hits_per_page", $hits_per_page);
587 if (strlen(
$_GET[
'target']) > 0) {
596 $this->userObj->setPref(
'bs_allow_to_contact_me',
$ilSetting->get(
'bs_allow_to_contact_me',
'n'));
597 $this->userObj->setPref(
'chat_osc_accept_msg',
$ilSetting->get(
'chat_osc_accept_msg',
'n'));
598 $this->userObj->writePrefs();
601 $rbacadmin->assignUser((
int) $a_role, $this->userObj->getId());
604 if ($this->code_was_used && is_array($code_local_roles)) {
605 foreach (array_unique($code_local_roles) as $local_role_obj_id) {
608 $rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId());
611 $role_obj =
$GLOBALS[
'DIC'][
'rbacreview']->getObjectOfRole($local_role_obj_id);
616 $role_ref = end($role_refs);
635 $mail->setRecipients($this->registration_settings->getApproveRecipients());
636 $mail->setAdditionalInformation(array(
'usr' => $this->userObj));
641 $mail->setRecipients($this->registration_settings->getApproveRecipients());
642 $mail->setAdditionalInformation(array(
'usr' => $this->userObj));
652 $mail->setRecipients(array($this->userObj));
653 $mail->setAdditionalInformation(
655 'usr' => $this->userObj,
656 'hash_lifetime' => $this->registration_settings->getRegistrationHashLifetime()
662 $this->registration_settings,
666 $accountMail->withDirectRegistrationMode()->send($this->userObj,
$password, $this->code_was_used);
673 $f = $DIC->ui()->factory();
674 $renderer = $DIC->ui()->renderer();
676 $tpl = ilStartUpGUI::initStartUpTemplate(array(
'tpl.usr_registered.html',
'Services/Registration'),
false);
677 $this->tpl->setVariable(
'TXT_PAGEHEADLINE', $this->lng->txt(
'registration'));
679 $tpl->setVariable(
"TXT_WELCOME", $this->lng->txt(
"welcome") .
", " . $this->userObj->getTitle() .
"!");
682 $this->registration_settings->getRegistrationType() ==
IL_REG_DIRECT ||
683 $this->registration_settings->getRegistrationType() ==
IL_REG_CODES ||
686 !$this->registration_settings->passwordGenerationEnabled()
688 $tpl->setVariable(
'TXT_REGISTERED', $this->lng->txt(
'txt_registered'));
690 $login_link = $renderer->render(
$f->link()->standard($this->lng->txt(
'login_to_ilias'),
'./login.php?cmd=force_login&lang=' . $this->userObj->getLanguage()));
691 $tpl->setVariable(
'LOGIN_LINK', $login_link);
692 } elseif ($this->registration_settings->getRegistrationType() ==
IL_REG_APPROVE) {
693 $tpl->setVariable(
'TXT_REGISTERED', $this->lng->txt(
'txt_submitted'));
694 } elseif ($this->registration_settings->getRegistrationType() ==
IL_REG_ACTIVATION) {
695 $tpl->setVariable(
'TXT_REGISTERED', $this->lng->txt(
'reg_confirmation_link_successful'));
697 $tpl->setVariable(
'TXT_REGISTERED', $this->lng->txt(
'txt_registered_passw_gen'));
707 protected function showLogin()
713 $auth_session = $DIC[
'ilAuthSession'];
714 $auth_session->setAuthenticated(
716 $DIC->user()->getId()
719 return ilInitialisation::redirectToStartingPage();
724 $field_id = (string) $_REQUEST[
"f"];
725 $term = (string) $_REQUEST[
"term"];
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
$termsOfServiceEvaluation
static getCodeData($code)
Class for mime mail registration notifications.
static _getInstance()
Get instance.
Class ilAccountRegistrationGUI.
static isPasswordValidForUserContext($clear_text_password, $user, &$error_language_variable=null)
static getInstance()
Get instance.
const TYPE_NOTIFICATION_ACTIVATION
static getAutocompleteResult($a_field_id, $a_term)
static generatePasswords($a_number)
Generate a number of passwords.
__distributeMails($password)
static printToGlobalTemplate($tpl)
static _getAllReferences($a_id)
get all reference ids of object
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getInstance()
Get instance.
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...
const TYPE_NOTIFICATION_APPROVERS
static getCodeRole($code)
static encode($mixed, $suppress_native=false)
Class ilAccountRegistrationMail.
static isValidRegistrationCode($a_code)
Check if given code is a valid registration code.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Class ilObjAuthSettingsGUI.
$recommended_content_manager
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
static getLogger($a_component_id)
Get component logger.
static initUserAccount()
Init user with current account id.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
const CONTEXT_REGISTRATION
static _lookupAllowRegister($a_role_id)
check whether role is allowed in user registration or not
Recommended content manager (business logic)
static _doesLoginnameExistInHistory($a_login)
Checks wether the passed loginname already exists in history.
const TYPE_NOTIFICATION_CONFIRMATION