Erick, if this code, if (!$defined(params) || !$defined(params.name)) return 0; doesnt let you login , why if I return 0 inside request.getContent wouldnt do the same? I am cant figure this out....
On Jan 23, 12:24 pm, Erick Romero <[email protected]> wrote: > Seems you have issues on client-side too. > Anyhow try Pablo's suggestions and please post your results. > > On 01/23/2012 02:14 PM, utan wrote: > > > > > > > > > Ok, > > Not a go partially , > > > 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; > > //Ape.log(isbanned(cmd.ip)); > > var request = new Http('http://someplace/sql/banned_ips.php'); > > request.set('method', 'POST'); > > request.writeData('password', 'pass'); > > request.writeData('ip', cmd.ip); > > > request.getContent(function(result){ > > if(result != ""){ > > 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; > > } > > }).bind(this); > > > /*cmd.user.setProperty('name', params.name); > > cmd.user.setProperty('ip', cmd.ip); > > > return 1;*/ > > }); > > > it let me go to the page and wont show up the login form again, gives > > me javascript errors.. > > if I dont use bin(this) then it goes fine to the page with no > > javascript properties.. so bin(this) is doing and helping return > > something, but doesnt really work well. > > > On Jan 23, 11:45 am, Erick Romero <[email protected]> wrote: > >> Thanks Pablo. > >> Technically you are right hence getContent is another function that is > >> out of the scope of hook-connect. > > >> The "trick" is to send the next command inside such function when the > >> result is "false" or "zero". > >> Well, it works fine for me. Also http gets the content sent by the php > >> output with not issues. (I am using latest github APED compiled by myself) > > >> cmd.sendResponse('ERR', {'code': 1001, 'value': 'User does not > >> logged in'}); > > >> Utan, about "non-defined-variables", try to bind getContent to the hook > >> function. > >> I am using mootools on the server. I am copying my code below so you get > >> an idea. > > >> If this does not help you, then I have not more ideas ;-) > > >> var Users = new Class({ > > >> initialize: function() { > >> Ape.registerHookCmd('connect', this.on_connect.bind(this)); > >> }, > > >> on_connect: function(params, cmd) { > > >> if ( ! params || ! params.session_id) return 0; > > >> var request = new Http(local_urls.IS_USER_LOGGED + > >> params.session_id); > > >> request.getContent(function(result) { //call the PHP file > > >> if (result == 0) { > >> *cmd.sendResponse('ERR', {'code': 1001, 'value': > >> error_codes._1001});* > >> log('USER_NOT_LOGGED_IN'); > >> return 0; > >> } > > >> else { > > >> var data_user = JSON.parse(result); > > >> //set private properties > >> cmd.user.code = data_user.code; > >> cmd.user.uid = data_user.uid; > > >> //send to user its identification code > >> cmd.sendResponse('userCode', {'code': data_user.code}); > >> return 1; > >> } > > >> }*.bind(this));* > >> } > >> }); > > >> var global_users; > >> Ape.addEvent('init', function(){ > >> global_users = new Users(); > >> }); > > >> On 01/23/2012 01:12 PM, Pablo Tejada wrote: > > >>> Erik, > >>> Returning 0 inside the getContent callback does not returns it to the > >>> parent function which is the hook. The problem is in the Http class > >>> itself. > >>> I skim through the Http.js file and quickly spotted a fix but I'm > >>> currently mobile so I don't know if I'll be able do anything. If I'm > >>> able to do the edits that I think could solve this I will share the > >>> file with you guys in an attachment. > >>> On Jan 23, 2012 2:02 PM, "Erick Romero" <[email protected] > >>> <mailto:[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] > >>> <mailto:[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 > >>> <http://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 > >>> <http://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] > >>> <mailto:[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' > >>> <http://anyplace/sql/banned_ips.php%27>); > >>>>>>>>> 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 > >>> <http://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 <http://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] > >>> <mailto:[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 > > ... > > read more » -- 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/
