refactoring

This commit is contained in:
Roland Gruber 2023-01-11 20:29:26 +01:00
parent 534c8048d4
commit b8d44f505e
2 changed files with 29 additions and 24 deletions

View file

@ -198,19 +198,22 @@ function profileShowDeleteDialog(title, okText, cancelText, scope, selectFieldNa
*/ */
function passwordHandleInput(random, ajaxURL, tokenName, tokenValue, okText) { function passwordHandleInput(random, ajaxURL, tokenName, tokenValue, okText) {
// get input values // get input values
var modules = new Array(); let modules = new Array();
jQuery('#passwordDialog').find(':checked').each(function() { const passwordDialog = document.getElementById('passwordDialog');
modules.push(jQuery(this).prop('name')); passwordDialog.querySelectorAll(':checked').forEach(item => {
modules.push(item.name);
}); });
var pwd1 = jQuery('#passwordDialog').find('[name=newPassword1]').val(); const pwd1 = passwordDialog.querySelector('[name=newPassword1]').value;
var pwd2 = jQuery('#passwordDialog').find('[name=newPassword2]').val(); const pwd2 = passwordDialog.querySelector('[name=newPassword2]').value;
var forcePasswordChange = jQuery('input[name=lamForcePasswordChange]').prop('checked'); const forcePasswordChange = passwordDialog.querySelector('input[name=lamForcePasswordChange]').checked;
var sendMail = jQuery('input[name=lamPasswordChangeSendMail]').prop('checked'); const sendMail = passwordDialog.querySelector('input[name=lamPasswordChangeSendMail]').checked;
var sendMailAlternateAddress = '';
if (jQuery('#passwordDialog').find('[name=lamPasswordChangeMailAddress]')) { let sendMailAlternateAddress = '';
sendMailAlternateAddress = jQuery('#passwordDialog').find('[name=lamPasswordChangeMailAddress]').val(); const lamPasswordChangeMailAddress = passwordDialog.querySelector('[name=lamPasswordChangeMailAddress]');
if (lamPasswordChangeMailAddress) {
sendMailAlternateAddress = lamPasswordChangeMailAddress.value;
} }
var pwdJSON = { const pwdJSON = {
"modules": modules, "modules": modules,
"password1": pwd1, "password1": pwd1,
"password2": pwd2, "password2": pwd2,
@ -219,16 +222,22 @@ function passwordHandleInput(random, ajaxURL, tokenName, tokenValue, okText) {
"sendMail": sendMail, "sendMail": sendMail,
"sendMailAlternateAddress": sendMailAlternateAddress "sendMailAlternateAddress": sendMailAlternateAddress
}; };
var data = {jsonInput: pwdJSON}; let data = new FormData();
data[tokenName] = tokenValue; data.append('jsonInput', JSON.stringify(pwdJSON));
data.append(tokenName, tokenValue);
// make AJAX call // make AJAX call
jQuery.post(ajaxURL, data, function(dataReturned) { fetch(ajaxURL, {
method: 'POST',
body: data
})
.then(async response => {
const jsonData = await response.json();
document.querySelector(".modal").classList.remove("show-modal"); document.querySelector(".modal").classList.remove("show-modal");
Swal.fire({ Swal.fire({
confirmButtonText: okText, confirmButtonText: okText,
html: dataReturned.messages html: jsonData.messages
}); });
}, 'json'); });
} }
/** /**

View file

@ -104,13 +104,9 @@ class Ajax {
die(); die();
} }
$function = $_GET['function']; $function = $_GET['function'];
if (!isset($_POST['jsonInput'])) {
die();
}
$jsonInput = $_POST['jsonInput']; if (($function === 'passwordStrengthCheck') && isset($_POST['jsonInput'])) {
if ($function == 'passwordStrengthCheck') { $this->checkPasswordStrength($_POST['jsonInput']);
$this->checkPasswordStrength($jsonInput);
die(); die();
} }
if ($function === 'webauthn') { if ($function === 'webauthn') {
@ -124,8 +120,8 @@ class Ajax {
die(); die();
} }
enforceUserIsLoggedIn(); enforceUserIsLoggedIn();
if ($function == 'passwordChange') { if (($function === 'passwordChange') && isset($_POST['jsonInput'])) {
$this->managePasswordChange($jsonInput); $this->managePasswordChange(json_decode($_POST['jsonInput'], true));
} }
elseif ($function === 'import') { elseif ($function === 'import') {
include_once('../../lib/import.inc'); include_once('../../lib/import.inc');