pull/5541/merge
juancp-contidosdixitais 7 months ago committed by GitHub
commit 1da8f18825
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 43
      main/admin/user_add.php
  2. 39
      main/admin/user_edit.php
  3. 15
      main/admin/user_import.php
  4. 44
      main/auth/inscription.php
  5. 19
      main/inc/lib/api.lib.php
  6. 7
      main/install/configuration.dist.php

@ -368,11 +368,47 @@ $html_results_enabled[] = $form->createElement('button', 'submit_plus', get_lang
$form->addGroup($html_results_enabled); $form->addGroup($html_results_enabled);
// Validate form // Validate form
if ($form->validate()) { $formValid = $form->validate();
if ($formValid) {
$check = Security::check_token('post'); $check = Security::check_token('post');
if ($check) { if ($check) {
$user = $form->exportValues(); $user = $form->exportValues();
$extraFields = api_get_configuration_value('extra_fields_to_validate_on_user_registration');
if (!empty($extraFields) && isset($extraFields['extra_fields'])) {
$extraFieldList = $extraFields['extra_fields'];
foreach ($user as $key => $value) {
if (substr($key, 0, 6) == 'extra_') {
$extra_value = Security::remove_XSS($value);
$extra_field = substr($key,6);
if(!empty($extra_value)) {
if (in_array($extra_field, $extraFieldList)) {
$extraValueExists = api_user_extra_field_validation($extra_field, $extra_value);
if ($extraValueExists) {
$formValid = false;
$element = $form->getElement($key);
if ($element) {
$attrs = ['style' => 'border-color: #a94442;'];
$form->updateElementAttr([$element], $attrs);
}
Display::addFlash(
Display::return_message(
get_lang('TheValueEntered ').$extra_field.get_lang('AlreadyExists'),
'error',
false
)
);
}
}
}
}
}
}
if ($formValid) {
$lastname = $user['lastname']; $lastname = $user['lastname'];
$firstname = $user['firstname']; $firstname = $user['firstname'];
$official_code = $user['official_code']; $official_code = $user['official_code'];
@ -498,7 +534,10 @@ if ($form->validate()) {
exit; exit;
} }
} }
} else { }
}
if (!$formValid) {
if (isset($_POST['submit'])) { if (isset($_POST['submit'])) {
Security::clear_token(); Security::clear_token();
} }

@ -432,6 +432,44 @@ $error_drh = false;
// Validate form // Validate form
if ($form->validate()) { if ($form->validate()) {
$user = $form->getSubmitValues(1); $user = $form->getSubmitValues(1);
$formValid = true;
$extraFields = api_get_configuration_value('extra_fields_to_validate_on_user_registration');
if (!empty($extraFields) && isset($extraFields['extra_fields'])) {
$extraFieldList = $extraFields['extra_fields'];
foreach ($user as $key => $value) {
if (substr($key, 0, 6) == 'extra_') {
$extra_value = Security::remove_XSS($value);
$extra_field = substr($key,6);
if(!empty($extra_value)) {
if (in_array($extra_field, $extraFieldList)) {
$extraValueExists = api_user_extra_field_validation($extra_field, $extra_value);
if ($extraValueExists) {
$formValid = false;
$element = $form->getElement($key);
if ($element) {
$attrs = ['style' => 'border-color: #a94442;'];
$form->updateElementAttr([$element], $attrs);
}
Display::addFlash(
Display::return_message(
get_lang('TheValueEntered ').$extra_field.get_lang('AlreadyExists'),
'error',
false
)
);
}
}
}
}
}
}
if ($formValid) {
$reset_password = (int) $user['reset_password']; $reset_password = (int) $user['reset_password'];
if ($reset_password == 2 && empty($user['password'])) { if ($reset_password == 2 && empty($user['password'])) {
Display::addFlash(Display::return_message(get_lang('PasswordIsTooShort'))); Display::addFlash(Display::return_message(get_lang('PasswordIsTooShort')));
@ -569,6 +607,7 @@ if ($form->validate()) {
header('Location: user_list.php'); header('Location: user_list.php');
exit(); exit();
} }
}
$actions = [ $actions = [
Display::url( Display::url(

@ -197,6 +197,21 @@ function validate_data($users, $checkUniqueEmail = false)
$user['has_error'] = true; $user['has_error'] = true;
} }
} }
// 6. Check if extra fields are duplicated
$extraFields = api_get_configuration_value('extra_fields_to_validate_on_user_registration');
if (!empty($extraFields) && isset($extraFields['extra_fields'])) {
$extraFieldList = $extraFields['extra_fields'];
foreach ($extraFieldList as $extraFieldToCheck) {
if (isset($user[$extraFieldToCheck]) && !empty($user[$extraFieldToCheck])) {
$valueExists = api_user_extra_field_validation($extraFieldToCheck, $user[$extraFieldToCheck]);
if ($valueExists) {
$user['message'] .= Display::return_message(get_lang('DuplicatedFieldAt').' '.$extraFieldToCheck, 'warning');
$user['has_error'] = true;
}
}
}
}
} }
return $users; return $users;

@ -673,8 +673,45 @@ if ($extraConditions && $extraFieldsLoaded) {
} }
} }
if ($form->validate()) { $formValid = $form->validate();
if ($formValid) {
$values = $form->getSubmitValues(1); $values = $form->getSubmitValues(1);
$extraFields = api_get_configuration_value('extra_fields_to_validate_on_user_registration');
if (!empty($extraFields) && isset($extraFields['extra_fields'])) {
$extraFieldList = $extraFields['extra_fields'];
foreach ($values as $key => $value) {
if (substr($key, 0, 6) == 'extra_') {
$extra_value = Security::remove_XSS($value);
$extra_field = substr($key,6);
if(!empty($extra_value)) {
if (in_array($extra_field, $extraFieldList)) {
$extraValueExists = api_user_extra_field_validation($extra_field, $extra_value);
if ($extraValueExists) {
$formValid = false;
$element = $form->getElement($key);
if ($element) {
$attrs = ['style' => 'border-color: #a94442;'];
$form->updateElementAttr([$element], $attrs);
}
Display::addFlash(
Display::return_message(
get_lang('TheValueEntered ').$extra_field.get_lang('AlreadyExists'),
'error',
false
)
);
}
}
}
}
}
}
if ($formValid) {
// Make *sure* the login isn't too long // Make *sure* the login isn't too long
if (isset($values['username'])) { if (isset($values['username'])) {
$values['username'] = api_substr($values['username'], 0, USERNAME_MAX_LENGTH); $values['username'] = api_substr($values['username'], 0, USERNAME_MAX_LENGTH);
@ -1059,7 +1096,10 @@ if ($form->validate()) {
$inscription = $tpl->get_template('auth/inscription.tpl'); $inscription = $tpl->get_template('auth/inscription.tpl');
$tpl->display($inscription); $tpl->display($inscription);
} }
} else { }
}
if (!$formValid) {
// Custom pages // Custom pages
if (CustomPages::enabled() && CustomPages::exists(CustomPages::REGISTRATION)) { if (CustomPages::enabled() && CustomPages::exists(CustomPages::REGISTRATION)) {
CustomPages::display( CustomPages::display(

@ -10714,3 +10714,22 @@ function api_encrypt_hash($data, $secret)
return base64_encode($iv).base64_encode($encrypted.$tag); return base64_encode($iv).base64_encode($encrypted.$tag);
} }
/**
* Check existence of a user extra field with a specific value
*
* @param string $extraField The name of the extra field to check.
* @param string $extraFieldValue The value of the extra field to validate against.
*
* @return bool True if the extra field with the specified value exists, false otherwise.
*/
function api_user_extra_field_validation($extraField, $extraFieldValue) {
$fieldValue = new ExtraFieldValue('user');
$data = $fieldValue->get_item_id_from_field_variable_and_field_value($extraField, $extraFieldValue, false, true);
if ($data) {
return true;
}
return false;
}

@ -1699,6 +1699,13 @@ ALTER TABLE notification_event_rel_user ADD CONSTRAINT FK_USER FOREIGN KEY (user
// Add help text to put 2 names in registration form // Add help text to put 2 names in registration form
//$_configuration['registration_add_helptext_for_2_names'] = false; //$_configuration['registration_add_helptext_for_2_names'] = false;
// Add extra fields to validate on user registration
/*$_configuration['extra_fields_to_validate_on_user_registration'] = [
'extra_fields' => [
'passport', 'employee_id'
]
];*/
// Allow career/promotions in global announcements // Allow career/promotions in global announcements
// ALTER TABLE sys_announcement ADD COLUMN career_id INT DEFAULT 0; // ALTER TABLE sys_announcement ADD COLUMN career_id INT DEFAULT 0;
// ALTER TABLE sys_announcement ADD COLUMN promotion_id INT DEFAULT 0; // ALTER TABLE sys_announcement ADD COLUMN promotion_id INT DEFAULT 0;

Loading…
Cancel
Save