yoake/webroot/lib/auth.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-11-07 04:45:02 -06:00
async function getAuth() {
2022-11-11 16:15:22 -06:00
let body = await fetch("/api/auth/auth.json?" + new Date(), { method: "GET" })
2022-11-07 04:45:02 -06:00
let bodyJSON = await body.json()
return bodyJSON
}
function submitLoginForm(target, e) {
e.preventDefault()
console.log("submitLoginForm", target)
let form = $(target);
var actionUrl = form.attr('action');
$.ajax({
type: 'POST',
url: actionUrl,
data: form.serialize(),
success: function (data) {
window.location.reload();
},
error: function (data) {
try {
let msg = data.responseJSON.message || data.responseJSON;
$('#login-form-error').removeClass('d-none').find('span').text(msg);
} catch (e) {
$('#login-form-error').removeClass('d-none').find('span').text(e.message);
}
}
});
}
function signin() {
$('#login-modal').modal('show');
}
function signout() {
$.ajax({
type: 'DELETE',
2022-11-11 16:15:22 -06:00
url: '/api/auth/login',
2022-11-07 04:45:02 -06:00
success: function (data) {
window.location.reload();
},
error: function (data) {
console.warn(data)
}
});
}