You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
170 lines
5.1 KiB
JavaScript
170 lines
5.1 KiB
JavaScript
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
|
|
function userpasslogin(username, password) {
|
|
$.post(accounthubapi, {
|
|
key: apikey,
|
|
username: username,
|
|
password: password,
|
|
action: "auth"
|
|
}, function (resp) {
|
|
if (resp.status == "OK") {
|
|
$.post(accounthubapi, {
|
|
key: apikey,
|
|
username: username,
|
|
action: "userinfo"
|
|
}, function (resp) {
|
|
if (resp.status == "OK") {
|
|
setuser(resp.data.username);
|
|
setname(resp.data.name);
|
|
setuid(resp.data.uid);
|
|
openScreen("home");
|
|
} else {
|
|
showmsg(resp.msg, "danger");
|
|
}
|
|
}, "json");
|
|
} else {
|
|
showmsg(resp.msg, "danger");
|
|
}
|
|
$(this).data("uid")
|
|
}, "json");
|
|
}
|
|
|
|
function codelogin(code) {
|
|
$.post(accounthubapi, {
|
|
key: apikey,
|
|
code: code,
|
|
action: "codelogin"
|
|
}, function (resp) {
|
|
if (resp.status == "OK") {
|
|
setuser(resp.user.username);
|
|
setname(resp.user.realname);
|
|
setuid(resp.user.uid);
|
|
openScreen("home");
|
|
} else {
|
|
showmsg(resp.msg, "danger");
|
|
}
|
|
}, "json");
|
|
}
|
|
|
|
function doQuickLogin(username, name, uid, pin) {
|
|
$('#pinmodal').modal('hide');
|
|
if (pin) {
|
|
$('#pinmodal').data("username", username);
|
|
$('#pinmodal').data("name", name);
|
|
$('#pinmodal').data("uid", uid);
|
|
$('#pinmodal').modal('show');
|
|
$('#pincode-box').val("");
|
|
} else {
|
|
setuser(username);
|
|
setname(name);
|
|
setuid(uid);
|
|
openScreen("home");
|
|
}
|
|
}
|
|
|
|
function loadQuickLogin() {
|
|
if (!isNaN(group) && group != "") {
|
|
$.post(accounthubapi, {
|
|
key: apikey,
|
|
gid: group,
|
|
action: "getusersbygroup",
|
|
get: "detail"
|
|
}, function (resp) {
|
|
if (resp.status == "OK") {
|
|
var userhtml = "";
|
|
for (var user in resp.users) {
|
|
var u = resp.users[user];
|
|
userhtml += '<div class="col-4 col-lg-3 quick-user" data-uid="' + u["uid"] + '" data-username="' + u["username"] + '" data-name="' + u["name"] + '" data-pin="' + (u["pin"] == true ? "1" : "") + '" >\n'
|
|
+ '<svg class="identicon" width="60" height="60" data-jdenticon-value="' + u["name"] + '"></svg>\n'
|
|
+ '<br />\n'
|
|
+ u["name"] + "\n"
|
|
+ '</div>\n';
|
|
}
|
|
$("#userlist .row").html(userhtml);
|
|
jdenticon.update(".identicon");
|
|
$(".quick-user").click(function () {
|
|
doQuickLogin($(this).data("username"), $(this).data("name"), $(this).data("uid"), $(this).data("pin") == "1");
|
|
});
|
|
} else {
|
|
$("#quickaccess_tab").tab("dispose");
|
|
$("#userpass_tab").tab("show");
|
|
}
|
|
}, "json");
|
|
} else {
|
|
$("#quickaccess_tab").tab("dispose");
|
|
$("#quickaccess_tab").css("display", "none");
|
|
$("#userpass_tab").tab("show");
|
|
}
|
|
}
|
|
|
|
$("#userpass_form").submit(function (event) {
|
|
event.preventDefault();
|
|
var user = $("#username").val();
|
|
var pass = $("#password").val();
|
|
if (user != "" && pass != "") {
|
|
userpasslogin(user, pass);
|
|
}
|
|
});
|
|
|
|
$("#mobilecode_form").submit(function (event) {
|
|
event.preventDefault();
|
|
var code = $("#code").val();
|
|
if (code != "") {
|
|
codelogin(code);
|
|
}
|
|
});
|
|
|
|
function tryPinModalLogin(pin) {
|
|
$.post(accounthubapi, {
|
|
key: apikey,
|
|
pin: pin,
|
|
uid: $('#pinmodal').data("uid"),
|
|
action: "checkpin"
|
|
}, function (resp) {
|
|
if (resp.pinvalid === true || resp.nopinset === true) {
|
|
doQuickLogin($('#pinmodal').data("username"), $('#pinmodal').data("name"), $('#pinmodal').data("uid"), false);
|
|
} else if (resp.pinvalid === false) {
|
|
showmsg("PIN incorrect.", "danger");
|
|
} else {
|
|
showmsg(resp.msg, "danger");
|
|
}
|
|
}, "json");
|
|
}
|
|
|
|
$(document).ready(function () {
|
|
var dials = $("#pinpad .digits");
|
|
var index;
|
|
var number = $("#pincode-box");
|
|
|
|
dials.click(function () {
|
|
index = dials.index(this);
|
|
if (index === 9) {
|
|
number.val("");
|
|
} else if (index === 10) {
|
|
number.val(number.val() + "0");
|
|
} else if (index === 11) {
|
|
tryPinModalLogin(number.val());
|
|
} else {
|
|
number.val(number.val() + (index + 1));
|
|
}
|
|
});
|
|
|
|
number.keypress(function (event) {
|
|
// Handle pressing Enter key
|
|
if (event.keyCode === 13) {
|
|
tryPinModalLogin(number.val());
|
|
}
|
|
});
|
|
|
|
|
|
loadQuickLogin();
|
|
});
|
|
|
|
$('#pinmodal').on('shown.bs.modal', function () {
|
|
$('#pincode-box').trigger('focus');
|
|
}) |