Modify api request to not run if keys unverified

Communication with Json API now only happens if the keys are verified.
Automatic rendering and reloading of downloads is handled by oninit attribute
of the downloads component.
This commit is contained in:
rottencandy 2019-04-05 19:32:40 +05:30
parent e35ce1d52b
commit e8f3d5d23c
3 changed files with 26 additions and 15 deletions

View File

@ -43,8 +43,8 @@ function cntrlBtn(file, act) {
}
module.exports = {
//oninit: rs.Downloads.load(), // means we re-load the list everytime we render
//onload: rs.Downloads.load(), // means we re-load the list everytime we render
oninit: rs.Downloads.load(), // means we re-load the list everytime we render
onload: rs.Downloads.load(), // means we re-load the list everytime we render
view: function() {
var filestreamer_url = "/fstream/";

View File

@ -3,7 +3,7 @@ var rs = require("rswebui");
function loginResponse(isSuccessful) {
if (isSuccessful) {
window.location.href = window.location.href.split("?")[0] + "?/downloads";
m.route.set("/downloads");
}
else {
m.render(document.getElementById("warning"), "Incorrent login/password");

View File

@ -6,10 +6,13 @@ var rsJsonApiUrl = "http://127.0.0.1:9092"
var loginKey = {
username: "",
passwd: "",
isSuccessful: false,
};
function rsJsonApiRequest(path, data, callback, async, failCallback)
{
if(loginKey.isSuccessful)
{
console.log("rsJsonApiRequest(path, data, callback)", path, data, callback)
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
@ -29,21 +32,29 @@ function rsJsonApiRequest(path, data, callback, async, failCallback)
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Authorization", "Basic "+btoa(loginKey.username + ":" + loginKey.passwd));
xhr.send(data);
}
}
function validateLogin(username, password, callback) {
loginKey.username = username;
loginKey.passwd = password;
rsJsonApiRequest("/rsPeers/GetRetroshareInvite",
"",
function() {
callback(true);
},
true,
function() {
callback(false);
},
)
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if(xhr.readyState === 4) {
if(xhr.status === 200) {
callback(true);
loginKey.username = username;
loginKey.passwd = password;
loginKey.isSuccessful = true;
}
else
callback(false);
}
}
xhr.open('POST', rsJsonApiUrl + "/rsPeers/GetRetroshareInvite", true);
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Authorization", "Basic "+btoa(username + ":" + password));
xhr.send("");
}
// These constants are the onces listed in retroshare/rsfiles.h. I would like to make them "members" of Downloads