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;
|
||||
}
|
40
js/script.js
40
js/script.js
|
@ -58,6 +58,14 @@ $(document).ready(function () {
|
|||
e.key == "Escape" && ($(this).val(""), lists[$("#tabs").tabs( "option", "active" )]())
|
||||
});
|
||||
|
||||
$("#logout").click(() => {
|
||||
request('logout', 'json').then(data => {
|
||||
data.error ? noticer.error(data.message) : (window.location.href = ".");
|
||||
}).catch(error => {
|
||||
noticer.error(error.message);
|
||||
});
|
||||
});
|
||||
|
||||
loadNumbers();
|
||||
loadSMS();
|
||||
loadUSSD();
|
||||
|
@ -129,7 +137,10 @@ function pEmpty(text) {
|
|||
|
||||
function loadNumbers() {
|
||||
request('listnumbergroups', 'text').then(data => {
|
||||
data.error ? noticer.error(data.message) : generateListNumberGroups(data);
|
||||
if (isJSON(data) && JSON.parse(data).error)
|
||||
noticer.error(JSON.parse(data).message);
|
||||
else
|
||||
generateListNumberGroups(data);
|
||||
}).catch(error => {
|
||||
noticer.error(error.message);
|
||||
});
|
||||
|
@ -161,8 +172,8 @@ function generateListGroupNumbers(panel) {
|
|||
}
|
||||
|
||||
request('listgroupnumbers', 'json', { group: panel.data("group-name") }).then(data => {
|
||||
if (isJSON(data) && JSON.parse(data).error)
|
||||
noticer.error(JSON.parse(data).message);
|
||||
if (data.error)
|
||||
noticer.error(data.message);
|
||||
else {
|
||||
numbers = data;
|
||||
showListNumbers(panel);
|
||||
|
@ -347,7 +358,10 @@ function delNumber(panel, currentWindow) {
|
|||
|
||||
function loadSMS() {
|
||||
request('listsmsgroups', 'text').then(data => {
|
||||
data.error ? noticer.error(data.message) : generateListSMSGroups(data);
|
||||
if (isJSON(data) && JSON.parse(data).error)
|
||||
noticer.error(JSON.parse(data).message);
|
||||
else
|
||||
generateListSMSGroups(data);
|
||||
}).catch(error => {
|
||||
noticer.error(error.message);
|
||||
});
|
||||
|
@ -379,8 +393,8 @@ function generateListGroupSMS(panel) {
|
|||
}
|
||||
|
||||
request('listgroupsms', 'json', { to: panel.data("to") }).then(data => {
|
||||
if (isJSON(data) && JSON.parse(data).error)
|
||||
noticer.error(JSON.parse(data).message);
|
||||
if (data.error)
|
||||
noticer.error(data.message);
|
||||
else {
|
||||
sms = data;
|
||||
showListSMS(panel);
|
||||
|
@ -483,7 +497,10 @@ function delSMS(panel, currentWindow) {
|
|||
|
||||
function loadUSSD() {
|
||||
request('listussdgroups', 'text').then(data => {
|
||||
data.error ? noticer.error(data.message) : generateListUSSDGroups(data);
|
||||
if (isJSON(data) && JSON.parse(data).error)
|
||||
noticer.error(JSON.parse(data).message);
|
||||
else
|
||||
generateListUSSDGroups(data);
|
||||
}).catch(error => {
|
||||
noticer.error(error.message);
|
||||
});
|
||||
|
@ -515,8 +532,8 @@ function generateListGroupUSSD(panel) {
|
|||
}
|
||||
|
||||
request('listgroupussd', 'json', { to: panel.data("to") }).then(data => {
|
||||
if (isJSON(data) && JSON.parse(data).error)
|
||||
noticer.error(JSON.parse(data).message);
|
||||
if (data.error)
|
||||
noticer.error(data.message);
|
||||
else {
|
||||
ussd = data;
|
||||
showListUSSD(panel);
|
||||
|
@ -618,7 +635,10 @@ function delUSSD(panel, currentWindow) {
|
|||
|
||||
function loadServerInfo() {
|
||||
request('serverinfo', 'text').then(data => {
|
||||
data.error ? noticer.error(data.message) : showServerInfo(data);
|
||||
if (isJSON(data) && JSON.parse(data).error)
|
||||
noticer.error(JSON.parse(data).message);
|
||||
else
|
||||
showServerInfo(data);
|
||||
}).catch(error => {
|
||||
noticer.error(error.message);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue