summaryrefslogtreecommitdiff
path: root/templates/js/auth.js
diff options
context:
space:
mode:
Diffstat (limited to 'templates/js/auth.js')
-rw-r--r--templates/js/auth.js48
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