【发布时间】:2017-08-22 07:21:50
【问题描述】:
目前我使用电子邮件身份验证将新用户注册到数据库,但现在我遇到了验证用户名和电子邮件的问题,这会阻止用户向数据库输入相同的用户名和密码,所以你们能帮我看看是否检索数据语句有错误?
auth = FirebaseAuth.getInstance();
db = FirebaseDatabase.getInstance();
ref = db.getReference();
FirebaseUser user = auth.getCurrentUser();
uid = user.getUid();//getuser id
run = (EditText) findViewById(R.id.Run);
rpw = (EditText) findViewById(R.id.Rpw);
rage = (EditText) findViewById(R.id.Rage);
//rbm = (RadioButton) findViewById(R.id.rbmale);
//rbfm = (RadioButton) findViewById(R.id.rbfemale);
re = (EditText) findViewById(R.id.Re);
rpn = (EditText) findViewById(R.id.Rpn);
ra = (EditText) findViewById(R.id.Ra);
rpc = (EditText) findViewById(R.id.Rpc);
//rbstd = (RadioButton) findViewById(R.id.rbstd);
//rbtt= (RadioButton) findViewById(R.id.rbtt);
final Button br = (Button) findViewById(R.id.Rbt);
br.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
usnm = run.getText().toString().trim();
pswd = rpw.getText().toString().trim();
email = re.getText().toString().trim();
ref.child(uid).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Object a = dataSnapshot.getValue();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
if (TextUtils.isEmpty(usnm)){
Toast.makeText(Register.this, "Username cannot be empty", Toast.LENGTH_SHORT).show();
return;
}else if (usnm.length()<8){
Toast.makeText(Register.this, "Username cannot less then 8 characters", Toast.LENGTH_SHORT).show();
return;
}else if (usnm.length()>8){
Toast.makeText(Register.this, "Username cannot greater then 8 characters", Toast.LENGTH_SHORT).show();
return;
}else if (ref.child(uid).child("username").equals(usnm)){
Toast.makeText(Register.this, "Username had been taken already! Please try another one.", Toast.LENGTH_SHORT).show();
return;
}else if (TextUtils.isEmpty(pswd)){
Toast.makeText(Register.this, "Password cannot be empty", Toast.LENGTH_SHORT).show();
return;
}else if (pswd.length()<8){
Toast.makeText(Register.this, "Password cannot less then 8 characters", Toast.LENGTH_SHORT).show();
return;
}else if (pswd.length()>8){
Toast.makeText(Register.this, "Password cannot greater then 8 characters", Toast.LENGTH_SHORT).show();
return;
}else if (TextUtils.isEmpty(email)){
Toast.makeText(Register.this, "Email cannot be empty", Toast.LENGTH_SHORT).show();
return;
}else if (ref.child(uid).child("email").equals(email)){
Toast.makeText(Register.this, "Email had been taken already! Please try another one.", Toast.LENGTH_SHORT).show();
return;
}
register(usnm, pswd, email);
}//end of onclick
});
【问题讨论】:
-
你想让那个使用已经退出吗?
-
为什么不检查它的数据库程序或网络服务
-
是的...使用按钮单击时检查数据库是否有相同的用户邮件和电子邮件。但它不起作用....
标签: java android firebase firebase-realtime-database