'.get_lang('Follow courses').'
', - COURSEMANAGER => ''.get_lang('Teach courses').'
', - ], - ['class' => 'register-profile'] - ); - $form->addRule('status', get_lang('Required field'), 'required'); - } - } - $LastnameLabel = get_lang('Last name'); if ('true' === api_get_setting('profile.registration_add_helptext_for_2_names')) { $LastnameLabel = [$LastnameLabel, get_lang('Insert your two names')]; @@ -364,55 +667,25 @@ function ($email) { } // PHONE - if (in_array('phone', $allowedFields)) { - $form->addElement( - 'text', - 'phone', - get_lang('Phone'), - ['size' => 20] - ); - $form->addRule( - 'phone', - get_lang('Required field'), - 'required' - ); + if (in_array('phone', $allowedFields, true)) { + $form->addElement('text', 'phone', get_lang('Phone'), ['size' => 20]); + $form->addRule('phone', get_lang('Required field'), 'required'); } // Language - if (in_array('language', $allowedFields)) { - $form->addSelectLanguage( - 'language', - get_lang('Language'), - [], - ['id' => 'language'] - ); + if (in_array('language', $allowedFields, true)) { + $form->addSelectLanguage('language', get_lang('Language'), [], ['id' => 'language']); } - if (in_array('official_code', $allowedFields)) { - $form->addElement( - 'text', - 'official_code', - get_lang('Official code'), - ['size' => 40] - ); - $form->addRule( - 'official_code', - get_lang('Required field'), - 'required' - ); + if (in_array('official_code', $allowedFields, true)) { + $form->addElement('text', 'official_code', get_lang('Official code'), ['size' => 40]); + $form->addRule('official_code', get_lang('Required field'), 'required'); } if (in_array('date_of_birth', $allowedFields, true)) { - $form->addDatePicker( - 'date_of_birth', - get_lang('Date of birth'), - ['required' => false] - ); + $form->addDatePicker('date_of_birth', get_lang('Date of birth'), ['required' => false]); } - $captcha = api_get_setting('allow_captcha'); - $allowCaptcha = 'true' === $captcha; - // EXTENDED FIELDS if ('true' === api_get_setting('extended_profile') && 'true' === api_get_setting('extendedprofile_registration', 'mycomptetences') @@ -485,20 +758,11 @@ function ($email) { } } - $form->addElement( - 'hidden', - 'extra_tcc_user_id' - ); - - $form->addElement( - 'hidden', - 'extra_tcc_hash_key' - ); + $form->addElement('hidden', 'extra_tcc_user_id'); + $form->addElement('hidden', 'extra_tcc_hash_key'); // EXTRA FIELDS - if (array_key_exists('extra_fields', $allowedFields) || - in_array('extra_fields', $allowedFields) - ) { + if (array_key_exists('extra_fields', $allowedFields) || in_array('extra_fields', $allowedFields, true)) { $extraField = new ExtraField('user'); $extraFieldList = []; if (isset($allowedFields['extra_fields']) && is_array($allowedFields['extra_fields'])) { @@ -511,7 +775,7 @@ function ($email) { $requiredFields = $requiredFields['options']; } - $returnParams = $extraField->addElements( + $extraField->addElements( $form, 0, [], @@ -547,37 +811,15 @@ function ($email) { 'font_size' => 20, 'font_path' => api_get_path(SYS_FONTS_PATH).'opensans/', 'font_file' => 'OpenSans-Regular.ttf', - //'output' => 'gif' ], ]; - $captcha_question = $form->addElement( - 'CAPTCHA_Image', - 'captcha_question', - '', - $options - ); + $captcha_question = $form->addElement('CAPTCHA_Image', 'captcha_question', '', $options); $form->addElement('static', null, null, get_lang('Click on the image to load a new one.')); - $form->addElement( - 'text', - 'captcha', - get_lang('Enter the letters you see.'), - ['size' => 40] - ); - $form->addRule( - 'captcha', - get_lang('Enter the characters you see on the image'), - 'required', - null, - 'client' - ); - $form->addRule( - 'captcha', - get_lang('The text you entered doesn\'t match the picture.'), - 'CAPTCHA', - $captcha_question - ); + $form->addElement('text', 'captcha', get_lang('Enter the letters you see.'), ['size' => 40]); + $form->addRule('captcha', get_lang('Enter the characters you see on the image'), 'required', null, 'client'); + $form->addRule('captcha', get_lang('The text you entered doesn\'t match the picture.'), 'CAPTCHA', $captcha_question); } } @@ -596,11 +838,9 @@ function ($email) { if (!empty($_GET['email'])) { $defaults['email'] = Security::remove_XSS($_GET['email']); } - if (!empty($_GET['phone'])) { $defaults['phone'] = Security::remove_XSS($_GET['phone']); } - if ('true' === api_get_setting('openid_authentication') && !empty($_GET['openid'])) { $defaults['openid'] = Security::remove_XSS($_GET['openid']); } @@ -625,22 +865,14 @@ function ($email) { $content .= Display::return_message(get_lang('Your account has to be approved')); } -//if openid was not found +// if openid was not found if (!empty($_GET['openid_msg']) && 'idnotfound' == $_GET['openid_msg']) { - $content .= Display::return_message(get_lang('This OpenID could not be found in our database. Please register for a new account. If you have already an account with us, please edit your profile inside your account to add this OpenID')); + $content .= Display::return_message(get_lang('This OpenID could not be found in our database. Please register for a new account. If you already an account with us, please edit your profile inside your account to add this OpenID')); } if ($extraConditions) { - $form->addCheckBox( - 'extra_platformuseconditions', - null, - get_lang('Platform use conditions') - ); - $form->addRule( - 'extra_platformuseconditions', - get_lang('Required field'), - 'required' - ); + $form->addCheckBox('extra_platformuseconditions', null, get_lang('Platform use conditions')); + $form->addRule('extra_platformuseconditions', get_lang('Required field'), 'required'); } $blockButton = false; @@ -677,17 +909,10 @@ function ($email) { $form->addLabel( null, - Display::url( - get_lang('Validate'), - 'javascript:void', - ['class' => 'btn btn--plain', 'id' => 'pre_validation'] - ) + Display::url(get_lang('Validate'), 'javascript:void', ['class' => 'btn btn--plain', 'id' => 'pre_validation']) ); $form->addHtml(''); } else { @@ -737,7 +962,8 @@ function ($email) { $values['username'] = api_substr($values['username'], 0, User::USERNAME_MAX_LENGTH); } - if ('false' === api_get_setting('allow_registration_as_teacher')) { + // Security rule: if teacher registration is disabled, force learner status. + if (!$allowTeacherRegistration) { $values['status'] = STUDENT; } @@ -749,13 +975,11 @@ function ($email) { $values['username'] = $values['email']; } - // Moved here to include extra fields when creating a user. Formerly placed after user creation // Register extra fields $extras = []; $extraParams = []; foreach ($values as $key => $value) { if ('extra_' === substr($key, 0, 6)) { - //an extra field $extras[substr($key, 6)] = $value; $extraParams[$key] = $value; } @@ -766,7 +990,7 @@ function ($email) { $values['language'] = isset($values['language']) ? $values['language'] : api_get_language_isocode(); $values['address'] = $values['address'] ?? ''; - // It gets a creator id when user is not logged + // It gets a creator id when user is not logged. $creatorId = 0; if (api_is_anonymous()) { $adminList = UserManager::get_all_administrators(); @@ -803,10 +1027,8 @@ function ($email) { $creatorId ); - // save T&C acceptance - if ('true' === api_get_setting('allow_terms_conditions') - && !empty($values['legal_accept_type']) - ) { + // Save T&C acceptance + if ('true' === api_get_setting('allow_terms_conditions') && !empty($values['legal_accept_type'])) { ChamiloHelper::saveUserTermsAcceptance($userId, $values['legal_accept_type']); } @@ -814,11 +1036,9 @@ function ($email) { $countExtraField = count($extras); if ($countExtraField > 0 && is_int($userId)) { foreach ($extras as $key => $value) { - // For array $value -> if exists key 'tmp_name' then must not be empty - // This avoid delete from user field value table when doesn't upload a file if (is_array($value)) { if (array_key_exists('tmp_name', $value) && empty($value['tmp_name'])) { - //Nothing to do + // Nothing to do. } else { if (array_key_exists('tmp_name', $value)) { $value['tmp_name'] = Security::filter_filename($value['tmp_name']); @@ -839,30 +1059,22 @@ function ($email) { $store_extended = false; $sql = "UPDATE ".Database::get_main_table(TABLE_MAIN_USER)." SET "; - if ('true' == api_get_setting('extended_profile') && - 'true' == api_get_setting('extendedprofile_registration', 'mycomptetences') - ) { + if ('true' == api_get_setting('extended_profile') && 'true' == api_get_setting('extendedprofile_registration', 'mycomptetences')) { $sql_set[] = "competences = '".Database::escape_string($values['competences'])."'"; $store_extended = true; } - if ('true' == api_get_setting('extended_profile') && - 'true' == api_get_setting('extendedprofile_registration', 'mydiplomas') - ) { + if ('true' == api_get_setting('extended_profile') && 'true' == api_get_setting('extendedprofile_registration', 'mydiplomas')) { $sql_set[] = "diplomas = '".Database::escape_string($values['diplomas'])."'"; $store_extended = true; } - if ('true' == api_get_setting('extended_profile') && - 'true' == api_get_setting('extendedprofile_registration', 'myteach') - ) { + if ('true' == api_get_setting('extended_profile') && 'true' == api_get_setting('extendedprofile_registration', 'myteach')) { $sql_set[] = "teach = '".Database::escape_string($values['teach'])."'"; $store_extended = true; } - if ('true' == api_get_setting('extended_profile') && - 'true' == api_get_setting('extendedprofile_registration', 'mypersonalopenarea') - ) { + if ('true' == api_get_setting('extended_profile') && 'true' == api_get_setting('extendedprofile_registration', 'mypersonalopenarea')) { $sql_set[] = "openarea = '".Database::escape_string($values['openarea'])."'"; $store_extended = true; } @@ -986,19 +1198,15 @@ function ($email) { 'lastName' => stripslashes($values['lastname']), 'mail' => $values['email'], 'language' => $values['language'], - 'user_id' => $userId + 'user_id' => $userId, ]; $sessionHandler->set('_user', $userData); $sessionHandler->set('_locale_user', $userEntity->getLocale()); - $is_allowedCreateCourse = isset($values['status']) && 1 == $values['status']; $sessionHandler->set('is_allowedCreateCourse', $is_allowedCreateCourse); // Stats - Container::getTrackELoginRepository() - ->createLoginRecord($userEntity, new DateTime(), $request->getClientIp()) - ; - // @todo implement Auto-subscribe according to STATUS_autosubscribe setting + Container::getTrackELoginRepository()->createLoginRecord($userEntity, new DateTime(), $request->getClientIp()); // last user login date is now $user_last_login_datetime = 0; // used as a unix timestamp it will correspond to : 1 1 1970 @@ -1191,7 +1399,8 @@ function ($email) { } if ($introPage) { - $content = '{{ 'Welcome to this platform'|trans({}, 'messages', user_locale) }}
{{ 'You are registered to'|trans({}, 'messages', user_locale) }} {{ 'platform.site_name' | api_get_setting }} {{ 'with the following settings:'|trans({}, 'messages', user_locale) }}
{{ 'Username'|trans({}, 'messages', user_locale) }} : {{ login_name }}
- {{ 'Pass'|trans({}, 'messages', user_locale) }} : {{ original_password }}
{{ 'For more details visit %s'|trans({'%s': search_link}, 'messages', user_locale) }}
{{ 'In case of trouble, contact us.'|trans({}, 'messages', user_locale) }}