Last Updated on : 2024-06-12 10:22:42download
Term | Description |
---|---|
Merchant | The merchant entity information, including the merchant name and business license. |
Main account | The main account in a SaaS system, equivalent to a developer account. |
Sub-account | The sub-account in a SaaS system, which is associated with the main account. |
You can get the operation class for the specified IThingUser
through ThingOSUser.getUserInstance()
.
Both the main account and sub-account support login with a password. If pre-login is enabled, users will be presented with multiple merchants to choose from. You need to populate the selected merchant code into the login parameters and then prompt users to log in using a password.
API description
Log in with a password.
void loginWithPassword(ThingUserLoginWithPwdReqBean request, IThingUserLoginCallback<User> callback)
Parameter description
Parameter | Required | Description |
---|---|---|
userName | Required | The account or email address. |
password | Required | The password. |
countryCode | Required | The country code, for example, 86 . |
merchantCode | Optional | The merchant code. |
Example
/**
* Log in with a password
* @param view
*/
public void loginWithPwd(View view) {
String username = etUsername.getText().toString();
String merchantCode = etMerchant.getText().toString();
String password = etPwd.getText().toString();
ThingUserLoginWithPwdReqBean reqBean = new ThingUserLoginWithPwdReqBean();
reqBean.setPassword(password);
reqBean.setUsername(username);
reqBean.setCountryCode("86");
reqBean.setMerchantCode(merchantCode);
ThingOSUser.getUserInstance().loginWithPassword(reqBean, new IThingUserLoginCallback<User>() {
@Override
public void onPreLogin(List<ThingMerchantBean> merchantBeanList) {
StringBuilder sb = new StringBuilder();
for (ThingMerchantBean item : merchantBeanList) {
sb.append(item.getMerchantCode())
.append(item.getMerchantName())
.append("\n");
}
toast("Input merchant code");
L.d(TAG, "get merchantList");
L.d(TAG, sb.toString());
if(null != merchantBeanList && !merchantBeanList.isEmpty()){
String merchantCode = merchantBeanList.get(0).getMerchantCode();
etMerchant.setText(merchantCode);
toast("Specify merchant code");
}
}
@Override
public void onSuccess(User data) {
toast("login success");
}
@Override
public void onError(String errorCode, String errorMessage) {
L.e(TAG, errorMessage);
toast(errorMessage);
}
});
}
Request a verification code for login and then populate it into the login parameters. For a pre-login operation with multiple merchants, specify the merchant code to request a new verification code, and then use the received verification code and merchant code for login.
API description
Request a verification code for login.
void getValidateCode(ThingUserSendCodeReqBean request, IResultCallback callback)
Parameter description
Parameter | Description |
---|---|
countryCode | The country code, for example, 86 . |
username | Phone number or email address. |
codeType | The type of verification code. Set it to 0 for the login purpose. |
API description
Log in with a verification code.
void loginWithVerifyCode(ThingUserLoginWithCodeReqBean request, IThingUserLoginCallback<User> callback)
Parameter | Description |
---|---|
userName | Phone number or email address. |
code | The verification code. |
countryCode | The country code, for example, 86 . |
merchantCode | (Optional) The merchant code. |
/**
* Log in with a verification code
* @param view
*/
public void loginWithCode(View view) {
String username = etUsername.getText().toString();
String merchantCode = etMerchant.getText().toString();
String code = etCode.getText().toString();
ThingUserLoginWithCodeReqBean reqBean = new ThingUserLoginWithCodeReqBean();
reqBean.setCode(code);
reqBean.setUsername(username);
reqBean.setCountryCode("86");
reqBean.setMerchantCode(merchantCode);
ThingOSUser.getUserInstance().loginWithVerifyCode(reqBean, new IThingUserLoginCallback<User>() {
@Override
public void onPreLogin(List<ThingMerchantBean> merchantBeanList) {
StringBuilder sb = new StringBuilder();
for (ThingMerchantBean item : merchantBeanList) {
sb.append(item.getMerchantCode())
.append(item.getMerchantName())
.append("\n");
}
toast("Input merchant code");
L.d(TAG, "get merchantList");
L.d(TAG, sb.toString());
if(null != merchantBeanList && !merchantBeanList.isEmpty()){
String merchantCode = merchantBeanList.get(0).getMerchantCode();
etMerchant.setText(merchantCode);
toast("Specify merchant code");
}
}
@Override
public void onSuccess(User data) {
toast("login success");
}
@Override
public void onError(String errorCode, String errorMessage) {
L.e(TAG, errorMessage);
toast(errorMessage);
}
});
}
Authorization process
The third-party server grants an account access to the Tuya IoT Development Platform. The third party specifies the type of account, such as a system or employee account. For example, businesses, stores, and projects.
After authorization, the third-party server uses the account and country code to request a ticket from Tuya.
Scenarios
lighting.console.tuyacn.com?ticket=xxx
. For example, redirect users to the system website or an H5 page for device control.API description
Log in with a third-party account.
void loginByTicket(String ticket, IThingUserResultCallback<User> listener);
Parameter description
Parameter | Description |
---|---|
ticket | The ticket obtained during the authorization process. |
Example
ThingOSUser.getUserInstance().loginByTicket(content, new IThingUserResultCallback<User>(){
@Override
public void onSuccess(User user) {
Log.e(TAG,"Login successful")
}
@Override
public void onError(String code, String error) {
Log.e(TAG,"Login failed:" + error)
}
});
Three steps to change the password before login.
API description
Request a verification code.
void getValidateCode(ThingUserSendCodeReqBean request, IResultCallback callback)
Parameter description
Parameter | Description |
---|---|
countryCode | The country code, for example, 86 . |
username | Phone number or email address. |
codeType | The type of verification code. Set it to 2 . |
API description
Request the list of merchants.
void loginWithVerifyCode(ThingUserLoginWithCodeReqBean request, IThingUserLoginCallback<User> callback);
Parameter description
Parameter | Description |
---|---|
countryCode | The country code, for example, 86 . |
username | Phone number or email address. |
code | The verification code. |
API description
Reset the password.
void findPassword(ThingUserFindPwdReqBean request, IThingUserFindPasswordCallback callback);
Parameter | Description |
---|---|
username | Phone number or email address. |
newPassword | The new password. |
code | The verification code. |
countryCode | The country code, for example, 86 . |
merchantCode | The merchant code. |
/**
* 1.0 Get a verification code
* @param v
*/
public void getCode(View v){
String username = etUsername.getText().toString();
String merchantCode = etMerchant.getText().toString();
ThingUserSendCodeReqBean reqBean = new ThingUserSendCodeReqBean();
reqBean.setCountryCode("86");
reqBean.setUsername(username);
reqBean.setCodeType(codeType);
reqBean.setMerchantCode(merchantCode);
ThingOSUser.getUserInstance().getValidateCode(reqBean, new IResultCallback() {
@Override
public void onError(String code, String error) {
L.e(TAG, error);
toast(error);
}
@Override
public void onSuccess() {
toast("getCode success");
}
});
}
/**
* 2.0 Request the list of merchants
* @param view
*/
public void queryMerchants(View view) {
String username = etUsername.getText().toString();
String code = etCode.getText().toString();
ThingUserQueryMerchantWithCodeReqBean reqBean = new ThingUserQueryMerchantWithCodeReqBean();
reqBean.setCode(code);
reqBean.setCountryCode("86");
reqBean.setUsername(username);
ThingOSUser.getUserInstance().queryMerchantList(reqBean, new IThingUserResultCallback<List<ThingMerchantBean>>() {
@Override
public void onSuccess(List<ThingMerchantBean> data) {
if(null == data ){
toast("Merchant list is empty");
return;
}
int size = data.size();
if(0 <= size){
String merchantCode = data.get(0).getMerchantCode();
etMerchant.setText(merchantCode);
toast("queryMerchants success. Specify the 0th merchant code");
}
}
@Override
public void onError(String errorCode, String errorMessage) {
toast(errorMessage);
}
});
}
/**
* Recover the password.
* @param view
*/
public void resetPwd(View view) {
String username = etUsername.getText().toString();
String merchantCode = etMerchant.getText().toString();
String code = etCode.getText().toString();
String password = etPwd.getText().toString();
ThingUserFindPwdReqBean reqBean = new ThingUserFindPwdReqBean();
reqBean.setUsername(username);
reqBean.setNewPassword(password);
reqBean.setCode(code);
reqBean.setCountryCode("86");
reqBean.setMerchantCode(merchantCode);
ThingOSUser.getUserInstance().findPassword(reqBean, new IResultCallback() {
@Override
public void onError(String code, String error) {
toast(error);
}
@Override
public void onSuccess() {
toast("findPassword success");
}
});
}
To change the password after login, pass the old and new passwords.
API description
Change the password.
void modifyPassword(ThingUserModifyPwdReqBean request, IResultCallback callback);
Parameter | Description |
---|---|
oldPassword | The old password. |
newPassword | The new password. |
Example
public void modifyPwd(View view) {
String oldPwd = etPwd.getText().toString();
String newPwd = etNewPwd.getText().toString();
ThingUserModifyPwdReqBean reqBean = new ThingUserModifyPwdReqBean();
reqBean.setOldPassword(oldPwd);
reqBean.setNewPassword(newPwd);
ThingOSUser.getUserInstance().modifyPassword(reqBean, new IResultCallback() {
@Override
public void onError(String code, String error) {
toast(error);
L.e(TAG, error);
}
@Override
public void onSuccess() {
toast("modify success");
}
});
}
API description
Log out of an account.
void logout(IResultCallback callback)
API description
Delete an account.
void cancelAccount(IResultCallback callback)
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
Request and synchronize user information.
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();
}
});
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback