Skip to content

Commit

Permalink
#117: added email login message for wrong password
Browse files Browse the repository at this point in the history
  • Loading branch information
bugy committed Feb 4, 2018
1 parent a4bbcb3 commit 0c8b7da
Showing 1 changed file with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.google.common.base.Strings;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthException;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseAuthInvalidUserException;
import com.google.firebase.auth.FirebaseAuthUserCollisionException;
Expand Down Expand Up @@ -144,39 +145,52 @@ private class SignInListener implements OnCompleteListener<AuthResult> {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.i("SharingBodyRenderer", "logInButton.onComplete: authenticated successfully");
Log.i("EmailAuthUnit", "logInButton.onComplete: authenticated successfully");
errorLabel.setVisibility(View.GONE);

} else {
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
final Exception exception = task.getException();

Log.w("SharingBodyRenderer",
"logInButton.onComplete: couldn't authenticate the user",
exception);
Log.w("EmailAuthUnit",
"logInButton.onComplete: couldn't authenticate the user",
exception);

final int errorTextKey;
if ((exception instanceof FirebaseAuthInvalidUserException)
|| (exception instanceof FirebaseAuthInvalidCredentialsException)) {
errorTextKey = R.string.unit_auth_email_login_error_user_not_exists;
} else {
errorTextKey = R.string.unit_auth_email_login_error_default;
}
final int errorTextKey = getErrorTextKey(exception);

errorLabel.setText(errorTextKey);
errorLabel.setVisibility(View.VISIBLE);
}

refresh();
}

private int getErrorTextKey(Exception exception) {
if (exception instanceof FirebaseAuthException) {
FirebaseAuthException authException = (FirebaseAuthException) exception;
final String errorCode = authException.getErrorCode();

if ("ERROR_WRONG_PASSWORD".equals(errorCode)) {
return R.string.unit_auth_email_login_error_wrong_password;
} else if ("ERROR_INVALID_EMAIL".equals(errorCode)) {
return R.string.unit_auth_email_login_error_user_not_exists;
}
}

if (exception instanceof FirebaseAuthInvalidUserException) {
return R.string.unit_auth_email_login_error_user_not_exists;
}

return R.string.unit_auth_email_login_error_default;
}
}

private class RegistrationListener implements OnCompleteListener<AuthResult> {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.i("SharingBodyRenderer",
"registerButton.onComplete: email registered");
Log.i("EmailAuthUnit",
"registerButton.onComplete: email registered");

errorLabel.setVisibility(View.GONE);

Expand All @@ -186,9 +200,9 @@ public void onComplete(@NonNull Task<AuthResult> task) {
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
final Exception exception = task.getException();

Log.w("SharingBodyRenderer",
"registerButton.onComplete: couldn't register the email",
exception);
Log.w("EmailAuthUnit",
"registerButton.onComplete: couldn't register the email",
exception);

final int errorTextKey;
if (exception instanceof FirebaseAuthUserCollisionException) {
Expand Down

0 comments on commit 0c8b7da

Please sign in to comment.