Automatically reload user page upon incorrect server
- Upon receiving responseError INCORRECT_SERVER_ERROR, reload the client page. (Triggered mainly when master is changed). - Fixed some minor syntax bugs
This commit is contained in:
parent
827bdcd793
commit
512dc3bcbc
@ -1,4 +1,5 @@
|
|||||||
//console.log(document.cookie.toString());
|
//console.log(document.cookie.toString());
|
||||||
|
const INVALID_SERVER_MSG = "INCORRECT_SERVER_ERROR";
|
||||||
var nodeList, nodeURL, nodeKBucket; //Container for (backup) node list
|
var nodeList, nodeURL, nodeKBucket; //Container for (backup) node list
|
||||||
|
|
||||||
function exchangeAPI(api, options) {
|
function exchangeAPI(api, options) {
|
||||||
@ -69,7 +70,9 @@ const tokenAPI = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ResponseError(status, data) {
|
function ResponseError(status, data) {
|
||||||
if (this instanceof ResponseError) {
|
if (data === INVALID_SERVER_MSG)
|
||||||
|
location.reload();
|
||||||
|
else if (this instanceof ResponseError) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
} else
|
} else
|
||||||
|
|||||||
@ -4,7 +4,7 @@ const express = require('express');
|
|||||||
//const sessions = require('express-session');
|
//const sessions = require('express-session');
|
||||||
const Request = require('./request');
|
const Request = require('./request');
|
||||||
|
|
||||||
const REFRESH_INTERVAL = 5 * 1000; //10 * 60 * 1000;
|
const REFRESH_INTERVAL = 1 * 60 * 1000;
|
||||||
|
|
||||||
module.exports = function App(secret, DB) {
|
module.exports = function App(secret, DB) {
|
||||||
|
|
||||||
|
|||||||
@ -22,19 +22,19 @@ const oneDay = 1000 * 60 * 60 * 24;
|
|||||||
const maxSessionTimeout = 60 * oneDay;
|
const maxSessionTimeout = 60 * oneDay;
|
||||||
|
|
||||||
var serving;
|
var serving;
|
||||||
const INVALID_SERVER_MSG = "Incorrect Server. Please connect to main server.";
|
const INVALID_SERVER_MSG = "INCORRECT_SERVER_ERROR";
|
||||||
|
|
||||||
function validateRequestFromFloID(request, sign, floID, proxy = true) {
|
function validateRequestFromFloID(request, sign, floID, proxy = true) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!serving)
|
if (!serving)
|
||||||
return reject(INVALID(INVALID_SERVER_MSG));
|
return reject(INVALID(INVALID_SERVER_MSG));
|
||||||
else if (!floCrypto.validateAddr(floID))
|
else if (!floCrypto.validateAddr(floID))
|
||||||
return reject(INVALID.e_code).send("Invalid floID");
|
return reject(INVALID("Invalid floID"));
|
||||||
DB.query("SELECT " + (proxy ? "session_time, proxyKey AS pubKey FROM Sessions" : "pubKey FROM Users") + " WHERE floID=?", [floID]).then(result => {
|
DB.query("SELECT " + (proxy ? "session_time, proxyKey AS pubKey FROM Sessions" : "pubKey FROM Users") + " WHERE floID=?", [floID]).then(result => {
|
||||||
if (result.length < 1)
|
if (result.length < 1)
|
||||||
return reject(INVALID(proxy ? "Session not active" : "User not registered"));
|
return reject(INVALID(proxy ? "Session not active" : "User not registered"));
|
||||||
if (proxy && result[0].session_time + maxSessionTimeout < Date.now())
|
if (proxy && result[0].session_time + maxSessionTimeout < Date.now())
|
||||||
return reject(INVALID.e_code).send("Session Expired! Re-login required");
|
return reject(INVALID("Session Expired! Re-login required"));
|
||||||
let req_str = validateRequest(request, sign, result[0].pubKey);
|
let req_str = validateRequest(request, sign, result[0].pubKey);
|
||||||
req_str instanceof INVALID ? reject(req_str) : resolve(req_str);
|
req_str instanceof INVALID ? reject(req_str) : resolve(req_str);
|
||||||
}).catch(error => reject(error));
|
}).catch(error => reject(error));
|
||||||
@ -62,6 +62,8 @@ function storeRequest(floID, req_str, sign) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getLoginCode(req, res) {
|
function getLoginCode(req, res) {
|
||||||
|
if (!serving)
|
||||||
|
return res.status(INVALID.e_code).send(INVALID_SERVER_MSG);
|
||||||
let randID = floCrypto.randString(8, true) + Math.round(Date.now() / 1000);
|
let randID = floCrypto.randString(8, true) + Math.round(Date.now() / 1000);
|
||||||
let hash = Crypto.SHA1(randID + secret);
|
let hash = Crypto.SHA1(randID + secret);
|
||||||
res.send({
|
res.send({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user