我正在尝试使用两个Firebase身份验证(客户端,客户),我需要对数据库查询使用Firebase身份验证

时间:2019-02-02 23:16:01

标签: java android firebase firebase-authentication

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);
                        }
            }
        });
    }

0 个答案:

没有答案