我要检查用户已经存在或不使用用户手机号码
这是我的代码
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
ref.child("users").child(mobile).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
// use "username" already exists
Toast.makeText(getApplicationContext(), "already account there",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "account not exist",
Toast.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
// FirebaseUser userid = FirebaseAuth.getInstance().getCurrentUser();
// String uid = userid.getUid();
// mDatabase = mDatabase.child("Users");
// Map<String, String> userData = new HashMap<String, String>();
// userData.put("Number", mobile);
// userData.put("Password", "mypassword");
// userData.put("Confirmed", "not confiremed");
// userData.put("Email", "jaisonkerala1@gmail.com");
// mDatabase = mDatabase.child(mobile).child(uid);
// mDatabase.setValue(userData);
Toast.makeText(getApplicationContext(), "login success",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "login faild",
Toast.LENGTH_LONG).show();
// Sign in failed, display a message and update the UI
// Log.w(TAG, "signInWithCredential:failure", task.getException());
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
// The verification code entered was invalid
Toast.makeText(getApplicationContext(), "OTP was wrong",
Toast.LENGTH_LONG).show();
}
}
}
});
数据库截图
我想通过将数据库中的“数字”节点与用户列表或数据进行比较来检查用户是否存在。现在,如果我使用相同的手机号码,