chore: add very basic password change form

This commit is contained in:
transcaffeine 2021-06-16 21:48:11 +02:00
parent 5d3bc5bb3e
commit 14d0be9c68
Signed by: transcaffeine
GPG Key ID: 03624C433676E465

View File

@ -0,0 +1,65 @@
<!DOCTYPE html>
<html>
<head>
<title>Password change</title>
<script type="text/javascript">
window.onload = () => {
const myform = document.getElementById('pwchange');
myform.addEventListener('submit', e => {
e.preventDefault();
const username = document.getElementById('username');
const bind_pass = document.getElementById('bind_pass');
const password = document.getElementById('password');
const payload = {
bind_pw: bind_pass.value,
userPassword: password.value
};
const response = fetch('/api/users/uid=' + username.value + '/updatePassword', {
method: 'POST',
cache: 'no-cache',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
console.log(response)
response.then(r => r.json()).then(answer => {
if (response.status === 204) {
alert('Password was updated');
}
})
.catch(e => {
console.log(e);
if (response.status === 401) {
alert('Invalid current password supplied');
} else {
alert('Error updating password: ' + response.status + ' ' + response.statusText);
}
})
})
}
</script>
</head>
<body>
<h1>finallycoffee.eu password self-service</h1>
<table>
<form id="pwchange">
<tr>
<td>Username</td>
<td><input type="text" name="username" id="username" /></td>
</tr>
<tr>
<td>Current Password</td>
<td><input type="password" name="old_password" id="bind_pass" /></td>
</tr>
<tr>
<td>New Password</td>
<td><input type="password" name="password" id="password" /></td>
</tr>
<tr>
<td><input type="submit" value="Change password" /></td>
</tr>
</form>
</table>
</body>
</html>