49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
$(document).ready(function () {
|
|
noticer = new Noticer;
|
|
|
|
$("#authorization").button({ icon: "ui-icon-home" });
|
|
|
|
$("#login, #password").on('keypress',function(e) {
|
|
if(e.which == 13) {
|
|
authorization()
|
|
}
|
|
});
|
|
|
|
$("#authorization").click(() => {
|
|
authorization()
|
|
});
|
|
|
|
$("body").fadeTo(500, 1);
|
|
});
|
|
|
|
function authorization() {
|
|
request().then((data) => {
|
|
data.error ? noticer.error(data.message) : (window.location.href = ".");
|
|
}).catch((e) => {
|
|
noticer.error(e.message);
|
|
});
|
|
}
|
|
|
|
async function request() {
|
|
let login = $("#login").val();
|
|
let password = $("#password").val();
|
|
|
|
let response = await fetch('.', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json;charset=utf-8'
|
|
},
|
|
body: JSON.stringify({
|
|
login: login,
|
|
password: password,
|
|
query: "login"
|
|
})
|
|
});
|
|
|
|
if (!response.ok)
|
|
throw new Error(`Произошла неизвестаня ошибка: ${response.status}`);
|
|
|
|
const data = await response.json();
|
|
return data;
|
|
}
|