From f73fdf9b94179e5bd64166df0234197b89c27ec4 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 30 Dec 2017 16:27:44 -0700 Subject: [PATCH] Add PIN login prompt to Quick Access (close #1) --- assets/css/other.css | 15 +++++++ js/login.js | 72 ++++++++++++++++++++++++++++++--- pages/login.html | 95 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 171 insertions(+), 11 deletions(-) diff --git a/assets/css/other.css b/assets/css/other.css index 99558fd..a572c83 100644 --- a/assets/css/other.css +++ b/assets/css/other.css @@ -39,4 +39,19 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. #sign-out-btn, #refresh-btn { background-color: rgba(255,255,255,.75); +} + +#pinpad .digits { + height: 50px; + padding: 10px; +} + +#pinpad .digits p { + font-weight: 500; + text-align: center; + font-size: 20px; +} + +#pincode-box { + font-size: 200%; } \ No newline at end of file diff --git a/js/login.js b/js/login.js index 097cdc8..79e1a92 100644 --- a/js/login.js +++ b/js/login.js @@ -30,6 +30,7 @@ function userpasslogin(username, password) { } else { showmsg(resp.msg, "danger"); } + $(this).data("uid") }, "json"); } @@ -50,6 +51,22 @@ function codelogin(code) { }, "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, { @@ -62,7 +79,7 @@ function loadQuickLogin() { var userhtml = ""; for (var user in resp.users) { var u = resp.users[user]; - userhtml += '
\n' + userhtml += '
\n' + '\n' + '
\n' + u["name"] + "\n" @@ -70,10 +87,7 @@ function loadQuickLogin() { } $("#userlist .row").html(userhtml); $(".quick-user").click(function () { - setuser($(this).data("username")); - setname($(this).data("name")); - setuid($(this).data("uid")); - openScreen("home"); + doQuickLogin($(this).data("username"), $(this).data("name"), $(this).data("uid"), $(this).data("pin") == "1"); }); } else { $("#quickaccess_tab").tab("dispose"); @@ -104,6 +118,52 @@ $("#mobilecode_form").submit(function (event) { } }); +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(); -}); \ No newline at end of file +}); + +$('#pinmodal').on('shown.bs.modal', function () { + $('#pincode-box').trigger('focus'); +}) \ No newline at end of file diff --git a/pages/login.html b/pages/login.html index 6ed2f09..0b53fa6 100644 --- a/pages/login.html +++ b/pages/login.html @@ -1,5 +1,90 @@ +
-
+

Login

@@ -16,8 +101,8 @@
- - + +
@@ -53,8 +138,8 @@
- - + +