From 36acd0ff0612bea5d0b0d6c9f7dd193b034f2e50 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 16 Nov 2018 00:41:21 -0700 Subject: [PATCH] Allow business account setup without pairing code, close #16, close #21 --- www/js/accounts.js | 10 ++++++++-- www/js/setup1.js | 36 +++++++++++++++++++++++++++++++++++- www/js/setup2.js | 2 +- www/pages/setup0.html | 10 ++++++++-- www/pages/setup1.html | 24 +++++++++++++++++++++--- 5 files changed, 73 insertions(+), 9 deletions(-) diff --git a/www/js/accounts.js b/www/js/accounts.js index 10547a1..d04f2c4 100644 --- a/www/js/accounts.js +++ b/www/js/accounts.js @@ -49,9 +49,13 @@ function recoveraccounts(callback) { /** * Switch to a different account. * @param {int} account The selected account index from localStorage.getItem('accounts') + * @param {boolean} showmsg Whether to show the "switched accounts" alert dialog. Default True. * @returns {undefined} */ -function switchaccount(account) { +function switchaccount(account, showmsg) { + if (typeof showmsg != 'boolean') { + showmsg = true; + } // If there isn't an accounts list yet, this shouldi take us back to the setup if (!isconfigvalid()) { restartApplication(); @@ -69,7 +73,9 @@ function switchaccount(account) { accountid = account; restartApplication(); - navigator.notification.alert("Successfully switched accounts.", null, "Switched", 'OK'); + if (showmsg == true) { + navigator.notification.alert("Successfully switched accounts.", null, "Switched", 'OK'); + } } /** diff --git a/www/js/setup1.js b/www/js/setup1.js index d3e1ec4..bcf7748 100644 --- a/www/js/setup1.js +++ b/www/js/setup1.js @@ -11,6 +11,7 @@ setupsynckey = ""; setupsyncurl = ""; netsymscomurl = "https://account.netsyms.com/mobile/index.php"; +netsymsbizurl = "https://BIZID.netsyms.biz/accounthub/mobile/index.php"; if (localStorage.getItem("firstrun") === null) { $("#setuptitle").text("Setup"); @@ -116,7 +117,7 @@ function personalsetup() { if (result.status == "OK") { var code = result.code; var accid = addaccount(username, password, netsymscomurl, code); - switchaccount(accid); + switchaccount(accid, false); localStorage.setItem("firstrun", "1"); navigator.notification.alert("Account connected!", null, "Success", 'Continue'); restartApplication(); @@ -131,6 +132,39 @@ function personalsetup() { }); } +function businesssetup() { + app.preloader.show(); + var username = $("#personal_username").val(); + var password = $("#personal_password").val(); + var url = netsymsbizurl.replace("BIZID", $("#bizid").val()); + + $.post(url, { + username: username, + password: password, + key: "NOKEY", + desc: device.platform + " " + device.model + " " + device.serial, + action: "generatesynccode" + }, function (result) { + app.preloader.hide(); + if (result.status == "OK") { + var code = result.code; + var accid = addaccount(username, password, url, code); + switchaccount(accid, false); + localStorage.setItem("firstrun", "1"); + navigator.notification.alert("Account connected!", null, "Success", 'Continue'); + restartApplication(); + } else if (result.status == "ERROR") { + navigator.notification.alert(result.msg, null, "Error", 'Dismiss'); + } else { + navigator.notification.alert("Something went wrong, please try again.", null, "Error", 'Dismiss'); + } + }, "json").fail(function () { + app.preloader.hide(); + navigator.notification.alert("Something went wrong, please try again.", null, "Error", 'Dismiss'); + }); + +} + function scanCode() { try { cordova.plugins.barcodeScanner.scan( diff --git a/www/js/setup2.js b/www/js/setup2.js index 02a5afe..7532dae 100644 --- a/www/js/setup2.js +++ b/www/js/setup2.js @@ -15,7 +15,7 @@ function savePassword() { if (data.status === 'OK') { setuppassword = $('#passbox').val(); var accid = addaccount(setupusername, setuppassword, setupsyncurl, setupsynckey); - switchaccount(accid); + switchaccount(accid, false); localStorage.setItem("firstrun", "1"); navigator.notification.alert("Account connected!", null, "Success", 'Continue'); restartApplication(); diff --git a/www/pages/setup0.html b/www/pages/setup0.html index c782178..28dcb7e 100644 --- a/www/pages/setup0.html +++ b/www/pages/setup0.html @@ -27,7 +27,8 @@
  • - +
    diff --git a/www/pages/setup1.html b/www/pages/setup1.html index 4d0ad34..d0c87ce 100644 --- a/www/pages/setup1.html +++ b/www/pages/setup1.html @@ -19,10 +19,15 @@
    - {{#if personal}} + {{#js_if "this.personal == true || this.business == true"}}
    + {{#if personal}}

    Type your netsyms.com username and password.

    + {{/if}} + {{#if business}} +

    Type your netsyms.biz username, password, and business ID.

    + {{/if}}
      @@ -45,18 +50,31 @@
  • + + {{#if business}} +
  • +
    +
    Business ID (____.netsyms.biz)
    +
    + + +
    +
    +
  • + {{/if}} +
    -
    +
    Continue

    - or -

    - {{/if}} + {{/js_if}}