Created
April 3, 2018 12:47
-
-
Save PollyGlot/5cf3cd8371dedc2b2565fa339493d7c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void userLogin(String email, String password) { | |
showProgressDialog(); | |
mFirebaseAuth.signInWithEmailAndPassword(email, password) | |
.addOnCompleteListener(new OnCompleteListener<AuthResult>() { | |
@Override | |
public void onComplete(@NonNull Task<AuthResult> task) { | |
Log.d(TAG, "signInWithEmail:onComplete:" + task.isSuccessful()); | |
if (!task.isSuccessful()) { | |
Log.w(TAG, "signInWithEmail", task.getException()); | |
Toast.makeText(LoginActivity.this, "Произошла ошибка. Введены неверные данные или такого пользователя не существует", | |
Toast.LENGTH_LONG).show(); | |
} else { | |
checkIfUserApproved(); | |
// Intent intent = new Intent(getApplicationContext(), MainActivity.class); | |
// startActivity(intent); | |
// finish(); | |
} | |
hideProgressDialog(); | |
} | |
}); | |
} | |
private void checkIfUserApproved() { | |
final String userID = currentCourier.getUid(); | |
mDatabaseReference.child("couriers").child(userID).child("verified") | |
.addValueEventListener(new ValueEventListener() { | |
@Override | |
public void onDataChange(DataSnapshot dataSnapshot) { | |
String userVerified = dataSnapshot.getValue(String.class); | |
// TODO: Debug | |
Toast.makeText(LoginActivity.this, "VALUE: " + userVerified, | |
Toast.LENGTH_SHORT).show(); | |
if (Objects.equals(userVerified, VERIFIED_TRUE)) { | |
mPreferences.setUserMode(COURIER_VERIFICATION, VERIFIED_FALSE); | |
Intent i = new Intent(LoginActivity.this, MainActivity.class); | |
startActivity(i); | |
finish(); | |
} else { | |
mPreferences.setUserMode(COURIER_VERIFICATION, VERIFIED_FALSE); | |
startActivity(new Intent(LoginActivity.this, RequestSentActivity.class)); | |
finish(); | |
} | |
} | |
@Override | |
public void onCancelled(DatabaseError databaseError) { | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment