java - “此操作很敏感,需要最近的身份验证。”编辑用户密码和电子邮件Android时出错-Java

标签 java android firebase firebase-realtime-database firebase-authentication

尝试从auth更改用户电子邮件和密码时收到此错误。
错误:http://prntscr.com/on0qg7(Imgur网站在我们的国家被禁止,所以我无法使用。)

该代码有时可行,有时会给出错误。不稳定

预先感谢您的帮助。

编辑方法代码:

public void editAlert() {
        LayoutInflater layoutInflater = LayoutInflater.from(ProfilePage.this);

        View design = layoutInflater.inflate(R.layout.edit_profile, null);
        final FirebaseUser userAuth = FirebaseAuth.getInstance().getCurrentUser();

        final EditText editTextUserName = design.findViewById(R.id.username_editTextProfileEdit);

        final EditText editTextRealName = design.findViewById(R.id.realName_editTextProfileEdit);

        final EditText editTextSurname = design.findViewById(R.id.surname_editTextProfileEdit);

        final EditText editTextEmail = design.findViewById(R.id.email_editTextProfileEdit);

        final EditText editTextPassword = design.findViewById(R.id.password_editTextProfileEdit);

        AlertDialog.Builder alertDialoga = new AlertDialog.Builder(ProfilePage.this);
        alertDialoga.setTitle("Edit Profile");
        alertDialoga.setView(design);
        alertDialoga.setPositiveButton("Finish", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                String username = editTextUserName.getText().toString().trim();
                String realName = editTextRealName.getText().toString().trim();
                String surname = editTextSurname.getText().toString().trim();
                final String email = editTextEmail.getText().toString().trim();
                final String password = editTextPassword.getText().toString().trim();
                String admin = "false";
                String url = "test_url";

                String key = FirebaseAuth.getInstance().getCurrentUser().getUid();

                Users user = new Users(key,username,realName,surname,email,password,url,admin);

                HashMap<String,Object> data = new HashMap<>();

                data.put("user_email", email);
                data.put("user_name", realName);
                data.put("user_password", password);
                data.put("user_surname", surname);
                data.put("user_username", username);

                myRef.child(key).updateChildren(data);

                // E Mail Update
                userAuth.updateEmail(email).addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(Task<Void> task) {
                        Toast.makeText(ProfilePage.this, "Mail değiştirildi", Toast.LENGTH_SHORT).show();
                    }
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(Exception e) {
                        Toast.makeText(ProfilePage.this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
                    }
                });

                // Password Update
                userAuth.updatePassword(password).addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(Task<Void> task) {
                        Toast.makeText(ProfilePage.this, "Şifre değiştirildi", Toast.LENGTH_SHORT).show();
                    }
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(Exception e) {
                        Toast.makeText(ProfilePage.this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
                    }
                });
            }
        });

        alertDialoga.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });

        alertDialoga.show();
    }


从上面的代码部分,auth的替换代码为:

我的电子邮件和密码更改部分:

 // E Mail Update
                userAuth.updateEmail(email).addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(Task<Void> task) {
                        Toast.makeText(ProfilePage.this, "Mail değiştirildi", Toast.LENGTH_SHORT).show();
                    }
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(Exception e) {
                        Toast.makeText(ProfilePage.this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
                    }
                });

                // Password Update
                userAuth.updatePassword(password).addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(Task<Void> task) {
                        Toast.makeText(ProfilePage.this, "Şifre değiştirildi", Toast.LENGTH_SHORT).show();
                    }
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(Exception e) {
                        Toast.makeText(ProfilePage.this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
                    }
                });

最佳答案

如错误所言,用户需要最近登录才能执行此操作。要删除此用户,您必须重新验证该用户。有关如何执行此操作的更多信息,请参见here

关于java - “此操作很敏感,需要最近的身份验证。”编辑用户密码和电子邮件Android时出错-Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57325759/

相关文章:

java - android:listSelector 在notifyDataSetChanged()之后,颜色消失

java - 如何将一种方法与另一种方法组合使用

java - 多个安卓屏幕的图像大小

firebase - 如何从Firestore检索List <Map <String,dynamic >>?

java - 使用 Spring Data Redis 在 Redis 中执行 SCAN 操作时出现 ERR 语法错误

java - MapBox 无法将 JSONObject 转换为 JSONArray

android - 适用于Android设备的视频库

android - 如何从我的 Android 设备访问我的本地主机?

ios - 使用 Swift 的 Firebase

ios - Firebase 上传文件在文件名中获取可选字符串