Just for the record is not the APE server's fault, is the way JS works and
the way you have structured your application. For example this function:
function setloggedinProperties(user){
var usernick = user.getProperty('name').toLowerCase();
sql.query('SELECT * FROM pfc_login WHERE BINARY
username="'+Ape.MySQL.escape(usernick)+'"',function(res,error){
if(error){
Ape.log('There was an error in the query'+this.errorString()+'');
}else{
if(res != ''){
return res[0].isauthorized;
}
}
});
}
You can not return a value inside the sql.query() callback and expect to
get it the in the callback's parent parent function. Is tricky and could be
confusing,
Is why i mention you should move your code inside the callback or create
another function to be called inside the callback to handle the result.
For example, try to move the line 'if
(res)cmd.user.setProperty('isauthorized', res)' inside the callback, it
should look like this:
function setloggedinProperties(user, cmd){
var usernick = user.getProperty('name').toLowerCase();
sql.query('SELECT * FROM pfc_login WHERE BINARY
username="'+Ape.MySQL.escape(usernick)+'"',function(res,error){
if(error){
Ape.log('There was an error in the query'+this.errorString()+'');
}else{
if (res){ cmd.user.setProperty('isauthorized', res) }
}
});
}
Notice i added a second parameter to include the cmd object so the function
call should pass the 'cmd' in the second parameter.
On Mon, Mar 5, 2012 at 7:45 PM, UTAN <[email protected]> wrote:
> Is inside the connect hook,
>
> I am setting properties inside the else if there is not error
> callback,
> if(error){
> Ape.log('There was an error in the query
> '+this.errorString()+'');
> }else{
> var isauthorized;
> if(res != ''){
> isauthorized = res[0].isauthorized;
> }
> if
> (isauthorized)user.setProperty('isauthorized', isauthorized);
> }
>
> inside the mysql query..
>
> but that doesnt work, works but properties are set too late..
>
> I am trying something like this:
>
> 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 > 16 || params.name.test('[^a-zA-
> Z0-9]',
> 'i')) return ["006", "BAD_NICK"];
> var res, isauthorized;
> cmd.user.setProperty('name', params.name);
> cmd.user.setProperty('ip', cmd.ip);
> res = setloggedinProperties(cmd.user);
>
> if (res)cmd.user.setProperty('isauthorized', res);
>
> return 1;
>
> });
>
>
> function setloggedinProperties(user){
>
> var usernick = user.getProperty('name').toLowerCase();
>
> sql.query('SELECT * FROM pfc_login WHERE BINARY
> username="'+Ape.MySQL.escape(usernick)+'"',function(res,error){
> if(error){
> Ape.log('There was an error in the query
> '+this.errorString()+'');
> }else{
> if(res != ''){
> return res[0].isauthorized;
> }
> }
> });
>
> }
>
>
> I got return inside the query but doesn't return to the parent
> function...
>
> what should I do...
>
>
>
>
> --
> 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/
>
--
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/