Registering a User

Register a user using a predefined asynchronous authentication mechanism.

For registering the user, perform the following:
  1. Establish the connection between the client and mobile platform server by providing details such as application ID, domain, security configuration and so on. . To

    Before initializing connection between client and server, you need to initialize the SDMRequestManager to get user the details. To initialize the SDMRequestManager, perform the following:

    1. Initialize the SDMLogger method to obtain the mobile platform framework logs
    2. Initialize the SDMPreferences method to provide the connection preference
    3. Initialize the SDMConnectivityParameters method to provide user credentials and to enable XSRF (Cross-site request forgery) to avoid malicious exploit of website.
      SDMLogger logger = new SDMLogger();
      SDMPreferences pref = new SDMPreferences(context,
      logger);
      pref.setStringPreference(ISDMPreferences.SDM_CONNECTIVITY_HANDLER_C
      LASS_NAME, SDMConstants.SDM_HTTP_HANDLER_CLASS);
      SDMConnectivityParameters param = new
      SDMConnectivityParameters();
      /*Set the Username and Password in
      SDMConnectivityParameters.*/
      param.setUserName(Utilities.userName);
      param.setUserPassword(Utilities.password);
      /*Enable XSRF support.*/
      param.enableXsrf(true);
      
    /* Initialize the SDMRequestManager */
                SDMRequestManager reqMan = new SDMRequestManager(logger,pref, param, 1);
    /*Initialize the ClientConnection using ClientConnection(<Context>,<Application ID>, <Domain>,
    <SecurityConfig>,<SDMRequestManager>)*/
    ClientConnection  cc = new ClientConnection(getApplicationContext(),com.sap.NewFlight, default, SSO ,reqMan);
    
    Also, create the objects for user manager and application settings classes before implementation.
    /*Initialize the UserManager using UserManager(ClientConnection)*/
                  UserManager um = new UserManager(cc);
    
    /* Initialize the AppSettings class using AppSettings(ClientConnection)*/
                    AppSettings as = new AppSettings(cc);
  2. Provide the server details.
    /*Provide the server details such as the request type HTTP/HTTPS, host, port, and so on. relay server URL template, farm ID (can be set to "null" if relay server is not used)  */
        cc.setConnectionProfile(isHttp,host,port,null, null);
    
  3. Set the ISMPUserRegistrationListener listener for asynchronous registration.
    /*set the Listener in case of Asynchronous Registration. This class has to implement ISMPUserRegistrationListener to get the callback*/
    um.setUserRegistrationListener(this);
  4. Register the user asynchronously.
    /*Asynchronously register the user using um.register(isSynchronous)*/
    um.registerUser(false);
  5. (optional) To check if the user registration is successful or not. Failure or success of registration is obtained in the callback onAsyncRegistrationResult.
    @Override
              public void onAsyncRegistrationResult(State registrationState, ClientConnection clientConnection, int errCode, String errMsg) 
                {
                      if(registrationState == ISMPUserRegistrationListener.State.SUCCESS)
                            {
                                      Log.i("Tutorial", "Registration successful");
                             }
                }