Page 1 of 1

Storing and retrieving users

Posted: 29 Dec 2010, 06:03
by haplo
I would like to store user's variables in our dabase. We are currently using an external user ID from facebook and when the user login we verify them against their stored uid and sig. everything works fines and i've been able to use the

addEventHandler(SFSEventType.USER_LOGIN, LoginEventHandler.class);

the client will provide LOGIN_NAME as facebook uid and LOGIN_PASSWORD as signature.

after the user succesfully login i will do
outData.putUtfString(SFSConstants.NEW_LOGIN_NAME, dbobject.getUtfString("name"));

to change their name to whatever we stored in our db.


the problem starts when the event

addEventHandler(SFSEventType.USER_JOIN_ZONE, UserJoinZoneEventHandler.class);

which is bascily where i would like to load all the user's variables. The problem is that when this event is fired i no longer have the facebook id to use.


any ideas how to add custom data so server can identify the user's id?

Posted: 29 Dec 2010, 08:39
by smilefr
from the docs:
When working with asynchronous events such as USER_LOGIN and USER_JOIN_ZONE it's a bit more difficult to maintain the state of the current transaction/operation.

A convenient way to maintain the state is to use the User Session object. In particular the Session object allows to store custom parameters as key-value pairs. (See the javadoc, methods getProperty/setProperty etc...)
details about Session object here: http://docs2x.smartfoxserver.com/api-do ... ssion.html

I hope this helps.

Posted: 29 Dec 2010, 15:55
by Kai
http://docs2x.smartfoxserver.com/Gettin ... wtos#item3

Check out the above.

You can assign various properties to the session object. The sessuib can later be called up via the user.getSession() or through event parameters.

Enjoy!