Last Updated on : 2024-11-22 02:19:31download
Commercial Lock App SDK allows users to receive a verification code, register, log in, and reset their password using their email address.
API description
ThingOSUser.getUserInstance().sendVerifyCodeWithUserName(String userName, String region, String countryCode, int type, IResultCallback callback);
Parameter description
Parameter | Description |
---|---|
userName | The email address. |
region | The region. Default value: "" . |
countryCode | The country code, for example, 86 . |
type | The purpose of the verification code. Valid values:
|
callback | The callback. |
API description
This method validates the verification code that is used for login, registration, or password resetting with an email address.
ThingOSUser.getUserInstance().checkCodeWithUserName(String userName, String region, String countryCode, String code, int type, IResultCallback callback)
Parameter description
Parameter | Description |
---|---|
userName | The username. |
region | The region. Default value: "" . |
countryCode | The country code, for example, 86 . |
code | The verification code. |
type | The purpose of the verification code. Valid values:
|
callback | The callback. |
To allow users to register an account with an email address, you must make an API request to send a verification code.
API description
ThingOSUser.getUserInstance().registerAccountWithEmail(final String countryCode, final String email, final String passwd, final String code, final IRegisterCallback callback);
Parameter description
Parameter | Description |
---|---|
countryCode | The country code, for example, 86 . Note that account data cannot be migrated between countries or regions after the account is registered in a country or region. |
The email address. | |
passwd | The password. |
code | The verification code. |
callback | The callback. |
Example
// Get email verification code.
ThingOSUser.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 received", Toast.LENGTH_SHORT).show();
}
});
// Register with email address and password.
ThingOSUser.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
ThingOSUser.getUserInstance().loginWithEmail(String countryCode, String email, String passwd, final ILoginCallback callback);
Parameter | Description |
---|---|
countryCode | The country code, for example, 86 . |
The email address. | |
passwd | The login password. |
callback | The callback. |
Example
// Log in with email address and password.
ThingOSUser.getUserInstance().loginWithEmail("86", "123456@123.com", "123123", new ILoginCallback() {
@Override
public void onSuccess(User user) {
Toast.makeText(mContext, "Logged in. 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 verification code, you must make an API request to send a verification code.
API description
ThingOSUser.getUserInstance().loginWithEmailCode(String countryCode, String email, String code, ILoginCallback callback);
Parameter description
Parameter | Description |
---|---|
countryCode | The country code, for example, 86 . |
The email address. | |
code | The verification code. |
callback | The login callback. |
Example
ThingOSUser.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 received", Toast.LENGTH_SHORT).show();
}
});
ThingOSUser.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. Username:" +ThingOSUser.getUserInstance().getUser().getUsername(), Toast.LENGTH_SHORT).show();
}
});
To allow users to reset the password of an account 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
ThingOSUser.getUserInstance().resetEmailPassword(String countryCode, final String email, final String emailCode, final String passwd, final IResetPasswordCallback callback);
Parameter description
Parameter | Description |
---|---|
countryCode | The country code, for example, 86 . |
The email address. | |
emailCode | The verification code. |
passwd | The new password. |
callback | The callback. |
Example
// Get email verification code.
ThingOSUser.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 received", Toast.LENGTH_SHORT).show();
}
});
// Reset password.
ThingOSUser.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();
}
});
Bind a user account with a mobile phone number. Two methods are used in this process: obtaining a verification code for binding and binding a mobile phone number.
API description
ThingOSUser.getUserInstance().sendBindVerifyCode(String countryCode, String phoneNumber, IResultCallback callback);
Parameter description
Parameter | Description |
---|---|
countryCode | The country code. For example, 86 for mainland China. |
phoneNumber | The mobile phone number. |
callback | The callback. |
API description
ThingOSUser.getUserInstance().bindMobile(String countryCode, String phoneNumber, String code, IResultCallback callback);
Parameter description
Parameter | Description |
---|---|
countryCode | The country code. For example, 86 for mainland China. |
phoneNumber | The mobile phone number. |
code | The verification code. |
callback | The callback. |
Example
// Get verification code for binding.
ThingOSUser.getUserInstance().sendBindVerifyCode("86", "12345678901", new IResultCallback() {
@Override
public void onError(String code, String error) {
// TODO
}
@Override
public void onSuccess() {
// TODO
}
});
// Bind with a mobile phone number.
ThingOSUser.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