Sign Up

Getting users registered with your application is the first step for user management.

Kii Cloud allows users to register with a username/password combination. Optionally, a registration can be performed with phone numbers and/or email addresses. When assigning an email address or phone number to a user, you can let Kii Cloud take the steps necessary to verify the credentials (either through a verification email or an SMS).

For more details on the user sign up, please read User Sign up and Sign in. You can also learn more on the email and phone verification by reading Email Address and Phone Number Verification.

User Sign-Up

The following snippet shows how to sign up a user with the username user_123456, the e-mail address user_123456@example.com, a phone number +819012345678 and a password 123ABC.

KiiUser.Builder builder;
builder = KiiUser.BuilderWithName("user_123456");
builder.WithEmail("user_123456@example.com");
builder.WithPhone("+819012345678");
KiiUser user = builder.Build();

user.Register("123ABC", (KiiUser registeredUser, Exception e) => {
  if (e != null)
  {
    // handle error
    return;
  }
});

The basic steps are as follows:

  1. Create a KiiUser instance by calling the BuilderWithName method with a username, optionally setting an email address and phone number with the WithEmail and WithPhone methods. Then call the Build method.
  2. Register this KiiUser instance with the Register method passing the password as parameter. At this point, a new account will be created and the user will be signed-in.

Sign Up without a Username

You can also create a new account without a username. To create an account with an e-mail address or a phone number, use the BuilderWithEmail and BuilderWithPhone methods respectively. Note that in this case, the email and phone number (SMS) verification must be disabled (please check the next section for more details on the verification mechanism).

Sign up with a Local Phone Number

When you want to specify a local phone number, please also set a valid 2-letter country code using the Country property like in the following example:

string phoneNumber = "09051903944";
string country = "JP";
string password = "123456";
KiiUser user = KiiUser.BuilderWithPhone(phoneNumber).Build();
user.Country = country; // 2-letter country code
user.Register(password, (KiiUser registeredUser, Exception e) => {
  if (e != null)
  {
    // handle error
    return;
  }
});

Limitations

Some limitations (i.e., number and type of characters) apply to the user identifiers. Please read this section and References for more information.

Hint for Creating a User List

Kii Cloud currently does not provide an API for getting a list of users; you need to implement the feature in your application if you want to get the list (Note: if you just need to get a single user, you might be able to implement it with Retrieving Data from other Users feature).

You can, for example, prepare an application scope bucket. When a new user is created, your application can register an object with the UserID (or URI) of this user in the application scope bucket. Later, your application can get a list of users by getting the objects in the bucket. By registering user attributes such as the user names, you can also query for users with these attributes.

Please note that the overall performance of this method will degrade when the number of users increases dramatically. You will need to implement the feature so as to avoid querying massive amount of users. Please read Performance for the related discussion.

Also note that any users can access the application scope bucket. Registering user's private information such as email addresses in the bucket make them vulnerable (please read Security for the related discussion). Consider setting some access controls and accessing the bucket only via Server Code with App Administrator Privilege to protect the data.

Enabling E-mail and/or Phone Verification

You can configure your application to verify the user's e-mail address and/or phone number. You can toggle the verification on/off on the developer portal as follows:

  1. Click the "Edit" button in your application console at the developer portal.

  2. Click "USER MANAGEMENT".

  3. Toggle Email/SMS verification.

When enabled, the email address and/or phone number will be verified as follows:

E-mail Verification

When the e-mail verification is enabled and an account is registered with an email address, Kii Cloud will send an e-mail to the user with a verification link. Signing in with the specified e-mail address will only be allowed if the user previously clicked on the verification link.

The email verification is also launched when it is enabled and a user modifies their email address. Signing in with the new email address will be allowed after the user clicks a link in the verification email. When the verification is finished, the user will be notified with another email. The old email will be invalidated at this time.

Setting the Redirection URLs

You can specify web pages where users are redirected when they click the link in the verification email.

  1. Click "USER MANAGEMENT".

  2. Toggle "Email Address" verification ON

  3. Set the URLs for the redirection. The first URL is for the page to be shown when the email verification succeeded, while the second URL is for the page to be shown when the verification failed (e.g., the email is already verified).

    If not specified, the default page will be used (i.e., no redirection).

Setting your Custom Email Templates

You can customize the content of the notification emails on the developer portal.

  1. Click "EMAIL SETTINGS".

  2. To change the "From" address of the notification emails, configure the following UI.

  3. Click the "EDIT" button of the target template to customize.

    This will bring up an UI for defining the template for email subject and body.

    You can use the following placeholders for defining the verification email template.

    Placeholders To be replaced with
    ${url} A verification link (only in "Body").
    ${app.appID} The AppID of the application.
    ${user.displayName} The display name of the user.
    ${user.userID} The UserID of the user.
    ${user.unverifiedEmailAddress} The unverified email address of the user.
    ${user.loginName} The login name of the user.

    You can use the following placeholders for defining the completion email template.

    Placeholder To be replaced with
    ${app.appID} The AppID of the application.
    ${user.displayName} The display name of the user.
    ${user.userID} The UserID of the user.
    ${user.emailAddress} The verified email address of the user.
    ${user.loginName} The login name of the user.

    Please put a space before and after a placeholder, especially when you are using ${url} (otherwise the link in the email body may not work properly).

Phone (SMS) Verification

When the phone verification is enabled and an account is registered with a phone number, Kii Cloud will send an SMS message with a verification code. Your application should then ask the user to type in the verification code to complete the registration. Signing-in with the specified phone number will only be allowed if the user previously submitted the correct verification code.

The phone verification is also launched when it is enabled and a user modifies their phone number. Signing in with the new phone number will be allowed after the user sends the code in the verification SMS message. The old phone number will be invalidated when the verification process is finished.

Please Note: You must specify a valid mobile phone number in an international phone number format (starting with + and your country code) in order to properly begin the SMS verification process.

After receiving the SMS verification code from the user, your application should call the VerifyPhone method to complete the verification process.

string code = "XYZXYZXYZ"; // Verification code
user.VerifyPhone(code, (KiiUser verifiedUser, Exception e) => {
  if (e != null)
  {
    // handle error
    return;
  }
});

Setting your Custom SMS Template

You can customize the content of the SMS message on the developer portal.

  1. On the "USER MANAGEMENT" configuration screen, toggle "Phone Number" verification ON.

    This will bring up an UI for setting the SMS template.

    You can use the following placeholders for defining the SMS template.

    Placeholder To be replaced with
    ${code} The verification code.
    ${valid} The period of validity of the verification code (in hour).