Manage User Accounts

Last Updated on : 2023-03-09 08:17:41

Tuya IoT Development Platform 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);

Parameters

Parameter Description
countryCode The country code. For example, 86 means mainland China.
email The email address of the user.
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);

Parameters

Parameter Description
countryCode The country code. For example, 86 means mainland China.
email The email address of the user.
code The verification code. You must call sendBindVerifyCodeWithEmail to send a verification code.
sId The session ID of the user. You can query the user data model TuyaHomeSdk.getUserInstance().getUser().getSid() to get the value.
callback The callback.

Example

// Returns a verification code to an email address.
TuyaHomeSdk.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 returned successfully.", Toast.LENGTH_SHORT).show();
	}
});

// Binds the email address with the account.
TuyaHomeSdk.getUserInstance().bindEmail("86", "123456@123.com","123456", TuyaHomeSdk.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();
	}
});

Modify account information

Change a user avatar

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

API description

void uploadUserAvatar(File file, IBooleanCallback callback)

Parameters

Parameter Description
file The user avatar file.
callback The callback.

Example

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

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

        }
});

Set temperature unit to Celsius or Fahrenheit

API description

void setTempUnit(TempUnitEnum unit, IResultCallback callback);
Parameter Description
unit The unit of temperature. Valid values:
  • TempUnitEnum.Celsius: °C
  • TempUnitEnum.Fahrenheit: °F
callback The callback.

Modify the nickname

API description

void updateNickName(String name, final IReNickNameCallback callback);

Parameters

Parameter Description
name The nickname.
callback The callback.

Example

TuyaHomeSdk.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);

Parameters

Parameter Description
timezoneId The time zone ID. Example: Asia/Shanghai.
callback The callback.

Example

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

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

        }
});

Update user’s location

Reports the location of the current user as required.

TuyaSdk.setLatAndLong(lat,lon);

Synchronize users

Synchronizes the latest user information if user information such as the avatar or nickname is changed.

If the user is logged in from multiple mobile phones and one of the mobile phones has user information changed, the changes are synchronized to the other mobile phone when the user information is checked on the mobile phone.

API description

void updateUserInfo(IResultCallback callback);

Parameters

Parameter Description
callback The callback.

Example

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

    }

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

Log out of account

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

Log out of an anonymous account

API description

Logs out of an anonymous account. This type of account is deleted immediately after logout.

void touristLogOut(final ILogoutCallback callback)

Parameters

Parameter Type Description
success ILogoutCallback The callback.

Example

TuyaHomeSdk.getUserInstance().touristLogOut(new ILogoutCallback() {
    @Override
    public void onSuccess() {

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

    }
});

Log out of other types of accounts

Example for Java

TuyaHomeSdk.getUserInstance().logout(new ILogoutCallback() {
  @Override
  public void onSuccess() {
    // Logout is successful.
  }

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

Inactivate or delete account

API description

Deletes 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

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

    }
    @Override
    public void onSuccess() {

    }
});

Process session expiration

Guides users to exit and log in to the app again after a login session expires to recreate the session. A login session might expire if certain exceptions occur or the user has not logged in for a long period such as 45 days, and when the user resets the password or deletes the account.

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 instructs the user to log in again.

API description

TuyaHomeSdk.setOnNeedLoginListener(INeedLoginListener needLoginListener);

Callback

needLoginListener.onNeedLogin(Context context);

Example

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

  }
});

<! --目前此接口功能未完善,先下掉–>
<! --## 通过云开发获取用户信息 -->

For more information, see Refresh token.

API description

You can call a third-party API method to get the ticket field and call the current API method to get user information.

TuyaHomeSdk.getUserInstance().loginWithTicket(String ticket, ILoginCallback callback);
Parameter Description
ticket The third-party app uses the temporary ticket to access SDK capabilities provided by Tuya.

Example

// Returns user information.
TuyaHomeSdk.getUserInstance().loginWithTicket("ticket", new ILoginCallback() {
	@Override
	public void onSuccess(User user) {
		Toast.makeText(mContext, "User information returned successfully:" , Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onError(String code, String error) {
		Toast.makeText(mContext, "code: " + code + "error:" + error, Toast.LENGTH_SHORT).show();
	}
});