英文:
Firestore Database Registration Failed Permission Denied But Actually Successfully Registers
问题
以下是翻译好的部分:
private void showREGISTERnew() {
final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle("注册");
dialog.setMessage("请使用电子邮件进行注册。");
LayoutInflater inflater = LayoutInflater.from(this);
View layout_login = inflater.inflate(R.layout.layout_login, null);
final MaterialEditText editEmail = layout_login.findViewById(R.id.editEmail);
final MaterialEditText editPassword = layout_login.findViewById(R.id.editPassword);
dialog.setView(layout_login);
// 设置按钮
dialog.setPositiveButton("注册", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
// 验证检查
if(TextUtils.isEmpty(editEmail.getText().toString())){
Snackbar.make(rootLayout, "请输入电子邮件地址", Snackbar.LENGTH_SHORT)
.show();
return;
}
if(TextUtils.isEmpty(editPassword.getText().toString())){
Snackbar.make(rootLayout, "请输入密码", Snackbar.LENGTH_SHORT)
.show();
return;
}
if(editPassword.getText().toString().length() < 6){
Snackbar.make(rootLayout, "密码太短。", Snackbar.LENGTH_SHORT)
.show();
return;
}
// 注册新用户
auth.createUserWithEmailAndPassword(editEmail.getText().toString(), editPassword.getText().toString())
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
// 将用户保存到数据库
User user = new User();
user.setEmail(editEmail.getText().toString());
// 设置用户电话
// 设置用户姓名
user.setPassword(editPassword.getText().toString());
// 使用电子邮件作为键
users.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(user)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Snackbar.make(rootLayout, "您已成功注册。", Snackbar.LENGTH_SHORT)
.show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Snackbar.make(rootLayout, "注册失败。" + e.getMessage(), Snackbar.LENGTH_SHORT)
.show();
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Snackbar.make(rootLayout, "注册失败。" + e.getMessage(), Snackbar.LENGTH_SHORT)
.show();
}
});
}
});
}
英文:
So I am having a rather ambiguous issue with my database. Everything was working fine and anytime I would register or somebody would register on my app, it would make the messasge "Registration Successful!" pop up.
I have been updating my code daily and working on changing things in the app and around the database. Today while registering a test user, I got this message -
It claims that registration failed, but the account was successfully registered. And I have tested this with 3 more accounts. Same message - registration, however, is actually successful and the user can log in with his details.
I have not coded this exception. I have coded exceptions such as password too short, registration failed, no internet, etc, but never have I created a Permission check. I think the Permission Denied comes from the +e.getMessage()? Could I have changed something inside the firestorm database rules?
This is my code:
private void showREGISTERnew() {
final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle("REGISTER");
dialog.setMessage("Please use email to register.");
LayoutInflater inflater = LayoutInflater.from(this);
View layout_login = inflater.inflate(R.layout.layout_login, null);
final MaterialEditText editEmail = layout_login.findViewById(R.id.editEmail);
final MaterialEditText editPassword = layout_login.findViewById(R.id.editPassword);
dialog.setView(layout_login);
//set btton
dialog.setPositiveButton("REGISTER", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//check validation
if(TextUtils.isEmpty(editEmail.getText().toString())){
Snackbar.make(rootLayout, "Please enter email address", Snackbar.LENGTH_SHORT)
.show();
return;
}
if(TextUtils.isEmpty(editPassword.getText().toString())){
Snackbar.make(rootLayout, "Please enter your password", Snackbar.LENGTH_SHORT)
.show();
return;
}
if(editPassword.getText().toString().length() < 6){
Snackbar.make(rootLayout, "Password too short.", Snackbar.LENGTH_SHORT)
.show();
return;
}
//reg new user
auth.createUserWithEmailAndPassword(editEmail.getText().toString(), editPassword.getText().toString())
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
//save user to db
User user = new User();
user.setEmail(editEmail.getText().toString());
//user setphone
//user setname
user.setPassword(editPassword.getText().toString());
//use email to key
users.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(user)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Snackbar.make(rootLayout, "You have registered successfully.", Snackbar.LENGTH_SHORT)
.show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Snackbar.make(rootLayout, "Registration failed."+e.getMessage(), Snackbar.LENGTH_SHORT)
.show();
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Snackbar.make(rootLayout, "Registration failed."+e.getMessage(), Snackbar.LENGTH_SHORT)
.show();
}
});
}
});
答案1
得分: 0
我实际上实现了两个数据库。一个将保存用户基础,另一个将保存价格和位置数据。
然而,我忘记了在一段时间后,读写权限会自动设置为 false。
在几周前收到通知时,我在主数据库上将读写权限改回为 true,但忘记了第二个数据库。
我检查了第二个数据库,权限被设置为 false,导致我注册失败,权限被拒绝,尽管我可以注册。
将它们改回 true 后,应用程序运行正常。
英文:
I actually implemented two databases. One that will hold the userbase ad one that will hold price and location data.
However, I forgot that after a certain period of time, read and write permissions will be automatically set to false.
When I got the notification weeks ago, I changed back the read and write permissions to true on the main database, but forgot about the second one.
I checked the second one and the permissions were set to false, thus giving me registration failed, permission denied even though I could register.
After changing them back to true, application works flawlessly.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论