Class SFS2X.Requests.System.LoginRequest

Logs the current user in one of the server Zones.

Class Summary
Constructor Attributes Constructor Name and Description
 
SFS2X.Requests.System.LoginRequest(userName, password, params, zoneName)
Creates a new LoginRequest instance.

Class Detail

SFS2X.Requests.System.LoginRequest(userName, password, params, zoneName)
Creates a new LoginRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

This requests logs the current user in one of the server Zones. Each Zone represent an indipendent multiuser application governed by SmartFoxServer. In order to join a Zone, a user name and password are usually required. If the user credentials must be validated, a custom login process should be implemented in the Zone's server-side Extension.

Read the SmartFoxServer 2X documentation about the login process for more informations.

If the login operation is successful, the current user receives a login event; otherwise the loginError event is fired.

The following example performs a login in the "SimpleChat" Zone:

function someMethod()
{
	sfs.addEventListener(SFS2X.SFSEvent.LOGIN, onLogin, this);
	sfs.addEventListener(SFS2X.SFSEvent.LOGIN_ERROR, onLoginError, this);
	
	// Login
	sfs.send(new SFS2X.Requests.System.LoginRequest("FozzieTheBear", "", null, "SimpleChat"));
}

function onLogin(evtParams)
{
	console.log("Login successful!");
}

function onLoginError(evtParams)
{
	console.log("Login failure: " + evtParams.errorMessage);
}
Parameters:
{String} userName
The name to be assigned to the user. If not passed and if the Zone allows guest users, the name is generated automatically by the server.
{String} password Optional
The user password to access the system. SmartFoxServer doesn't offer a default authentication system, so the password must be validated implementing a custom login system in the Zone's server-side Extension.
{Object} params Optional
An object containing custom parameters to be passed to the Zone Extension (requires a custom login system to be in place).
{String} zoneName Optional
The name (case-sensitive) of the server Zone to login to; if a Zone name is not specified, the client will use the setting passed to the SmartFox class constructor.
See also:
SFS2X.SmartFox
SFS2X.SmartFox#send
SFS2X.SFSEvent.LOGIN
SFS2X.SFSEvent.LOGIN_ERROR