首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >你好,Firebase专家最近我用实时数据库实现了防火墙的身份验证,现在我想上传用户的个人资料图像又如何呢?

问你好,Firebase专家最近我用实时数据库实现了防火墙的身份验证,现在我想上传用户的个人资料图像又如何呢?
EN

Stack Overflow用户
提问于 2022-02-26 18:38:01
回答 1查看 23关注 0票数 -1

注册活动屏幕截图

我实现了从图片库中提取图像的其余部分,并将其设置为图像视图!现在我想要的功能是上传用户个人资料图像和注册细节,也请注意,是否需要在用户模型类中增加一个变量?以及我必须在后面添加哪些参数、构造函数、getter或setter。下面也给出了用户模型类的代码,谢谢:)

//这是注册用户的函数:

代码语言:javascript
复制
        private void register_doctor () {
            String dname = et_name.getText().toString().trim();
            String demail = et_email.getText().toString().trim();
            String dpass = et_pass.getText().toString().trim();
            String dcpass = et_cnf_pass.getText().toString().trim();
            String dcontact = et_contact.getText().toString().trim();
            String dcity = et_city.getText().toString().trim();
            String dage = et_age.getText().toString().trim();


            if (dname.isEmpty()) {
                et_name.setError("Full Name is Required");
                et_name.requestFocus();
                return;
            }
            if (demail.isEmpty()) {
                et_email.setError("Email is Required");
                et_email.requestFocus();
                return;
            }

            if (dpass.isEmpty()) {
                et_pass.setError("Password is Required");
                et_pass.requestFocus();
                return;
            }

            if (dpass.length() < 6) {
                et_pass.setError("Password Length Should be greater than 6 characters");
                et_pass.requestFocus();
                return;
            }

            if (dcpass.isEmpty()) {
                et_cnf_pass.setError("Password is Required");
                et_cnf_pass.requestFocus();
                return;
            }
            if (!dcpass.equals(dpass)) {
                et_cnf_pass.setError("Password Does not Matched!");
                et_cnf_pass.requestFocus();
                return;
            }

            if (dcontact.isEmpty()) {
                et_contact.setError("Contact is Required");
                et_contact.requestFocus();
                return;
            }

            if (dcity.isEmpty()) {
                et_city.setError("City is Required");
                et_city.requestFocus();
                return;
            }

            if (dage.isEmpty()) {
                et_age.setError("Age is Required");
                et_age.requestFocus();
                return;
            }

            progressBar.setVisibility(View.VISIBLE);

            mAuth.createUserWithEmailAndPassword(demail, dpass)
                    .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {
                                User user = new User(dname, demail, dcontact, dcity, dage);
                                
                                FirebaseDatabase.getInstance().getReference("doctors")
                                        .child("Doctors_Registration")
//                                        .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
                                        .child(demail.replace(".", ","))
                                        .setValue(user)
                                        .addOnCompleteListener(new OnCompleteListener<Void>() {
                                            @Override
                                            public void onComplete(@NonNull Task<Void> task) {

                                                if (task.isSuccessful()) {
                                                    Toast.makeText(signup.this, "Doctor Registered", Toast.LENGTH_SHORT).show();
                                                    progressBar.setVisibility(View.GONE);
                                                } else {
                                                    Toast.makeText(signup.this, "Failed to Registered, Try Again!" + task.getException(), Toast.LENGTH_LONG).show();
                                                    progressBar.setVisibility(View.GONE);
                                                }
                                            }
                                        });
                            } else {
                                Toast.makeText(signup.this, "Failed to Registered, Try Again!", Toast.LENGTH_LONG).show();
                                progressBar.setVisibility(View.GONE);
                            }
                        }
                    });

        }




// here is my user-model class code
package com.example.iotbaseddriverhealthmonitoring;

public class User {
    public String name, email, password, contact, city, age;
    public  User(){
    }
    public User(String name, String email, String contact, String city, String age){
        this.name = name;
        this.email = email;
        this.contact = contact;
        this.city = city;
        this.age = age;
    }
}
EN

回答 1

Stack Overflow用户

发布于 2022-02-26 19:13:59

我认为您的意思是setPhotoUri() (然后更新用户):

来自[消]火基文件

代码语言:javascript
复制
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
    .setDisplayName("Jane Q. User")
    .setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.jpg"))
    .build();

user.updateProfile(profileUpdates)
    .addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                Log.d(TAG, "User profile updated.");
            }
        }
    });

还可以将图像存储在Firebase存储中,然后将该下载链接保存在Firebase数据库中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71279342

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档