login and register logic
This commit is contained in:
parent
a2f8452eec
commit
8d0c02e27e
15 changed files with 496 additions and 106 deletions
30
public/index.js
Normal file
30
public/index.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
async function formClick(ev) {
|
||||
ev.preventDefault();
|
||||
|
||||
let { target } = ev;
|
||||
|
||||
let fData = new FormData(target);
|
||||
|
||||
let file = target.querySelector('input[type=file]');
|
||||
if (file)
|
||||
file.value = null;
|
||||
|
||||
let fetched = await fetch(target.action, {
|
||||
'method': 'POST',
|
||||
'body': fData
|
||||
});
|
||||
|
||||
let json = await fetched.json();
|
||||
|
||||
target.querySelector('.form-message').textContent = json.message;
|
||||
|
||||
if (json.redirect && json.success) {
|
||||
setTimeout(function () {
|
||||
window.location.href = json.redirect;
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
document.addEventListener('submit', formClick);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue