Email System

Last Updated on : 2022-02-17 06:12:51download

Tuya Smart provides a login system for email registration.

Account registration

There are two interfaces for email registration. First, get the verification code, and then use the verification code and password to register.

Get verification code

TuyaOSUser.getUserInstance().sendVerifyCodeWithUserName(String userName, String region, String countryCode, int type, IResultCallback callback);

Parameters

Parameter Description
userName email address
region Region, fill in by default: “” is fine
countryCode Country code: such as “86”
type Type of verification code sent: 1: Register verification code
callback callback

Registration

void registerAccountWithEmail (final String countryCode, final String email, final String passwd, final String code, final IRegisterCallback callback);

Parameters

Parameters Description
countryCode country code, for example: 86
email email
passwd password
code Verification Code
callback callback

Example

// Sign up for email verification code
TuyaOSUser.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, "Get the verification code successfully", Toast.LENGTH_SHORT).show();
			}
		});
// Email password registration
TuyaOSUser.getUserInstance(). registerAccountWithEmail ("86", "123456@123.com", "123456", "5723", new IRegisterCallback () {
    @Override
    public void onSuccess (User user) {
        Toast.makeText (mContext, "Registration succeeded", Toast.LENGTH_SHORT) .show ();
    }

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

Note:

Once the account is registered in one country, data cannot currently be migrated to other countries.

Login with Email

User email password login

TuyaOSUser.getUserInstance().loginWithEmail(String countryCode, String email, String passwd, final ILoginCallback callback);

Parameters

Parameters Description
countryCode country code, for example: 86
email email
passwd Login password
callback callback

Example

// mail password login
TuyaOSUser.getUserInstance().loginWithEmail("86", "123456@123.com", "123123", new ILoginCallback () {
    @Override
    public void onSuccess (User user) {
        Toast.makeText (mContext, "Login succeeded, username:"). Show ();
    }

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

User email reset password

The user mailbox reset password function is divided into two interfaces, a verification code interface, and a password reset interface.

Get verification code

TuyaOSUser.getUserInstance().sendVerifyCodeWithUserName(String userName, String region, String countryCode, int type, IResultCallback callback);

Parameters

Parameter Description
userName email address
region Region, fill in by default: “” is fine
countryCode Country code: such as “86”
type Type of verification code sent: 3: Reset password verification code
callback callback

Email reset password

TuyaOSUser.getUserInstance().resetEmailPassword (String countryCode, final String email, final String emailCode, final String passwd, final IResetPasswordCallback callback);

Parameters

Parameters Description
countryCode country code, for example: 86
email email
emailCode verification code
passwd New password
callback callback

Example

// Get email verification code
TuyaOSUser.getUserInstance().getEmailValidateCode("86", "123456@123.com", new IValidateCallback () {
    @Override
    public void onSuccess () {
        Toast.makeText (mContext, "Success in obtaining verification code", Toast.LENGTH_SHORT) .show ();
    }
    @Override
    public void onError (String code, String error) {
        Toast.makeText (mContext, "code:" + code + "error:" + error, Toast.LENGTH_SHORT) .show ();
    }
});
//reset Password
TuyaOSUser.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, "Get the verification code successfully", Toast.LENGTH_SHORT).show();
			}
		});

Verification of verification code

Description

Verification verification code, used for verification verification during registration, login, and password reset

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

Parameters

Parameters Description
userName User name
region region,Fill in the default: “”
countryCode Country code
code Verification code
type Type:
1: For verification code verification during registration
2: Use the verification code to log in
3: Used when resetting the password
8: Used when canceling the account