v0.0.10
+ Добавлена авторизация как отдельная страница + Небольшие исправления в JS при ответе от сервера
This commit is contained in:
parent
639118f781
commit
e74c0a1af0
11 changed files with 283 additions and 40 deletions
48
js/authorization.js
Normal file
48
js/authorization.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
$(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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue