在创建用户Firebase Android之前检查电子邮件是否存在
所以我遇到的问题是我有一个注册表,用户可以在其中输入信息(其中还包含电子邮件).
So the issue I am having is I have a registration form in which users enter information (which also contains an email).
我有一个名为onp的方法
I have an onClick method called
public void onCreateAccount(View view);
当用户单击注册"时,它将验证表单上的字段.
when the user clicks "Register", it validates the fields on the form.
public class Foo extends AppCompatActivity {
//OTHER PRIVATE MEMBERS
private EditText etEmail;
boolean isValid;
private DatabaseReference databaseUser = FirebaseDatabase.getInstance().getReference().child("User");
@Override
protected void onCreate(Bundle savedInstanceState) {
//DOES SOME INITIALIZATION
}
public void onCreateAccount(View view){
String email = etEmail.getText().toString().trim();
if(validateEmail(email)){
String id = databaseUser.push().getKey();
User user = new User(id, email);
databaseUser.child(user.getId()).setValue(user);
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
intent.putExtra("isCreateAccount", true);
startActivityForResult (intent,0);
}
}
private boolean validateEmail(String email) {
isValid = true;
databaseUser.orderByChild("email").equalTo(emailUserEntered).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists())
isValid=false;
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
在将记录插入Firebase数据库之前,我想先检查电子邮件是否已经存在,然后再插入.因此,输入电子邮件= a@mail.com的人将不允许这样做.
Before inserting the record into the firebase database, I want to first check if the email already exists prior to inserting. So a person typing email = a@mail.com would not allow so.
此方法仅用于身份验证:firebase.auth().fetchProvidersForEmail("emailaddress@gmail.com")
This method is for auth only: firebase.auth().fetchProvidersForEmail("emailaddress@gmail.com")