Android: graffiti sdk user registration and login process

Posted by focus310 on Wed, 13 Oct 2021 17:55:53 +0200

Send mobile verification code

TuyaHomeSdk.getUserInstance().sendVerifyCodeWithUserName(String userName, String region, String countryCode, int type, IResultCallback callback);
parameterexplain
userNamephone number
regionArea, which is filled in by default: "".
countryCodeMobile area code: such as "86"
typeSend verification code type. Value:
  • 1: Send a verification code when registering an account with a mobile phone number
  • 2: Send verification code when logging in with mobile phone number
  • 3: Send the verification code when resetting the password of the account registered by the mobile phone number
callbackCallback

Verify the filled verification code

Registered account, login account, reset account password

TuyaHomeSdk.getUserInstance().checkCodeWithUserName(String userName, String region, String countryCode, String code, int type, IResultCallback callback)

Required parameters

parameterexplain
userNameuser name
regionArea, which is filled in by default: ""
countryCodeCountry code
codeVerification Code
typeCheck type. Value:
  • 1: Verify the verification code when registering an account with a mobile phone number
  • 2: Check the verification code when logging in the account with the mobile phone number
  • 3: Verify the verification code when resetting the password of the account registered by the mobile phone number
  • 8: Verify the verification code when canceling the account registered by the mobile phone number
callbackCallback

Register your account with your mobile number

TuyaHomeSdk.getUserInstance().registerAccountWithPhone(final String countryCode, final String phoneNumber, final String passwd, final String code, final IRegisterCallback callback);
parameterexplain
countryCodeMobile area code: such as "86"
phoneNumberTelephone number
passwdpassword
codeVerification Code
callbackCallback

Registration case

// Get mobile phone verification code
TuyaHomeSdk.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, "Successfully obtained verification code", Toast.LENGTH_SHORT).show();
      }
    });
// Register mobile password account
TuyaHomeSdk.getUserInstance().registerAccountWithPhone("86","13666666666","123456","124332", new IRegisterCallback() {
  @Override
  public void onSuccess(User user) {
    Toast.makeText(mContext, "login was successful", Toast.LENGTH_SHORT).show();
  }
  @Override
  public void onError(String code, String error) {
    Toast.makeText(mContext, "code: " + code + "error:" + error, Toast.LENGTH_SHORT).show();
  }
});

Log in to your account with your mobile number and password

TuyaHomeSdk.getUserInstance().loginWithPhonePassword(String countryCode, String phone, String passwd, final ILoginCallback callback);
parameterexplain
countryCodeMobile area code: such as "86"
phonephone number
passwdLogin password
callbackLogin callback interface

Code case

//Mobile password login
TuyaHomeSdk.getUserInstance().loginWithPhonePassword("86", "13666666666", "123456", new ILoginCallback() {
  @Override
  public void onSuccess(User user) {
    Toast.makeText(mContext, "Login succeeded, user name:" +TuyaHomeSdk.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();
  }
});

Log in to your account with your mobile number and verification code

You need to call Verification code sending interface , send the verification code, and then call Verification code verification interface . Fill the received verification code into the corresponding parameters.

TuyaHomeSdk.getUserInstance().loginWithPhone(String countryCode, String phone, String code, final ILoginCallback callback)
parameterexplain
countryCodeMobile area code: such as "86"
phoneTelephone number
codeVerification Code
callbackLogin callback interface

Code case

//Get mobile phone verification code
TuyaHomeSdk.getUserInstance().sendVerifyCodeWithUserName("13666666666", "", "86", 2, 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, "Successfully obtained verification code", Toast.LENGTH_SHORT).show();
      }
    });
// Mobile authentication code login
TuyaHomeSdk.getUserInstance().loginWithPhone("86", "13355555555", "123456", new ILoginCallback() {
  @Override
  public void onSuccess(User user) {
    Toast.makeText(mContext, "Login succeeded, user name:" +TuyaHomeSdk.getUserInstance().getUser().getUsername(), Toast.LENGTH_SHORT).show();
  }
  @Override
  public void onError(String code, String error) {
    Toast.makeText(mContext, error, Toast.LENGTH_SHORT).show();
  }
});

Reset the account password of mobile phone number registration

TuyaHomeSdk.getUserInstance().resetPhonePassword(final String countryCode, final String phone, final String code, final String newPasswd, final IResetPasswordCallback callback);
parameterexplain
countryCodeMobile area code: such as "86"
phonephone number
codeVerification Code
newPasswdNew password
callbackCallback

Sample code

// Mobile phone access verification code
TuyaHomeSdk.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, "Successfully obtained verification code", Toast.LENGTH_SHORT).show();
      }
    });
// Reset phone password
TuyaHomeSdk.getUserInstance().resetPhonePassword("86", "13555555555", "123456", "123123", new IResetPasswordCallback(){
  @Override
  public void onSuccess() {
    Toast.makeText(mContext, "Password retrieved successfully", Toast.LENGTH_SHORT).show();
  }

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

After resetting the password, if multiple apps log in to this account at the same time, apps on other devices will trigger a callback of session failure. You need to implement the actions after callback, such as jump to the login page, etc.

Topics: Android