Last Updated on : 2024-06-12 10:22:55download
Tuya Smart Community App SDK supports login to a mobile app with a password.
To enhance data security, Tuya has optimized the verification code service for mobile phones and placed limits on users. To use the verification code service, contact your account manager of Tuya or submit a ticket to activate the service.
The SDK enables registration with the mobile phone number and password and includes the APIs for the verification code service and user registration.
API description
TuyaOSUser.getUserInstance().sendVerifyCodeWithUserName(String userName, String region, String countryCode, int type, IResultCallback callback);
Parameters
Parameter | Description |
---|---|
userName | The mobile phone number. |
region | The region in which the verification code service is available for the user. Default value: "" . |
countryCode | The country code. Set the value to 86 to specify mainland China. |
type | The type of verification code. Set the value to 1 to specify a registration verification code. |
callback | The callback. |
API description
TuyaOSUser.getUserInstance().registerAccountWithPhone(final String countryCode, final String phoneNumber, final String passwd, final String code, final IRegisterCallback callback);
Parameters
Parameter | Description |
---|---|
countryCode | The country code. Set the value to 86 to specify mainland China. |
phoneNumber | The mobile phone number. |
passwd | The login password. |
code | The verification code. |
callback | The callback. |
Example
// Returns a verification code to a mobile phone.
TuyaOSUser.getUserInstance().sendVerifyCodeWithUserName("13666666666", "", "86", 1, new IResultCallback() {
@Override
public void onError(String code, String error) {
Toast.makeText(mContext, "code: " + code + "error:" + error, Toast.LENGTH_SHORT).show();
}
@Override
public void onSuccess() {
Toast.makeText(mContext, "Verification code returned successfully.", Toast.LENGTH_SHORT).show();
}
});
// Registers an account with a mobile phone number and a password.
IRegisterCallback callback = new IRegisterCallback() {
@Override
public void onSuccess(User user) {
Toast.makeText(mContext, "Registered successfully.", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(String code, String error) {
Toast.makeText(mContext, "code: " + code + "error:" + error, Toast.LENGTH_SHORT).show();
}
};
TuyaOSUser.getUserInstance().registerAccountWithPhone("86","13666666666","123456","124332", callback);
API description
Enables login to the app with a mobile phone number and a password.
TuyaOSUser.getUserInstance().loginWithPhonePassword(String countryCode, String phone, String passwd, final ILoginCallback callback);
Parameters
Parameter | Description |
---|---|
countryCode | The country code. Set the value to 86 to specify mainland China. |
phone | The mobile phone number. |
passwd | The login password. |
callback | The callback. |
Example
// Enables login to the app with the mobile phone number and password.
TuyaOSUser.getUserInstance().loginWithPhonePassword("86", "13666666666", "123456", new ILoginCallback() {
@Override
public void onSuccess(User user) {
Toast.makeText(mContext, "Logged in successfully. Username: " +TuyaOSUser.getUserInstance().getUser().getUsername(), Toast.LENGTH_SHORT).show();
}
@Override
public void onError(String code, String error) {
Toast.makeText(mContext, "code: " + code + "error:" + error, Toast.LENGTH_SHORT).show();
}
});
The SDK enables login password resetting with the mobile phone number and includes the APIs for the verification code service and password resetting.
API description
Returns a verification code to a mobile phone. To enable this feature, the region in which the user is registered must support the verification code service.
TuyaOSUser.getUserInstance().sendVerifyCodeWithUserName(String userName, String region, String countryCode, int type, IResultCallback callback);
Parameters
Parameter | Description |
---|---|
userName | The mobile phone number. |
region | The region in which the verification code service is available for the user. Default value: "" . |
countryCode | The country code. Set the value to 86 to specify mainland China. |
type | The type of verification code. Set the value to 3 to specify a verification code used for password resetting. |
callback | The callback. |
API description
Resets the password of a user.
TuyaOSUser.getUserInstance().resetPhonePassword(final String countryCode, final String phone, final String code, final String newPasswd, final IResetPasswordCallback callback);
Parameters
Parameter | Description |
---|---|
countryCode | The country code. Set the value to 86 to specify mainland China. |
phone | The mobile phone number. |
code | The verification code. |
newPasswd | The new password. |
callback | The callback. |
Example
// Returns a verification code to a mobile phone.
TuyaOSUser.getUserInstance().sendVerifyCodeWithUserName("13666666666", "", "86", 3, new IResultCallback() {
@Override
public void onError(String code, String error) {
Toast.makeText(mContext, "code: " + code + "error:" + error, Toast.LENGTH_SHORT).show();
}
@Override
public void onSuccess() {
Toast.makeText(mContext, "Verification code returned successfully.", Toast.LENGTH_SHORT).show();
}
});
// Resets the password for login with the mobile phone number.
TuyaOSUser.getUserInstance().resetPhonePassword("86", "13555555555", "123456", "123123", new IResetPasswordCallback(){
@Override
public void onSuccess() {
Toast.makeText(mContext, "Password reset successfully.", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(String code, String error) {
Toast.makeText(mContext, "code: " + code + "error:" + error, Toast.LENGTH_SHORT).show();
}
});
Users can get different types of verification codes depending on their purposes.
API description
Verifies the validity of a verification code that can be used for login, registration, or password resetting.
TuyaOSUser.getUserInstance().checkCodeWithUserName(String userName, String region, String countryCode, String code, int type, IResultCallback callback)
Parameters
Parameter | Description |
---|---|
userName | The user’s mobile phone number. |
region | The region in which the verification code service is available for the user. Default value: "" . |
countryCode | The country code. Set the value to 86 to specify mainland China. |
code | The verification code. |
type | The purpose of a verification code. Valid values:
|
callback | The callback. |
A user can be registered with the verification code service only when the user’s region supports this service.
API description
TuyaOSUser.getUserInstance().getWhiteListWhoCanSendMobileCodeSuccess(IWhiteListCallback callback);
Parameters
Parameter | Description |
---|---|
callback | The callback. |
Example
TuyaOSUser.getUserInstance().getWhiteListWhoCanSendMobileCodeSuccess(new IWhiteListCallback() {
@Override
public void onSuccess(WhiteList whiteList) {
Toast.makeText(mContext, "Support for the verification code service is checked successfully: " + whiteList.getCountryCodes(), Toast.LENGTH_SHORT).show();
}
@Override
public void onError(String code, String error) {
Toast.makeText(mContext, "code: " + code + "error:" + error, Toast.LENGTH_SHORT).show();
}
});
Tuya IoT Platform supports user management. For example, bind users, modify user information, process session expiration, and delete users.
API description
Uploads a custom user avatar.
void uploadUserAvatar(File file, IBooleanCallback callback)
Parameters
Parameter | Type | Description |
---|---|---|
file | File | The user avatar file. |
callback | IBooleanCallback | The callback. |
Example
TuyaOSUser.getUserInstance().uploadUserAvatar(
file,
new IBooleanCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(String code, String error) {
}
});
API description
Changes a nickname.
void reRickName(String name, final IReNickNameCallback callback);
Parameters
Parameter | Type | Description |
---|---|---|
name | String | The nickname. |
callback | IReNickNameCallback | The callback. |
Example
TuyaOSUser.getUserInstance().reRickName(nickName,
new IReNickNameCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(String code, String error) {
}
});
If user information such as the avatar or nickname is changed, this API method is used to synchronize the latest user information. 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
Synchronizes user information.
void updateUserInfo(IResultCallback callback);
Parameters
Parameter | Type | Description |
---|---|---|
callback | IResultCallback | The callback. |
Example
TuyaOSUser.getUserInstance().updateUserInfo(new IResultCallback() {
@Override
public void onError(String code, String error) {
}
@Override
public void onSuccess() {
User user = TuyaOSUser.getUserInstance().getUser();
}
});
API description
Logs out of an anonymous account. This type of account is deleted immediately after logout. Other types of accounts might be deleted seven days after delete requests are sent.
void touristLogOut(final ILogoutCallback callback)
Parameters
Parameter | Type | Description |
---|---|---|
success | ILogoutCallback | The callback. |
Example
TuyaOSUser.getUserInstance().touristLogOut(new ILogoutCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(String code, String error) {
}
});
Java example
TuyaOSUser.getUserInstance().updateUserInfo(new IResultCallback() {
@Override
public void onError(String code, String error) {
}
@Override
public void onSuccess() {
User user = TuyaOSUser.getUserInstance().getUser();
}
});
API description
Deletes a user. 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
TuyaOSUser.getUserInstance().cancelAccount(new IResultCallback() {
@Override
public void onError(String code, String error) {
}
@Override
public void onSuccess() {
}
});
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback