Correct, the problem is server side, when called the php return 1 if
the user ip is banned and empty if is not from this php code echo
mysql_num_rows($query) > 0; , so in the your proposed code should have
been if(result != "") then return 0
the code should have stopped the user to login but it doesn't, if you
see this code above at the beginning of the hook
if (!$defined(params) || !$defined(params.name)) return 0; the return
0 is sufficient to stop the code from running and wont allow the user
to pass the login form..
I shouldn't code anything else at serve side because the return 0
would reshow the login form as it doesn't when it tests if (!
$defined(params) || !$defined(params.name))..
So I have no Idea why is this happening at all..


On Jan 23, 11:02 am, Erick Romero <[email protected]> wrote:
> No sure if I understand what you mean.
> I am understanding that your problem is on the server side.  If you have
> troubles into the client-side you should add more information.
>
> By the way, is the flow-logic entering into the if (result == '')?
> If it is the case, then the hook is returning zero and the code should
> stop there (returning zero into the hook-connect server makes
> client-users to be dropped)
>
> If the flow-logic is not entering into the "if" quoted above, in that
> case make the PHP-file outputs ZERO when there are not match instead of
> a empty char and change the IF to if (result === 0)
>
> On 01/23/2012 12:44 PM, utan wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I 've tried your suggestion too I get this nickname.js:40:TypeError:
> > user.getProperty("name") is undefined
> > and the code runs after the else, but when logged in, the
> > user.properties is undefined.. so somehow it stops the code but the
> > wrong way..
> > My brain is about to explode.. ROLF
>
> > On Jan 23, 10:25 am, Erick Romero <[email protected]> wrote:
> >> What about this:
>
> >>     Ape.registerHookCmd("connect", function(params, cmd) {
>
> >>         if ( ! params || ! params.session_id) return 0;
>
> >>         var request = new Http("your_php_file");
> >>         request.getContent(function(result) { //call the PHP file
>
> >>             if (result == '') { //YOUR PHP is sending an EMPTY when
> >>     there are not match (as you wrote)
>
> >>                 cmd.sendResponse('ERR', {'code': 1001, 'value': 'User
> >>     BANNED'});
> >>                 return 0;
>
> >>             } else {
>
> >>                 cmd.user.setProperty('name', params.name);
> >>                 cmd.user.setProperty('ip', cmd.ip);
> >>                 return 1;
>
> >>             }
> >>         });
>
> >>     });
>
> >> On 01/23/2012 11:34 AM, utan wrote:
>
> >>> Ok, moved the function code to the hook , now I have the code like
> >>> this:
> >>> code before to call the php file
> >>> request.getContent(function (result){
> >>>    if(result){
> >>>            return 0;
> >>>    }
> >>>    else{
> >>>            cmd.user.setProperty('name', params.name);
> >>>            cmd.user.setProperty('ip', cmd.ip);
> >>>    }
> >>>    });
> >>> but still the code runs after the return 0 , then the page opens but
> >>> with error user.properites are undefined..
> >>> and server side gets me this: TypeError: user.getProperty("name") is
> >>> undefined
> >>> since I am not working with a function when returning the code doesnt
> >>> stop..
> >>> any thoughts?
> >>> On Jan 23, 9:08 am, Erick Romero <[email protected]> wrote:
> >>>> Try the following:
> >>>> Remove "return 1" from connect hook. As you said, the code will be ran
> >>>> before you get the php response; so no matter if it is banned you are
> >>>> returning 1 (true).
> >>>> I would delete is_banned function and move that logic into connect hook,
> >>>> making a IF to return 0 or 1 for the connect hook based on the 
> >>>> php-response.
> >>>> Also you may move the logic user-setProperty into the if (the side that
> >>>> returns 1)
> >>>> On 01/23/2012 10:44 AM, utan wrote:
> >>>>> Thanks for your help,
> >>>>> I end up doing all the work at php side, send the ip with http and
> >>>>> then checking it at php level return either true or false and work
> >>>>> with it.
> >>>>> There is a problem , in the moment the http does its job the other
> >>>>> code had run and even if true it doesn't return because I think
> >>>>> because  anonymous function  or because it doesn't have a response yet
> >>>>> from php server side..
> >>>>> which then tests as false and keep running the code.. this is what I
> >>>>> am doing..
> >>>>> I have a function in name.js,
> >>>>> function isbanned(ip){
> >>>>>    var request = new Http('http://anyplace/sql/banned_ips.php');
> >>>>>    request.set('method', 'POST');
> >>>>>    request.writeData('password', 'any');
> >>>>>    request.writeData('ip', ip);
> >>>>>    request.getContent(function (result){
> >>>>>            Ape.log(ip);
> >>>>>       return result;
> >>>>>    });
> >>>>> }
> >>>>> and
> >>>>> Ape.registerHookCmd("connect", function(params, cmd) {
> >>>>>    if (!$defined(params) || !$defined(params.name)) return 0;
> >>>>>    if (userlist.has(params.name.toLowerCase())) return ["007",
> >>>>> "NICK_USED"];
> >>>>>    if (params.name.length > 9 || params.name.test('[^a-zA-Z0-9]', 'i'))
> >>>>> return ["006", "BAD_NICK"];
> >>>>>    if(isbanned(cmd.ip))return 0;// if true would return 0 and the code
> >>>>> should stop
> >>>>>    cmd.user.setProperty('name', params.name);
> >>>>>    cmd.user.setProperty('ip', cmd.ip);
> >>>>>    return 1;
> >>>>> });
> >>>>> If I put the code directly in Ape.registerHookCmd I have the same
> >>>>> result, doesnt matter if is true or false the code continued to the
> >>>>> next code , but if I test putting a return 1  before
> >>>>> request.getContent the code stops and do what I want..
> >>>>> maybe I still dont know much but why is this? if I do with json you
> >>>>> think I will have better luck?
> >>>>> On Jan 23, 6:24 am, Erick Romero <[email protected]> wrote:
> >>>>>> You should add JSON  to the server.
> >>>>>> I made it in this way:
> >>>>>> 1. Download the JSON file from the below link.
> >>>>>> 2. Add the file inside the server under "framework" directory
> >>>>>> 3. Modify "main.ape.js" in the server and add the line
> >>>>>> "include("framework/JSON.js");"
> >>>>>> 3. That's all.
> >>>>>>http://www.json.org/js.html
> >>>>>> github:https://github.com/douglascrockford/JSON-js
> >>>>>> Now in php you do
> >>>>>> var data = array('name'=>'naruto', 'age'=>'15' );
> >>>>>> /echo json_encode(/data);
> >>>>>> And in the server:
> >>>>>> /
> >>>>>> var request = new Http(URL);
> >>>>>> request.getContent(function(result) { //call the PHP file
> >>>>>>     if ( ! result) {
> >>>>>>         cmd.sendResponse('ERR', {'code': 1001, 'value':
> >>>>>> 'error_codes._1001'});
> >>>>>>         Ape.log('USER_NOT_LOGGED_IN');
> >>>>>>         return 0;
> >>>>>>     }
> >>>>>>     var data_user = JSON.parse(result)
> >>>>>>     Ape.log(data_user.name);
> >>>>>> //    Ape.log(data_user.age
> >>>>>>     return 1;
> >>>>>> //}/
> >>>>>> On 01/22/2012 08:04 PM, utan wrote:
> >>>>>>> Hi,
> >>>>>>> Sorry to highjack this tread, I've done the same I get the response
> >>>>>>> from the php db array  json encoded , but when I try to use it in the
> >>>>>>> serverside of Ape and try something like this:
> >>>>>>> request.getContent(function (result){
> >>>>>>>            Ape.log(result.ID);
> >>>>>>>       });
> >>>>>>> where result has the json from the test.php, if I try to access say
> >>>>>>> result.ID I get JavaScript : undefined , how can I access it properly,
> >>>>>>> tried JSON.decode(); but is not a function and I think core doesnt
> >>>>>>> have loaded..
> >>>>>>> need to convert it to object so I can use.. can find if Ape has json
> >>>>>>> decode to work with..
> >>>>>>> thanks for any help.
> >>>>>>> On Jan 17, 2:19 pm, Erick Romero <[email protected]> wrote:
> >>>>>>>> This works for me:
> >>>>>>>> 1. On APE Server use Http to fetch test.php (included into
> >>>>>>>> APE_server/framework). Define a call back for that Http
> >>>>>>>> 2. Test.php handles mysql functions and sends back the data (a simple
> >>>>>>>> echo works). For convenience I send the data JSON encoded
> >>>>>>>> 3. The http-call-back on APE server handles the raw with the data 
> >>>>>>>> retrieved.
> >>>>>>>> On 01/17/2012 03:54 PM, Micael Ribeiros wrote:
> >>>>>>>>> Is there a better way to do this besides this one:
> >>>>>>>>> 1: On APE Server use mootools Request method to send a 
> >>>>>>>>> XMLHttpRequest
> >>>>>>>>> to a test.php file
> >>>>>>>>> 2: On the test.php file retrieve the mysql data and send it back 
> >>>>>>>>> using
> >>>>>>>>> file_get_contents or curl to send a Raw to the APE Server
> >>>>>>>>> 3: On APE Server process the raw with the mysql data received from 
> >>>>>>>>> the
> >>>>>>>>> php script
> >>>>>>>>> ?
> >>>>>>>>> Thank you in advance for any response

-- 
You received this message because you are subscribed to the Google
Groups "APE Project" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
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/

Reply via email to