66 lines
2.0 KiB
HTML
66 lines
2.0 KiB
HTML
<!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>
|