|
|
@ -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"); |
|
|
|
}); |
|
|
|
} |