website-PretendoNetwork/public/assets/js/reset-password.js
2023-03-05 21:27:45 +01:00

30 lines
899 B
JavaScript

const passwordInput = document.querySelector('#password');
const passwordConfirmInput = document.querySelector('#password_confirm');
const tokenInput = document.querySelector('#token');
document.querySelector('form').addEventListener('submit', function (event) {
event.preventDefault();
fetch('https://api.pretendo.cc/v1/reset-password', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
password: passwordInput.value,
password_confirm: passwordConfirmInput.value,
token: tokenInput.value
})
})
.then(response => response.json())
.then(body => {
if (body.error) {
alert(`Error: ${body.error}. TODO: red error message thing`);
} else {
alert('Password reset. TODO: reword this and green success');
window.location.assign('/account/login');
}
})
.catch(console.log);
});