Manage User Account Information

Last Updated on : 2024-11-22 02:19:31download

Commercial Lock App SDK supports user management. For example, bind users, modify user information, process session expiration, and delete users.

Bind email address with account

Send verification code

API description

void sendBindVerifyCodeWithEmail(@NonNull String countryCode, @NonNull String email, @NonNull IResultCallback callback);

Parameter description

Parameter Description
countryCode The country or region code. For example, 86 for mainland China.
email The email address.
callback The callback.

Bind email address

API description

void bindEmail(@NonNull String countryCode, @NonNull String email, @NonNull String code, @NonNull String sId, @NonNull IResultCallback callback);

Parameter description

Parameter Description
countryCode The country or region code. For example, 86 for mainland China.
email The email address.
code The verification code returned by sendBindVerifyCodeWithEmail.
sId The session ID of a user account. You can get the value from the user data model ThingOSUser.getUserInstance().getUser().getSid().
callback The callback.

Example

// Get email verification code.
ThingOSUser.getUserInstance().sendBindVerifyCodeWithEmail("86","123456@123.com", new IResultCallback(){

    @Override
    public void onError(String code, String error) {

    }

    @Override
    public void onSuccess() {
        Toast.makeText(mContext, "Verification code sent successfully", Toast.LENGTH_SHORT).show();
    }
});

// Bind an email address.
ThingOSUser.getUserInstance().bindEmail("86", "123456@123.com","123456", ThingOSUser.getUserInstance().getUser().getSid(), new IResultCallback() {
    @Override
    public void onError(String code, String error) {

    }

    @Override
    public void onSuccess() {
        Toast.makeText(mContext, "Bound successfully", Toast.LENGTH_SHORT).show();
    }
});

Change email address

API description

void changeUserName(String countryCode, String code, String sId, String userName, IResultCallback callback);

Parameter description

Parameter Description
countryCode The country or region code. For example, 86 for mainland China.
code The verification code returned by sendVerifyCodeWithUserName.
sId The session ID of a user account. You can get the value from the user data model ThingOSUser.getUserInstance().getUser().getSid().
userName The new email address.
callback The callback.

Example

// Get verification code to change the email address.
ThingOSUser.getUserInstance().sendVerifyCodeWithUserName("Send the verification code to the new email address",ThingOSUser.getUserInstance().getUser().getDomain().getRegionCode(),"86",7, new IResultCallback(){

    @Override
    public void onError(String code, String error) {

    }

    @Override
    public void onSuccess() {
        Toast.makeText(mContext, "Verification code sent successfully", Toast.LENGTH_SHORT).show();
    }
});

// Change email address.
ThingOSUser.getUserInstance().changeUserName("86", "123456", ThingOSUser.getUserInstance().getUser().getSid(), "123456@123.com",new IResultCallback() {
    @Override
    public void onError(String code, String error) {

    }

    @Override
    public void onSuccess() {
        Toast.makeText(mContext, "Bound successfully", Toast.LENGTH_SHORT).show();
    }
});

Modify account information

Change avatar

Compliance issues and risks might be caused if users are allowed to upload a custom avatar. To protect you from these potential problems, this API method is deprecated. Adjust your app features accordingly and avoid using this API method.

API description

void uploadUserAvatar(File file, IBooleanCallback callback)

Parameter description

Parameter Description
file The file of the avatar.
callback The callback.

Example

ThingOSUser.getUserInstance().uploadUserAvatar(
    file,
    new IBooleanCallback() {
        @Override
        public void onSuccess() {
        }

        @Override
        public void onError(String code, String error) {

        }
});

Modify nickname

API description

void updateNickName(String name, final IReNickNameCallback callback);

Parameter description

Parameter Description
name The nickname.
callback The callback.

Example

ThingOSUser.getUserInstance().updateNickName(nickName,
    new IReNickNameCallback() {
        @Override
        public void onSuccess() {
        }
        @Override
        public void onError(String code, String error) {

        }
});

Update user’s time zone

API description

void updateTimeZone(String timezoneId, IResultCallback callback);

Parameter description

Parameter Description
timezoneId The time zone ID, for example, Asia/Shanghai.
callback The callback.

Example

ThingOSUser.getUserInstance().updateTimeZone(
    timezoneId,
    new IResultCallback() {
        @Override
        public void onSuccess() {
        }

        @Override
        public void onError(String code, String error) {

        }
});

Update user’s location

You can report location information using the following method.

ThingSdk.setLatAndLong(lat,lon);

Synchronize account information

When user information, such as the avatar or nickname, is updated, synchronize it to keep it up-to-date.

When a user modifies their account information on one device while logged in to multiple devices, the changes need to synchronize across all devices. You can call the synchronization method to update user information when checking user information.

API description

void updateUserInfo(IResultCallback callback);

Parameter description

Parameter Description
callback The callback.

Example

ThingOSUser.getUserInstance().updateUserInfo(new IResultCallback() {
    @Override
    public void onError(String code, String error) {

    }

    @Override
    public void onSuccess() {
        User user = ThingOSUser.getUserInstance().getUser();
    }
});

Log out

Logs out of an anonymous account or other types of accounts.

Example for Java

ThingOSUser.getUserInstance().logout(new ILogoutCallback() {
  @Override
  public void onSuccess() {
    // Logged out successfully.
  }

  @Override
  public void onError(String errorCode, String errorMsg) {
  }
});

Deactivate or delete account

API description

Delete a user account. During the week following this delete operation, if the user is logged in again, the delete request is canceled. If not, the user is permanently disabled and all its information is deleted after this week.

void cancelAccount(IResultCallback callback);

Example

ThingOSUser.getUserInstance().cancelAccount(new IResultCallback() {
    @Override
    public void onError(String code, String error) {

    }
    @Override
    public void onSuccess() {

    }
});

Process session expiration

A login session may expire due to an exception or if the user has not logged in for an extended period, such as 45 days. If the user resets their password or deletes their account, the login session will expire. This method instructs users to log in to the app after a login session expires.

We recommend that you register a listener for session expiration in Application. When this callback is triggered, you can enable navigation to the login page and instruct the user to log in again.

API description

ThingSdk.setOnNeedLoginListener(INeedLoginListener needLoginListener);

Callback

needLoginListener.onNeedLogin(Context context);

Example

ThingSdk.setOnNeedLoginListener(new INeedLoginListener() {
  @Override
  public void onNeedLogin(Context context) {

  }
});