在创建用户Firebase Android之前检查电子邮件是否存在 [英] check if an email exists before creating a user firebase android

查看:77
本文介绍了在创建用户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")

这篇关于在创建用户Firebase Android之前检查电子邮件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆