1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-09 18:25:58 +01:00

Use management stubs in change-password.js.

This commit is contained in:
Juliusz Chroboczek 2024-05-02 18:34:42 +02:00
parent 53481fde5e
commit 8be8e6fec7
2 changed files with 15 additions and 33 deletions

View file

@ -15,12 +15,12 @@
<h1 id="title" class="navbar-brand">Change password</h1> <h1 id="title" class="navbar-brand">Change password</h1>
<form id="passwordform"> <form id="passwordform">
<label for="old1">Old password:</label> <label for="old">Old password:</label>
<input id="old1" type="password"/> <input id="old" type="password"/>
<label for="old2">Old password (repeat):</label> <label for="new1">New password:</label>
<input id="old2" type="password"/> <input id="new1" type="password"/>
<label for="new">New password:</label> <label for="new2">New password (repeat):</label>
<input id="new" type="password"/> <input id="new2" type="password"/>
<input type="submit" value="Submit"/> <input type="submit" value="Submit"/>
</form> </form>
@ -28,6 +28,7 @@
<p id="errormessage"></p> <p id="errormessage"></p>
<script src="/management.js" defer></script>
<script src="/change-password.js" defer></script> <script src="/change-password.js" defer></script>
</body> </body>
</html> </html>

View file

@ -35,18 +35,19 @@ document.getElementById('passwordform').onsubmit = async function(e) {
return; return;
} }
let old1 = document.getElementById('old1').value; let old = document.getElementById('old').value;
let old2 = document.getElementById('old2').value; let new1 = document.getElementById('new1').value;
if(old1 !== old2) { let new2 = document.getElementById('new2').value;
if(new1 !== new2) {
displayError("Passwords don't match."); displayError("Passwords don't match.");
return; return;
} }
try { try {
await doit(group, user, old1, document.getElementById('new').value); await setPassword(group, user, new1, old);
document.getElementById('old1').value = ''; document.getElementById('old').value = '';
document.getElementById('old2').value = ''; document.getElementById('new1').value = '';
document.getElementById('new').value = ''; document.getElementById('new2').value = '';
displayError(null); displayError(null);
document.getElementById('message').textContent = document.getElementById('message').textContent =
'Password successfully changed.'; '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) { function displayError(message) {
document.getElementById('errormessage').textContent = (message || ''); document.getElementById('errormessage').textContent = (message || '');
} }