Last active
June 29, 2019 15:52
-
-
Save notgull/5dc6edec63270cdb0cdd1e19ca4cb674 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// hookup to PRS system | |
app.post("/prs", function(req, res) { | |
var ip_addr = req.headers['x-forwarded-for'] || req.connection.remoteAddress; | |
console.log("PRS Request: " + JSON.stringify(req.body)); | |
// get username | |
var username = ut.check_session(Number(req.body.sessionId), ip_addr); | |
if (username) { | |
// pull all parameters from req.body and put them in args | |
var args = {}; | |
for (var key in req.body) | |
args[key] = req.body[key]; | |
prs.request(args["name"], username, args, function(result) { | |
res.send(JSON.stringify(result)); | |
}); | |
} else { | |
res.send(JSON.stringify({not_logged_in: true, result: false})); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sending xmlhttprequests to the server and receiving data in return | |
// need to include: js/cookie.js | |
var prsRequest = function(name, args, next) { | |
// set up a form data with everything needed | |
var fData = new FormData(); | |
fData.append('name', name); | |
fData.append('sessionId', getCookie('sessionId')); | |
for (var key in args) | |
fData.append(key, args[key]); | |
// create callback | |
var xhrCallback = function() { | |
console.log(this.responseText); | |
var result = JSON.parse(this.responseText); | |
next(result); | |
}; | |
// create XMLHttpRequest | |
console.log("Sending PRS Request..."); | |
var req = new XMLHttpRequest(); | |
req.onload = xhrCallback; | |
req.open("POST", "/prs"); | |
req.send(fData); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment