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
|
|
|
|
}
|
|
|
|
|
2022-11-20 12:05:14 -06:00
|
|
|
function onLoginError(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 onTelegramAuth(user) {
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: '/api/auth/login_tg',
|
|
|
|
data: JSON.stringify(user),
|
|
|
|
contentType: 'application/json',
|
|
|
|
success: function (data) {
|
|
|
|
window.location.reload();
|
|
|
|
},
|
|
|
|
error: onLoginError,
|
|
|
|
})
|
|
|
|
}
|
2022-11-07 04:45:02 -06:00
|
|
|
|
|
|
|
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();
|
|
|
|
},
|
2022-11-20 12:05:14 -06:00
|
|
|
error: onLoginError,
|
2022-11-07 04:45:02 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|