diff options
| author | haturatu <taro@eyes4you.org> | 2025-10-12 15:01:34 +0900 |
|---|---|---|
| committer | haturatu <taro@eyes4you.org> | 2025-10-12 15:01:34 +0900 |
| commit | 10c90d8654b94916bf0a4ffb8263e512a8e6be04 (patch) | |
| tree | dd109fb357abb40f943a7818fedc659e69ee5d11 /templates/js/auth.js | |
first commit
Diffstat (limited to 'templates/js/auth.js')
| -rw-r--r-- | templates/js/auth.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/templates/js/auth.js b/templates/js/auth.js new file mode 100644 index 0000000..3ca7c4e --- /dev/null +++ b/templates/js/auth.js @@ -0,0 +1,48 @@ +document.addEventListener('DOMContentLoaded', () => { + const changePasswordForm = document.getElementById('change-password-form'); + if (changePasswordForm) { + changePasswordForm.addEventListener('submit', handleChangePassword); + } +}); + +async function handleChangePassword(event) { + event.preventDefault(); + const form = event.target; + const formData = new FormData(form); + const messagePlaceholder = document.getElementById('message-placeholder'); + messagePlaceholder.textContent = ''; + + const newPassword = formData.get('new_password'); + const confirmNewPassword = formData.get('confirm_new_password'); + + if (newPassword !== confirmNewPassword) { + messagePlaceholder.className = 'error'; + messagePlaceholder.textContent = 'New passwords do not match.'; + return; + } + + try { + const response = await fetch(form.action, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: new URLSearchParams(formData) + }); + + const data = await response.json(); + + if (!response.ok) { + messagePlaceholder.className = 'error'; + messagePlaceholder.textContent = data.error || `Error: ${response.statusText}`; + } else { + messagePlaceholder.className = 'success'; + messagePlaceholder.textContent = data.message || 'Password updated successfully.'; + } + + } catch (error) { + console.error('Password change failed:', error); + messagePlaceholder.className = 'error'; + messagePlaceholder.textContent = 'An unexpected error occurred.'; + } +}
\ No newline at end of file |
