Finish Persims consolidation
This commit is contained in:
1 parent
638e33cf9d
commit
60cc0186d3
1 file changed
+26
@@ -0,0 +1,26 @@
|
||||
document.getElementById('signin').onsubmit = async event => {
|
||||
event.preventDefault();
|
||||
const form = event.currentTarget;
|
||||
const status = document.getElementById('status');
|
||||
const action = event.submitter.value;
|
||||
const password = document.getElementById('password');
|
||||
const payload = {name: document.getElementById('name').value, password: password.value};
|
||||
password.value = '';
|
||||
for (const button of form.querySelectorAll('button')) button.disabled = true;
|
||||
try {
|
||||
const response = await fetch('/api/auth/' + action, {
|
||||
method: 'POST', credentials: 'same-origin',
|
||||
headers: {'Content-Type': 'application/json'}, body: JSON.stringify(payload)
|
||||
});
|
||||
payload.password = '';
|
||||
if (!response.ok) throw new Error();
|
||||
location.assign('/');
|
||||
} catch {
|
||||
payload.password = '';
|
||||
status.textContent = 'Sign-in unavailable. Check details and retry.';
|
||||
for (const button of form.querySelectorAll('button')) button.disabled = false;
|
||||
}
|
||||
};
|
||||
|
||||
fetch('/api/session', {credentials: 'same-origin', cache: 'no-store'})
|
||||
.then(response => { if (response.ok) location.replace('/'); }).catch(() => {});
|
||||
Reference in new issue
Block a user