Browse Source

Use callAPI method

master
Skylar Ittner 3 years ago
parent
commit
a92b59f0a4
  1. 2
      www/index.html
  2. 81
      www/js/setup1.js

2
www/index.html

@ -11,6 +11,7 @@
<link rel="stylesheet" href="fonts/roboto/Roboto.css">
<link rel="stylesheet" href="node_modules/framework7/css/framework7.bundle.min.css">
<link rel="stylesheet" href="node_modules/@fortawesome/fontawesome-free/css/all.min.css">
<link rel="stylesheet" href="css/styles.css">
<title>Helping Helena</title>
@ -28,6 +29,7 @@
<script src="node_modules/framework7/js/framework7.bundle.min.js"></script>
<script src="settings.js"></script>
<script src="js/api.js"></script>
<script src="routes.js"></script>
<script src="js/platform.js"></script>
<script src="js/main.js"></script>

81
www/js/setup1.js

@ -11,37 +11,21 @@ $('#username').on("keyup", function () {
function checkAndSave(username, password, type) {
app.preloader.show();
var url = SETTINGS["server"] + "/getkey";
$.ajax({
url: url,
dataType: "json",
cache: false,
method: "POST",
data: {
username: username,
password: password,
type: type
},
success: function (data) {
app.preloader.hide();
if (data.status == "OK") {
localStorage.setItem("username", username);
localStorage.setItem("password", password);
localStorage.setItem("accttype", type);
localStorage.setItem("configured", true);
// Restart the app to re-read the config
restartApplication();
} else if (data.status == "ERROR") {
app.dialog.alert(data.msg, "Error");
} else {
app.dialog.alert("", "Error");
}
}, error: function () {
app.preloader.hide();
app.dialog.alert("Could not sign in. Check your credentials and connection.", "Error");
}
callAPI("getkey", {
username: username,
password: password
}, function (data) {
app.preloader.hide();
localStorage.setItem("key", data.key);
localStorage.setItem("username", username);
localStorage.setItem("password", password);
localStorage.setItem("accttype", type);
localStorage.setItem("configured", true);
// Restart the app to re-read the config
restartApplication();
}, function (msg) {
app.preloader.hide();
app.dialog.alert(msg, "Error");
});
}
@ -60,30 +44,15 @@ function createAccount() {
app.preloader.show();
var url = SETTINGS["server"] + "/signup";
$.ajax({
url: url,
dataType: "json",
cache: false,
method: "POST",
data: {
username: username,
password: password,
accttype: type
},
success: function (data) {
app.preloader.hide();
if (data.status == "OK") {
checkAndSave(username, password, type);
} else if (data.status == "ERROR") {
app.dialog.alert(data.msg, "Error");
} else {
app.dialog.alert("", "Error");
}
}, error: function () {
app.preloader.hide();
app.dialog.alert("Could not create account. Check your connection.", "Error");
}
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");
});
}
Loading…
Cancel
Save