Search in sources :

Example 6 with TaskFailureLogger

use of com.firebase.ui.auth.ui.TaskFailureLogger in project FirebaseUI-Android by firebase.

the class WelcomeBackPasswordPrompt method next.

private void next(final String email, final String password) {
    // Check for null or empty password
    if (TextUtils.isEmpty(password)) {
        mPasswordLayout.setError(getString(R.string.required_field));
        return;
    } else {
        mPasswordLayout.setError(null);
    }
    mActivityHelper.showLoadingDialog(R.string.progress_dialog_signing_in);
    final FirebaseAuth firebaseAuth = mActivityHelper.getFirebaseAuth();
    // Sign in with known email and the password provided
    firebaseAuth.signInWithEmailAndPassword(email, password).addOnFailureListener(new TaskFailureLogger(TAG, "Error signing in with email and password")).addOnSuccessListener(new OnSuccessListener<AuthResult>() {

        @Override
        public void onSuccess(AuthResult authResult) {
            AuthCredential authCredential = AuthCredentialHelper.getAuthCredential(mIdpResponse);
            // Otherwise, the user has an email account that we need to link to an idp.
            if (authCredential == null) {
                mActivityHelper.saveCredentialsOrFinish(mSaveSmartLock, authResult.getUser(), password, new IdpResponse(EmailAuthProvider.PROVIDER_ID, email));
            } else {
                authResult.getUser().linkWithCredential(authCredential).addOnFailureListener(new TaskFailureLogger(TAG, "Error signing in with credential " + authCredential.getProvider())).addOnSuccessListener(new OnSuccessListener<AuthResult>() {

                    @Override
                    public void onSuccess(AuthResult authResult) {
                        mActivityHelper.saveCredentialsOrFinish(mSaveSmartLock, authResult.getUser(), mIdpResponse);
                    }
                });
            }
        }
    }).addOnFailureListener(this, new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            mActivityHelper.dismissDialog();
            String error = e.getLocalizedMessage();
            mPasswordLayout.setError(error);
        }
    });
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger) AuthResult(com.google.firebase.auth.AuthResult) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) IdpResponse(com.firebase.ui.auth.IdpResponse)

Example 7 with TaskFailureLogger

use of com.firebase.ui.auth.ui.TaskFailureLogger in project FirebaseUI-Android by firebase.

the class RecoverPasswordActivity method next.

private void next(final String email) {
    mActivityHelper.getFirebaseAuth().sendPasswordResetEmail(email).addOnFailureListener(new TaskFailureLogger(TAG, "Error sending password reset email")).addOnSuccessListener(new OnSuccessListener<Void>() {

        @Override
        public void onSuccess(Void aVoid) {
            mActivityHelper.dismissDialog();
            RecoveryEmailSentDialog.show(email, getSupportFragmentManager());
        }
    }).addOnFailureListener(this, new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            mActivityHelper.dismissDialog();
            if (e instanceof FirebaseAuthInvalidUserException) {
                // No FirebaseUser exists with this email address, show error.
                mEmailEditText.setError(getString(R.string.error_email_does_not_exist));
            }
        }
    });
}
Also used : FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException)

Aggregations

TaskFailureLogger (com.firebase.ui.auth.ui.TaskFailureLogger)7 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)5 AuthCredential (com.google.firebase.auth.AuthCredential)4 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)3 AuthResult (com.google.firebase.auth.AuthResult)3 FirebaseUser (com.google.firebase.auth.FirebaseUser)3 IdpResponse (com.firebase.ui.auth.IdpResponse)2 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)2 NonNull (android.support.annotation.NonNull)1 CredentialSignInHandler (com.firebase.ui.auth.ui.idp.CredentialSignInHandler)1 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)1 FirebaseAuthInvalidCredentialsException (com.google.firebase.auth.FirebaseAuthInvalidCredentialsException)1 FirebaseAuthInvalidUserException (com.google.firebase.auth.FirebaseAuthInvalidUserException)1 FirebaseAuthWeakPasswordException (com.google.firebase.auth.FirebaseAuthWeakPasswordException)1 UserProfileChangeRequest (com.google.firebase.auth.UserProfileChangeRequest)1