Login extension works but signs users as undefined

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Login extension works but signs users as undefined

Postby Ninjaoninja2 » 20 Mar 2014, 20:23

Hello,
Today I have an interesting problem, I setup the login extension but now when I login it lists me or anyone else who logs in "undefined" here is a picture of this happening Image now I will give you my extension code:

Code: Select all

var userList

function init()
{
        // Simple list of users
        // The key is the username, the value is the password
        userList = new Object()
       
        userList["Ninja"]    = "younoseemypass"
        userList["jerry"]    = "jerry"
        userList["smart"]    = "blah"
}


function destroy()
{
        trace("Bye bye!")
}

function handleRequest(cmd, params, user, fromRoom)
{
       
        // no requests to handle here...
}

function handleInternalEvent(evt)
{
        if (evt.name == "loginRequest")
        {
                var error = ""
               
                var nick = evt["nick"]
                var pass = evt["pass"]
                var chan = evt["chan"]
            
                if (userList[nick] != pass)
                {
                        error = "Authentication failed"
                }
                else
                {
                        var obj = _server.loginUser(nick, pass, chan)
                       
                        if (obj.success == false)
                        error = obj.error
                }
               
                // Send response to client
                var response = new Object()
               
                if (error == "")
                {
                        response._cmd = "logOK"
                }
                else
                {
                        response._cmd = "logKO"
                        response.err = error
                }
               
                _server.sendResponse(response, -1, null, chan)
               
        }
}

I don't see the problem here.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Login extension works but signs users as undefined

Postby Bax » 21 Mar 2014, 10:11

When using a custom login the response is sent back to the client via the extension and it is handled in the onExtensionResponse handler. For this reason the SmartFoxClient.myUserName and SmartFoxClient.myUserId properties ARE NOT populated auto-magically, so you will need to do it manually.
For example, on the server side add this:

Code: Select all

if (error == "")
{
   response._cmd = "logOK"
   response.uName = nick
}
else
...

And on the client side:

Code: Select all

if (resObj._cmd == "logOK")
{
   // Login successful
   smartfox.myUserName = resObj.uName
   ...
}

Then make sure the label in the interface reads the smartfox.myUserName property.
Paolo Bax
The SmartFoxServer Team
Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Re: Login extension works but signs users as undefined

Postby Ninjaoninja2 » 21 Mar 2014, 18:58

Bax wrote:When using a custom login the response is sent back to the client via the extension and it is handled in the onExtensionResponse handler. For this reason the SmartFoxClient.myUserName and SmartFoxClient.myUserId properties ARE NOT populated auto-magically, so you will need to do it manually.
For example, on the server side add this:

Code: Select all

if (error == "")
{
   response._cmd = "logOK"
   response.uName = nick
}
else
...

And on the client side:

Code: Select all

if (resObj._cmd == "logOK")
{
   // Login successful
   smartfox.myUserName = resObj.uName
   ...
}

Then make sure the label in the interface reads the smartfox.myUserName property.

Thanks for your response! I fixed it but then the bug came back.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Login extension works but signs users as undefined

Postby Bax » 22 Mar 2014, 08:30

Then I guess you didn't fix it :D
Paolo Bax
The SmartFoxServer Team

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 38 guests