Class LoginRequest

  • All Implemented Interfaces:
    sfs2x.client.requests.IRequest

    public class LoginRequest
    extends BaseRequest
    Logs the current user in one of the server Zones.

    Each Zone represent an independent multiuser application governed by SmartFoxServer. In order to join a Zone, a user name and password are usually required. In order to validate the user credentials, 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
    The following example performs a login in the "SimpleChat" Zone:

     private void someMethod() {
         sfs.addEventListener(SFSEvent.LOGIN, new IEventListener() {
             public void dispatch(BaseEvent evt) throws SFSException {
                 System.out.println("Login successful!");
             }
         });
         sfs.addEventListener(SFSEvent.LOGIN_ERROR, new IEventListener() {
             public void dispatch(BaseEvent evt) throws SFSException {
                 System.out.println("Login failure: " + evt.getArguments().get("errorMessage"));
             }
         });
         
         // Login
         sfs.send(new LoginRequest("FozzieTheBear", "", "SimpleChat"));
     }
     
    See Also:
    SFSEvent.LOGIN, SFSEvent.LOGIN_ERROR
    • Field Detail

      • KEY_ZONE_NAME

        public static final java.lang.String KEY_ZONE_NAME
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_USER_NAME

        public static final java.lang.String KEY_USER_NAME
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_PASSWORD

        public static final java.lang.String KEY_PASSWORD
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_PARAMS

        public static final java.lang.String KEY_PARAMS
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_PRIVILEGE_ID

        public static final java.lang.String KEY_PRIVILEGE_ID
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_ID

        public static final java.lang.String KEY_ID
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_ROOMLIST

        public static final java.lang.String KEY_ROOMLIST
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_RECONNECTION_SECONDS

        public static final java.lang.String KEY_RECONNECTION_SECONDS
        * API internal usage only *
        See Also:
        Constant Field Values
    • Constructor Detail

      • LoginRequest

        public LoginRequest​(java.lang.String userName,
                            java.lang.String password,
                            java.lang.String zoneName,
                            com.smartfoxserver.v2.entities.data.ISFSObject params)
        Creates a new LoginRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.
        Parameters:
        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.
        password - 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.
        zoneName - The name (case-sensitive) of the server Zone to login to; if a Zone name is not specified, the client will use the setting loaded via SmartFox.loadConfig() method.
        params - An instance of SFSObject containing custom parameters to be passed to the Zone Extension (requires a custom login system to be in place).
        See Also:
        SmartFox.send(sfs2x.client.requests.IRequest), SmartFox.loadConfig(String, boolean), SFSObject
    • Method Detail

      • validate

        public void validate​(ISmartFox sfs)
                      throws sfs2x.client.exceptions.SFSValidationException
        * API internal usage only *
        Throws:
        sfs2x.client.exceptions.SFSValidationException
      • execute

        public void execute​(ISmartFox sfs)
        * API internal usage only *