Search in sources :

Example 1 with LoginListener

use of com.waz.api.LoginListener in project wire-android by wireapp.

the class AppEntryStore method signInWithEmail.

@Override
public void signInWithEmail(String email, String password, final ErrorCallback errorCallback) {
    setAndStoreEmail(email);
    this.password = password;
    ignoreSelfUpdates = true;
    zMessagingApi.login(CredentialsFactory.emailCredentials(email, password), new LoginListener() {

        @Override
        public void onSuccess(Self self) {
            bindSelf(self);
            setState(AppEntryState.EMAIL_SIGNED_IN);
            ignoreSelfUpdates = false;
            appEntryStateCallback.tagAppEntryEvent(new LoggedInEvent(false));
        }

        @Override
        public void onFailed(int errorCode, String message, String label) {
            if (AppEntryError.EMAIL_INVALID_REQUEST.correspondsTo(errorCode, label)) {
                errorCallback.onError(AppEntryError.EMAIL_INVALID_REQUEST);
            } else if (AppEntryError.SERVER_CONNECTIVITY_ERROR.correspondsTo(errorCode, "")) {
                errorCallback.onError(AppEntryError.SERVER_CONNECTIVITY_ERROR);
            } else if (AppEntryError.EMAIL_INVALID_LOGIN_CREDENTIALS.correspondsTo(errorCode, "")) {
                errorCallback.onError(AppEntryError.EMAIL_INVALID_LOGIN_CREDENTIALS);
            } else if (AppEntryError.TOO_MANY_ATTEMPTS.correspondsTo(errorCode, "")) {
                errorCallback.onError(AppEntryError.TOO_MANY_ATTEMPTS);
            } else if (AppEntryError.NO_INTERNET.correspondsTo(errorCode, label)) {
                errorCallback.onError(AppEntryError.NO_INTERNET);
            } else {
                errorCallback.onError(AppEntryError.EMAIL_GENERIC_ERROR);
            }
            ignoreSelfUpdates = false;
        }
    });
}
Also used : LoggedInEvent(com.waz.zclient.core.controllers.tracking.events.session.LoggedInEvent) LoginListener(com.waz.api.LoginListener) Self(com.waz.api.Self)

Example 2 with LoginListener

use of com.waz.api.LoginListener in project wire-android by wireapp.

the class OTREmailSignInFragment method signIn.

private void signIn() {
    getContainer().enableProgress(true);
    KeyboardUtils.hideKeyboard(getActivity());
    Credentials credentials = CredentialsFactory.emailCredentials(guidedEditTextEmail.getText(), guidedEditTextPassword.getText());
    getStoreFactory().getZMessagingApiStore().getApi().login(credentials, new LoginListener() {

        @Override
        public void onSuccess(Self user) {
            if (getContainer() == null) {
                return;
            }
            getContainer().startMain();
        }

        @Override
        public void onFailed(int code, String message, String label) {
            if (getContainer() == null) {
                return;
            }
            getContainer().enableProgress(false);
            AppEntryUtil.showErrorDialog(OTREmailSignInFragment.this.getActivity(), AppEntryError.EMAIL_REGISTER_GENERIC_ERROR, new AppEntryUtil.ErrorDialogCallback() {

                @Override
                public void onOk() {
                    KeyboardUtils.showKeyboard(getActivity());
                }
            });
        }
    });
}
Also used : LoginListener(com.waz.api.LoginListener) Self(com.waz.api.Self) Credentials(com.waz.api.Credentials)

Example 3 with LoginListener

use of com.waz.api.LoginListener 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

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