Last Updated on : 2023-03-21 09:16:15download
Tuya Smart Life App SDK supports login with a verification code that is sent to a user’s email address.
This API method has been updated starting from the SDK version 3.26.5. If you are using an earlier version, you can update the version. For more information, see Update to v3.26.5.
API description
TuyaHomeSdk.getUserInstance().sendVerifyCodeWithUserName(String userName, String region, String countryCode, int type, IResultCallback callback);
Parameters
Parameter | Description |
---|---|
userName | The email address used for login. |
region | The area in which the verification code service is available for the account. Default value: "" . |
countryCode | The country code, such as 86 . |
type | The purpose of the verification code. Valid values:
|
callback | The callback. |
API description
Verifies a verification code that is used for login, registration, or password resetting with an email address.
TuyaHomeSdk.getUserInstance().checkCodeWithUserName(String userName, String region, String countryCode, String code, int type, IResultCallback callback)
Parameters
Parameter | Description |
---|---|
userName | The username. |
region | The area in which the verification code service is available for the account. Default value: "" . |
countryCode | The country code, such as 86 . |
code | The verification code. |
type | The purpose of the verification code. Valid values:
|
callback | The callback. |
To allow users to reset the password of an account that is registered with an email address, you must make an API request to send a verification code.
API description
TuyaHomeSdk.getUserInstance().registerAccountWithEmail(final String countryCode, final String email, final String passwd, final String code, final IRegisterCallback callback);
Parameters
Parameter | Description |
---|---|
countryCode | The country code, such as 86 . Note that account data cannot be migrated between countries or areas after the account is registered in a country or area. |
The email address of the user. | |
passwd | The password. |
code | The verification code. |
callback | The callback. |
Example
// Returns a verification code to an email address.
TuyaHomeSdk.getUserInstance().sendVerifyCodeWithUserName("123456@123.com", "", "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 an email address and a password.
TuyaHomeSdk.getUserInstance().registerAccountWithEmail("86", "123456@123.com","123456","5723", 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();
}
});
API description
TuyaHomeSdk.getUserInstance().loginWithEmail(String countryCode, String email, String passwd, final ILoginCallback callback);
Parameter | Description |
---|---|
countryCode | The country code, such as 86 . |
The email address of the user. | |
passwd | The password. |
callback | The callback. |
Example
// Enables login to the app with the email address and password.
TuyaHomeSdk.getUserInstance().loginWithEmail("86", "123456@123.com", "123123", new ILoginCallback() {
@Override
public void onSuccess(User user) {
Toast.makeText(mContext, "Logged in with Username: ").show();
}
@Override
public void onError(String code, String error) {
Toast.makeText(mContext, "code: " + code + "error:" + error, Toast.LENGTH_SHORT).show();
}
});
To allow users to log in with an email address and a verification code, you must make an API request to send a verification code.
API description
TuyaHomeSdk.getUserInstance().loginWithEmailCode(String countryCode, String email, String code, ILoginCallback callback);
Parameters
Parameter | Description |
---|---|
countryCode | The country code, such as 86 . |
The email address of the user. | |
code | The verification code. |
callback | The callback. |
Example
TuyaHomeSdk.getUserInstance().sendVerifyCodeWithUserName("123456@123.com", "", "86", 2, new IResultCallback() {
@Override
public void onError(String s, String s1) {
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();
}
});
TuyaHomeSdk.getUserInstance().loginWithEmailCode("86", "123456@123.com", "5723", new ILoginCallback() {
@Override
public void onError(String code, String error) {
Toast.makeText(mContext, error, Toast.LENGTH_SHORT).show();
}
@Override
public void onSuccess(User user) {
Toast.makeText(mContext, "Logged in with Username: " +TuyaHomeSdk.getUserInstance().getUser().getUsername(), Toast.LENGTH_SHORT).show();
}
});
To allow users to reset the password of an account that is registered with an email address, you must make an API request to send a verification code.
If an account is logged in on different mobile phones, after the password is reset with one of the phones, the app on other phones triggers the callback of session expiration. You must implement the actions after the callback. For example, navigate to the login page. For more information, see Login session expiration.
API description
TuyaHomeSdk.getUserInstance().resetEmailPassword(String countryCode, final String email, final String emailCode, final String passwd, final IResetPasswordCallback callback);
Parameters
Parameter | Description |
---|---|
countryCode | The country code, such as 86 . |
The email address of the user. | |
emailCode | The verification code. |
passwd | The new password. |
callback | The callback. |
Example
// Returns a verification code to an email address.
TuyaHomeSdk.getUserInstance().sendVerifyCodeWithUserName("123456@123.com", "", "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.
TuyaHomeSdk.getUserInstance().resetEmailPassword("86", "123456@123.com", "123123", "a12345", 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();
}
});
Enables binding a phone number with an app account and includes the APIs for the verification code service and phone number binding.
API description
TuyaHomeSdk.getUserInstance().sendBindVerifyCode(String countryCode, String phoneNumber, IResultCallback callback);
Parameters
Parameter | Description |
---|---|
countryCode | The country code. For example, 86 means mainland China. |
phoneNumber | The mobile phone number. |
callback | The callback. |
API description
TuyaHomeSdk.getUserInstance().bindMobile(String countryCode, String phoneNumber, String code, IResultCallback callback);
Parameters
Parameter | Description |
---|---|
countryCode | The country code. For example, 86 means mainland China. |
phoneNumber | The mobile phone number. |
code | The verification code. |
callback | The callback. |
Example
// Returns a verification code for binding.
TuyaHomeSdk.getUserInstance().sendBindVerifyCode("86", "12345678901", new IResultCallback() {
@Override
public void onError(String code, String error) {
// TODO
}
@Override
public void onSuccess() {
// TODO
}
});
// Binds the mobile phone number with the account.
TuyaHomeSdk.getUserInstance().bindMobile("86", "12345678901", "123456", new IResultCallback() {
@Override
public void onError(String code, String error) {
// TODO
}
@Override
public void onSuccess() {
// TODO
}
});
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback