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.
107 lines
3.5 KiB
JavaScript
107 lines
3.5 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/.
|
|
*/
|
|
|
|
$('#username').on("keyup", function () {
|
|
$('#username').val($('#username').val().toLowerCase());
|
|
});
|
|
|
|
function checkAndSave(username, password) {
|
|
app.preloader.show();
|
|
|
|
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");
|
|
});
|
|
}, function (msg) {
|
|
app.preloader.hide();
|
|
app.dialog.alert(msg, "Error");
|
|
});
|
|
}
|
|
|
|
function setupAccount() {
|
|
var type = $("#accttype").val();
|
|
var username = $("#username").val();
|
|
var password = $("#password").val();
|
|
|
|
checkAndSave(username, password, type);
|
|
}
|
|
|
|
function createAccount() {
|
|
var type = $("#accttype").val();
|
|
var username = $("#username").val();
|
|
var password = $("#password").val();
|
|
|
|
if (username.length < 1) {
|
|
app.dialog.alert("Enter a username.", "Error");
|
|
return;
|
|
}
|
|
if (password.length < SETTINGS["min_password_length"]) {
|
|
app.dialog.alert("Password must be at least " + SETTINGS["min_password_length"] + " characters long.", "Error");
|
|
return;
|
|
}
|
|
|
|
app.dialog.create({
|
|
text: "I agree to the terms of service and privacy policy.",
|
|
buttons: [
|
|
{
|
|
text: "No",
|
|
onClick: function () {
|
|
restartApplication();
|
|
}
|
|
},
|
|
{
|
|
text: "Yes",
|
|
onClick: function () {
|
|
app.preloader.show();
|
|
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");
|
|
});
|
|
}
|
|
},
|
|
{
|
|
text: "Show",
|
|
onClick: function () {
|
|
openBrowser(SETTINGS["terms_of_service_url"]);
|
|
}
|
|
},
|
|
]
|
|
}).open();
|
|
} |