private void userSign() {
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
String message = Objects.requireNonNull(task.getException()).getMessage();
Toast.makeText(Start.this, "Error occured: " + message, Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
else
{
Query DatabaseQuery = databaseReference.child("Users").child("Customer").orderByChild("email").equalTo(CLemail.getText().toString().trim());
DatabaseQuery.addListenerForSingleValueEvent(new ValueEventListener()
{
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
{
if (dataSnapshot.exists())
{
for (DataSnapshot user : dataSnapshot.getChildren())
{
User usersBean = user.getValue(User.class);
if (!usersBean.password.equals(CLpassword.getText().toString().trim()))
{
CLpassword.setError("Password is Wrong!");
CLpassword.requestFocus();
}
else
{
Intent intent = new Intent(Start.this, Home.class);
startActivity(intent);
dialog.setMessage("Loging please wait");
dialog.setIndeterminate(true);
dialog.show();
}
}
}
else {
Toast.makeText(Start.this, "User not found", Toast.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
{
Toast.makeText(Start.this, "Email not found", Toast.LENGTH_LONG).show();
}
});
dialog.dismiss();
Intent intent = new Intent(Start.this, Home.class);
startActivity(intent);
}
}
});
}