From 8be8e6fec709fb94599b76da73aa93c30ba87d7e Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Thu, 2 May 2024 18:34:42 +0200 Subject: [PATCH] Use management stubs in change-password.js. --- static/change-password.html | 13 +++++++------ static/change-password.js | 35 ++++++++--------------------------- 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/static/change-password.html b/static/change-password.html index 78387c9..bff9f96 100644 --- a/static/change-password.html +++ b/static/change-password.html @@ -15,12 +15,12 @@

Change password

- - - - - - + + + + + +
@@ -28,6 +28,7 @@

+ diff --git a/static/change-password.js b/static/change-password.js index 8125464..ed713f0 100644 --- a/static/change-password.js +++ b/static/change-password.js @@ -35,18 +35,19 @@ document.getElementById('passwordform').onsubmit = async function(e) { return; } - let old1 = document.getElementById('old1').value; - let old2 = document.getElementById('old2').value; - if(old1 !== old2) { + let old = document.getElementById('old').value; + let new1 = document.getElementById('new1').value; + let new2 = document.getElementById('new2').value; + if(new1 !== new2) { displayError("Passwords don't match."); return; } try { - await doit(group, user, old1, document.getElementById('new').value); - document.getElementById('old1').value = ''; - document.getElementById('old2').value = ''; - document.getElementById('new').value = ''; + await setPassword(group, user, new1, old); + document.getElementById('old').value = ''; + document.getElementById('new1').value = ''; + document.getElementById('new2').value = ''; displayError(null); document.getElementById('message').textContent = 'Password successfully changed.'; @@ -55,26 +56,6 @@ document.getElementById('passwordform').onsubmit = async function(e) { } } -async function doit(group, user, old, pw) { - let creds = btoa(user + ":" + old); - let r = await fetch(`/galene-api/0/.groups/${group}/.users/${user}/.password`, - { - method: 'POST', - body: pw, - credentials: 'omit', - headers: { - 'Authorization': `Basic ${creds}` - } - }); - if(!r.ok) { - if(r.status === 401) - throw new Error('Permission denied'); - else - throw new Error(`The server said: ${r.status} ${r.statusText}`); - return; - } -} - function displayError(message) { document.getElementById('errormessage').textContent = (message || ''); }