Search in sources :

Example 1 with VerifiedPhoneEvent

use of com.waz.zclient.core.controllers.tracking.events.registration.VerifiedPhoneEvent in project wire-android by wireapp.

the class AppEntryStore method submitCode.

@Override
public void submitCode(String phoneVerificationCode, final ErrorCallback errorCallback) {
    setAndStorePhoneVerificationCode(phoneVerificationCode);
    if (entryPoint == AppEntryState.PHONE_REGISTER) {
        zMessagingApi.verifyPhoneNumber(countryCode + phone, phoneVerificationCode, KindOfVerification.PREVERIFY_ON_REGISTRATION, new ZMessagingApi.PhoneNumberVerificationListener() {

            @Override
            public void onVerified(KindOfVerification kindOfVerification) {
                appEntryStateCallback.tagAppEntryEvent(new VerifiedPhoneEvent(OutcomeAttribute.SUCCESS, "", "", getPhoneRegistrationContext()));
                setState(AppEntryState.PHONE_SET_NAME);
            }

            @Override
            public void onVerificationFailed(KindOfVerification kindOfVerification, int errorCode, String message, String label) {
                appEntryStateCallback.tagAppEntryEvent(new VerifiedPhoneEvent(OutcomeAttribute.FAIL, String.valueOf(errorCode), message + "; " + label, getPhoneRegistrationContext()));
                if (AppEntryError.PHONE_INVALID_REGISTRATION_CODE.correspondsTo(errorCode, label)) {
                    errorCallback.onError(AppEntryError.PHONE_INVALID_REGISTRATION_CODE);
                } else {
                    errorCallback.onError(AppEntryError.PHONE_REGISTER_GENERIC_ERROR);
                }
            }
        });
    } else if (entryPoint == AppEntryState.PHONE_SIGN_IN) {
        ignoreSelfUpdates = true;
        zMessagingApi.login(CredentialsFactory.phoneCredentials(countryCode + phone, phoneVerificationCode), new LoginListener() {

            @Override
            public void onSuccess(Self self) {
                appEntryStateCallback.tagAppEntryEvent(PhoneVerification.success(PhoneVerification.Context.SIGN_IN));
                appEntryStateCallback.tagAppEntryEvent(new LoggedInEvent(true));
                bindSelf(self);
                setState(AppEntryState.PHONE_SIGNED_IN);
                ignoreSelfUpdates = false;
            }

            @Override
            public void onFailed(int errorCode, String message, String label) {
                appEntryStateCallback.tagAppEntryEvent(PhoneVerification.error(PhoneVerification.Context.SIGN_IN));
                if (AppEntryError.PHONE_INVALID_LOGIN_CODE.correspondsTo(errorCode, "")) {
                    errorCallback.onError(AppEntryError.PHONE_INVALID_LOGIN_CODE);
                } else if (AppEntryError.TOO_MANY_ATTEMPTS.correspondsTo(errorCode, "")) {
                    errorCallback.onError(AppEntryError.TOO_MANY_ATTEMPTS);
                } else {
                    errorCallback.onError(AppEntryError.PHONE_REGISTER_GENERIC_ERROR);
                }
                ignoreSelfUpdates = false;
            }
        });
    } else if (entryPoint == AppEntryState.EMAIL_SIGN_IN) {
        zMessagingApi.verifyPhoneNumber(countryCode + phone, phoneVerificationCode, KindOfVerification.VERIFY_ON_UPDATE, new ZMessagingApi.PhoneNumberVerificationListener() {

            @Override
            public void onVerified(KindOfVerification kindOfVerification) {
                appEntryStateCallback.tagAppEntryEvent(PhoneVerification.success(PhoneVerification.Context.POST_LOGIN));
                setState(AppEntryState.LOGGED_IN);
            }

            @Override
            public void onVerificationFailed(KindOfVerification kindOfVerification, int errorCode, String message, String label) {
                appEntryStateCallback.tagAppEntryEvent(PhoneVerification.error(PhoneVerification.Context.POST_LOGIN));
                if (AppEntryError.PHONE_INVALID_ADD_CODE.correspondsTo(errorCode, label)) {
                    errorCallback.onError(AppEntryError.PHONE_INVALID_ADD_CODE);
                } else {
                    errorCallback.onError(AppEntryError.PHONE_REGISTER_GENERIC_ERROR);
                }
            }
        });
    }
}
Also used : LoggedInEvent(com.waz.zclient.core.controllers.tracking.events.session.LoggedInEvent) ZMessagingApi(com.waz.api.ZMessagingApi) LoginListener(com.waz.api.LoginListener) KindOfVerification(com.waz.api.KindOfVerification) VerifiedPhoneEvent(com.waz.zclient.core.controllers.tracking.events.registration.VerifiedPhoneEvent) Self(com.waz.api.Self)

Aggregations

KindOfVerification (com.waz.api.KindOfVerification)1 LoginListener (com.waz.api.LoginListener)1 Self (com.waz.api.Self)1 ZMessagingApi (com.waz.api.ZMessagingApi)1 VerifiedPhoneEvent (com.waz.zclient.core.controllers.tracking.events.registration.VerifiedPhoneEvent)1 LoggedInEvent (com.waz.zclient.core.controllers.tracking.events.session.LoggedInEvent)1