mirror of
https://github.com/jech/galene.git
synced 2024-11-22 00:25:58 +01:00
Use management stubs in change-password.js.
This commit is contained in:
parent
53481fde5e
commit
8be8e6fec7
2 changed files with 15 additions and 33 deletions
|
@ -15,12 +15,12 @@
|
|||
<h1 id="title" class="navbar-brand">Change password</h1>
|
||||
|
||||
<form id="passwordform">
|
||||
<label for="old1">Old password:</label>
|
||||
<input id="old1" type="password"/>
|
||||
<label for="old2">Old password (repeat):</label>
|
||||
<input id="old2" type="password"/>
|
||||
<label for="new">New password:</label>
|
||||
<input id="new" type="password"/>
|
||||
<label for="old">Old password:</label>
|
||||
<input id="old" type="password"/>
|
||||
<label for="new1">New password:</label>
|
||||
<input id="new1" type="password"/>
|
||||
<label for="new2">New password (repeat):</label>
|
||||
<input id="new2" type="password"/>
|
||||
<input type="submit" value="Submit"/>
|
||||
</form>
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
|||
|
||||
<p id="errormessage"></p>
|
||||
|
||||
<script src="/management.js" defer></script>
|
||||
<script src="/change-password.js" defer></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -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 || '');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue