Skip to content

Commit

Permalink
fix: improved overwriting password
Browse files Browse the repository at this point in the history
  • Loading branch information
modelrailroader authored Jul 30, 2024
1 parent d20fe13 commit ec239e4
Showing 1 changed file with 10 additions and 37 deletions.
47 changes: 10 additions & 37 deletions phpmyfaq/admin/assets/src/user/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,52 +235,25 @@ export const handleUsers = async () => {
const buttonOverwritePassword = document.getElementById('pmf-user-password-overwrite-action');
const container = document.getElementById('pmf-modal-user-password-overwrite');

if (buttonOverwritePassword) {
if (buttonOverwritePassword) {
const modal = new Modal(container);
const message = document.getElementById('pmf-user-message');

buttonOverwritePassword.addEventListener('click', (event) => {
buttonOverwritePassword.addEventListener('click', async (event) => {
event.preventDefault();

const csrf = document.getElementById('modal_csrf').value;
const userId = document.getElementById('modal_user_id').value;
const newPassword = document.getElementById('npass').value;
const passwordRepeat = document.getElementById('bpass').value;

fetch('./api/user/overwrite-password', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
body: JSON.stringify({
csrf: csrf,
userId: userId,
newPassword: newPassword,
passwordRepeat: passwordRepeat,
}),
})
.then(async (response) => {
if (response.ok) {
return response.json();
}
throw new Error('Network response was not ok: ', { cause: { response } });
})
.then((response) => {
message.insertAdjacentElement(
'afterend',
addElement('div', { classList: 'alert alert-success', innerText: response.success }),
);
modal.hide();
})
.catch(async (error) => {
const errorMessage = await error.cause.response.json();
console.error(errorMessage.error);
message.insertAdjacentElement(
'afterend',
addElement('div', { classList: 'alert alert-danger', innerText: errorMessage.error }),
);
});
const response = await overwritePassword(csrf, userId, newPassword, passwordRepeat);
if (response.success) {
pushNotification(response.success);
modal.hide();
}
if (response.error) {
pushErrorNotification(response.error);
}
});
}

Expand Down

0 comments on commit ec239e4

Please sign in to comment.