Re: [APE Project] Re: Server JS module Http request callback function skipped

42 views
Skip to first unread message
Message has been deleted
Message has been deleted

Nicolas Guibert

unread,
Nov 14, 2012, 10:26:49 AM11/14/12
to ape-p...@googlegroups.com
If Http is similar to mysql use, then you need to work from the callback function that is called when the request is finished. 

I don't know if this applies to this case, but to me it looks like it.



2012/11/14 Urgent Programmer <urgent.p...@gmail.com>
To clarify the issue, I added some more logging in the code. Here are the logs:

2012-11-14 07:18:33 - libape-spidermonkey.c:2204 - JavaScript : custom log
2012-11-14 07:18:33 - libape-spidermonkey.c:2204 - JavaScript : connect hook end
2012-11-14 07:18:33 - src/users.c:180 - New user - (ip : 107.9.214.85)
2012-11-14 07:18:36 - libape-spidermonkey.c:2204 - JavaScript : USER_NOT_LOGGED_IN

It looks like it's finishing the hook and connecting the user before the http request callback finishes.

Ape.registerHookCmd("connect", function(params, cmd) {
    Ape.log('custom log');
    if ( ! params || ! params.token) return ["001", "INVALID PARAMS"];
checkLogin(params, cmd);
Ape.log('connect hook end');
});

function checkLogin(params, cmd){
var request = new Http('http://dev.itecode.com/bow/auction/index/checkLogin?SID='  + params.token+'&proId='+params.proId);
request.getContent(function(result) { //call the PHP file
if ( ! result ) {
//send error if cannot contact page
cmd.sendResponse('ERR', {'code': 1001, 'value': 'error_codes._1001'});
Ape.log('USER_NOT_LOGGED_IN');
return 0;
}
var result2=JSON.parse(result);
if(result2.res == 'in auction'){
Ape.log('USER_LOGGED_IN');
return 1;
}
else {
//send error if not logged in
cmd.sendResponse('ERR', {'code': 1001, 'value': 'error_codes._1001'});
Ape.log('USER_NOT_LOGGED_IN');
return 0;
}
});
}

--
You received this message because you are subscribed to the Google
Groups "APE Project" group.
To post to this group, send email to ape-p...@googlegroups.com
To unsubscribe from this group, send email to
ape-project...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/ape-project?hl=en
---
APE Project (Ajax Push Engine)
Official website : http://www.ape-project.org/
Git Hub : http://github.com/APE-Project/

Pablo Tejada

unread,
Nov 14, 2012, 10:28:30 AM11/14/12
to ape-p...@googlegroups.com

On the connect hook return -1

On checkLogin where USER_LOGGED_IN add

Ape.addUser(cmd.user)

Urgent Programmer

unread,
Nov 14, 2012, 10:51:25 AM11/14/12
to ape-p...@googlegroups.com
That worked. Thanks. Final code below

Ape.registerHookCmd("connect", function(params, cmd) {
    Ape.log('custom log');
    if ( ! params || ! params.token) return ["001", "INVALID PARAMS"];
checkLogin(params, cmd);
Ape.log('connect hook end');
return -1;
});
 
function checkLogin(params, cmd){
var request = new Http('myurl'  + params.token+'&proId='+params.proId);
request.getContent(function(result) { //call the PHP file
if ( ! result ) {
//send error if cannot contact page
cmd.sendResponse('ERR', {'code': 1001, 'value': 'error_codes._1001'});
Ape.log('USER_NOT_LOGGED_IN');
return 0;
}
var result2=JSON.parse(result);
if(result2.res == 'in auction'){
Ape.log('USER_LOGGED_IN');
Ape.addUser(cmd.user);

Urgent Programmer

unread,
Nov 14, 2012, 10:51:56 AM11/14/12
to ape-p...@googlegroups.com, ioa.g...@googlemail.com
Could you please delete this reply as I accidentally posted my IP?
Reply all
Reply to author
Forward
0 new messages