From 7155cbbd6f4251324b8b59630e25e28aad88b1b0 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Tue, 26 Dec 2017 20:36:40 -0700 Subject: [PATCH] Implement quick login --- js/home.js | 72 +++++++++++++++--------------- js/login.js | 112 ++++++++++++++++++++++++++++++++--------------- pages/login.html | 44 ++++--------------- 3 files changed, 122 insertions(+), 106 deletions(-) diff --git a/js/home.js b/js/home.js index d2b5a9f..ccb89d3 100644 --- a/js/home.js +++ b/js/home.js @@ -15,40 +15,40 @@ var cardSettings = { function loadCard(type, apiurl, title) { $.get("cards/" + type + ".html", {}, function (html) { - console.log(type + " " + apiurl + " " + title); - var cardClasses = "col-sm-12 col-md-6 col-lg-6 col-xl-4 order-12"; - if (cardSettings.hasOwnProperty(type) && cardSettings[type].hasOwnProperty("classes")) { - cardClasses = cardSettings[type]["classes"]; - } - var box = $('
'); - var card = $('
'); - $(card).html(html); - $(box).html(card); - $("#card-box").append(box); - if (loadedCardTypes.indexOf(type) == -1) { - loadedCardTypes.push(type); - } + console.log(type + " " + apiurl + " " + title); + var cardClasses = "col-sm-12 col-md-6 col-lg-6 col-xl-4 order-12"; + if (cardSettings.hasOwnProperty(type) && cardSettings[type].hasOwnProperty("classes")) { + cardClasses = cardSettings[type]["classes"]; + } + var box = $('
'); + var card = $('
'); + $(card).html(html); + $(box).html(card); + $("#card-box").append(box); + if (loadedCardTypes.indexOf(type) == -1) { + loadedCardTypes.push(type); + } }); } function applyCardTitles() { $(".card_app").each(function () { - var title = $(this).data("title"); - $(this).find(".card_title").text(title); + var title = $(this).data("title"); + $(this).find(".card_title").text(title); }); } function waitForCardsToLoadThenInjectScripts() { // How's *that* for self-documenting code? for (var i = 0; i < totalCardTypes.length; i++) { - if (loadedCardTypes.indexOf(totalCardTypes[i]) == -1) { - setTimeout(waitForCardsToLoadThenInjectScripts, 50); - return; - } + if (loadedCardTypes.indexOf(totalCardTypes[i]) == -1) { + setTimeout(waitForCardsToLoadThenInjectScripts, 50); + return; + } } applyCardTitles(); for (var i = 0; i < loadedCardTypes.length; i++) { - $.getScript('cards/js/' + loadedCardTypes[i] + '.js'); + $.getScript('cards/js/' + loadedCardTypes[i] + '.js'); } } @@ -56,22 +56,22 @@ function waitForCardsToLoadThenInjectScripts() { getApps(function (apps) { console.log(apps); for (var appname in apps) { - if (!apps.hasOwnProperty(appname)) { - continue; - } - var app = apps[appname]; - console.log(app); - console.log(" " + app.url); - console.log(" " + app.title); - if (typeof app.station_features !== "undefined" && app.station_features.length > 0) { - for (var type in app.station_features) { - if (!app.station_features.hasOwnProperty(type)) { - continue; - } - totalCardTypes.push(app.station_features[type]); - loadCard(app.station_features[type], app.url + "/api.php", app.title); - } - } + if (!apps.hasOwnProperty(appname)) { + continue; + } + var app = apps[appname]; + console.log(app); + console.log(" " + app.url); + console.log(" " + app.title); + if (typeof app.station_features !== "undefined" && app.station_features.length > 0) { + for (var type in app.station_features) { + if (!app.station_features.hasOwnProperty(type)) { + continue; + } + totalCardTypes.push(app.station_features[type]); + loadCard(app.station_features[type], app.url + "/api.php", app.title); + } + } } waitForCardsToLoadThenInjectScripts(); }); diff --git a/js/login.js b/js/login.js index 50b5022..9a1c0aa 100644 --- a/js/login.js +++ b/js/login.js @@ -7,46 +7,76 @@ function userpasslogin(username, password) { $.post(accounthubapi, { - key: apikey, - username: username, - password: password, - action: "auth" + 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"); - } + 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"); + } }, "json"); } function codelogin(code) { $.post(accounthubapi, { - key: apikey, - code: code, - action: "codelogin" + 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"); - } + 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 loadQuickLogin() { + $.post(accounthubapi, { + key: apikey, + gid: 4, + action: "getusersbygroup", + get: "detail" + }, function (resp) { + if (resp.status == "OK") { + var userhtml = ""; + for (var user in resp.users) { + var u = resp.users[user]; + userhtml += '
\n' + + '\n' + + '
\n' + + u["name"] + "\n" + + '
\n'; + } + $("#userlist .row").html(userhtml); + $(".quick-user").click(function () { + setuser($(this).data("username")); + setname($(this).data("name")); + setuid($(this).data("uid")); + openScreen("home"); + }); + } else { + showmsg(resp.msg, "danger"); + } }, "json"); } @@ -54,13 +84,25 @@ $("#userpassloginbtn").click(function () { var user = $("#username").val(); var pass = $("#password").val(); if (user != "" && pass != "") { - userpasslogin(user, pass); + userpasslogin(user, pass); } }); +function quicklogin(uid) { + var quickuser = + setuser(resp.data.username); + setname(resp.data.name); + setuid(resp.data.uid); + openScreen("home"); +} + $("#mobilecodeloginbtn").click(function () { var code = $("#code").val(); if (code != "") { - codelogin(code); + codelogin(code); } +}); + +$(document).ready(function () { + loadQuickLogin(); }); \ No newline at end of file diff --git a/pages/login.html b/pages/login.html index 1d0aba0..bf1d872 100644 --- a/pages/login.html +++ b/pages/login.html @@ -5,10 +5,10 @@

Login

-
+
-
- -
- Caroline Herschel -
-
- -
- Edmond Halley -
-
- -
- Jocelyn Bell Burnell -
-
- -
- Max Born -
-
- -
- Patty Jo Watson -
-
- -
- Sarah Boysen -
-
+ + +
@@ -64,8 +36,10 @@
+ +
-
Open the Business app on your phone,
then press the button to get a code.
+
Open the Business app on your phone,
then press the button to get a code.
B-