LoginRequest
Logs the current user in one of the server Zones.
new 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 executed.
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.
Example
This example performs a login in the "BasicExamples" Zone.
function someMethod()
{
sfs.addEventListener(SFS2X.SFSEvent.LOGIN, onLogin, this);
sfs.addEventListener(SFS2X.SFSEvent.LOGIN_ERROR, onLoginError, this);
// Login
sfs.send(new SFS2X.LoginRequest("FozzieTheBear", "", null, "BasicExamples"));
}
function onLogin(evtParams)
{
console.log("Login successful!");
}
function onLoginError(evtParams)
{
console.log("Login failure: " + evtParams.errorMessage);
}
Parameters
Name | Type | Optional | Description |
---|---|---|---|
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. Defaults to |
password |
|
Yes |
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. Defaults to |
params |
|
Yes |
An instance of SFSObject containing custom parameters to be passed to the Zone Extension (requires the custom login system to be active). Defaults to |
zoneName |
|
Yes |
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. Defaults to |