Backendless Support
 

Registering app users with the User Registration API

This topic covers the issue of the user registration API (see the API documentation for Android, iOS, JavaScript, .NET, ActionScript, REST). The User Registration API is likely one of the first APIs you work with when a developer starts with Backendless. 

The API handles the process of registering a user with an application so he can login and use the application. The API uses the built-in BackendlessUser class (unless you use REST where it would be just a JSON object). 

The code below creates a user, sets the userid/password as well as an additional "phoneNumber" registration property and calls the backend. Please note that in mobile applications, you need to use the asynchronous version of the API.

You can download complete project with the source code using the links below: Java: https://backendless.com/documentation/samples/F2-UserRegistration-java.zip iOS (objective-c and swift): https:///backendless.com/documentation/samples/F2-RegisteringUsers-ios.zip 


JAVA

package com.mbaas.samples.userlogin;
import com.backendless.Backendless;
import com.backendless.BackendlessUser;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.exceptions.BackendlessFault;
public class Main
{
 public static String APP_ID = "YOUR-APP-ID";
 public static String SECRET_KEY = "YOUR-SECRET-KEY";
 public static String VERSION = "v1";
 public static void main( String[] args )
 {
 Backendless.initApp( APP_ID, SECRET_KEY, VERSION );
 registerUser();
 registerUserAsync();
 }
 private static void registerUser()
 {
 BackendlessUser user = new BackendlessUser();
 user.setEmail( "spidey@backendless.com" );
 user.setPassword( "greeng0blin" );
 user.setProperty( "phoneNumber", "214-555-1212" );
 BackendlessUser registeredUser = Backendless.UserService.register( user );
 System.out.println( "User has been registered - " + registeredUser.getObjectId() );
 }
 private static void registerUserAsync()
 {
 AsyncCallback<BackendlessUser> callback = new AsyncCallback<BackendlessUser>()
 {
 @Override
 public void handleResponse( BackendlessUser registeredUser )
 {
 System.out.println( "User has been registered - " + registeredUser.getObjectId() );
 }
 @Override
 public void handleFault( BackendlessFault backendlessFault )
 {
 System.out.println( "Server reported an error - " + backendlessFault.getMessage() );
 }
 };
 BackendlessUser user = new BackendlessUser();
 user.setEmail( "green.goblin@backendless.com" );
 user.setPassword( "sp1dey" );
 user.setProperty( "phoneNumber", "212-555-1212" );
 Backendless.UserService.register( user, callback );
 }
}

Once a developer runs the code, the users get registered and should be able to login (unless developer's  Backendless backend requires them to confirm the email address, which is another Feature). 

The registered users are shown in Backendless Console:

  1. Navigate to console, select an app and click the Data icon.
  2. The Users table should be selected by default. The users will show up there:
Is article helpful?