HelpingHelenaApp/www/js/setup1.js

77 lines
2.4 KiB
JavaScript
Raw Normal View History

2019-03-25 19:10:58 -06:00
/*
* 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/.
*/
$('#username').on("keyup", function () {
$('#username').val($('#username').val().toLowerCase());
});
function checkAndSave(username, password) {
2019-03-25 19:10:58 -06:00
app.preloader.show();
2019-03-26 14:15:45 -06:00
callAPI("getkey", {
username: username,
password: password
}, function (data) {
app.preloader.hide();
localStorage.setItem("key", data.key);
localStorage.setItem("username", username);
localStorage.setItem("password", password);
callAPI("getprofile", {
key: data.key
}, function (profile) {
if (profile.profile.type == 1) {
localStorage.setItem("accttype", "giver");
} else if (profile.profile.type == 2) {
localStorage.setItem("accttype", "receiver");
} else if (profile.profile.type == 3){
app.preloader.hide();
app.dialog.alert("You need to download the merchant app instead. Visit ntsm.co/contact if you need help.", "Error");
return;
} else {
app.preloader.hide();
app.dialog.alert("Server replied with unknown account type. You might need to update this app.", "Error");
return;
}
localStorage.setItem("configured", true);
// Restart the app to re-read the config
restartApplication();
}, function (msg) {
app.preloader.hide();
app.dialog.alert(msg, "Error");
});
2019-03-26 14:15:45 -06:00
}, function (msg) {
app.preloader.hide();
app.dialog.alert(msg, "Error");
2019-03-25 19:10:58 -06:00
});
}
function setupAccount() {
var type = $("#accttype").val();
2019-03-25 21:20:03 -06:00
var username = $("#username").val();
var password = $("#password").val();
checkAndSave(username, password, type);
}
2019-03-25 19:10:58 -06:00
2019-03-25 21:20:03 -06:00
function createAccount() {
var type = $("#accttype").val();
2019-03-25 19:10:58 -06:00
var username = $("#username").val();
var password = $("#password").val();
2019-03-25 21:20:03 -06:00
app.preloader.show();
2019-03-26 14:15:45 -06:00
callAPI("signup", {
username: username,
password: password,
accttype: type
}, function (data) {
app.preloader.hide();
checkAndSave(username, password, type);
}, function (msg) {
app.preloader.hide();
app.dialog.alert(msg, "Error");
2019-03-25 21:20:03 -06:00
});
2019-03-25 19:10:58 -06:00
}