Firebase Auth使用电子邮件和密码登录需要3.52分钟

2022-01-30 15:00:32 标签 javaandroidfirebasefirebase-authentication

我已经使用Firebase Auth差不多一个月了,直到上周,Firebase Auth工作得又快又干净,但突然间只用了3。52分钟。我检查了每一行代码,到处搜索,仍然不能找到原因。

Java代码:

public class Login extends AppCompatActivity {
    private static final String PREFS_NAME = "preferences";
    private static final String PREFS_UNAME = "Username";
    private static final String PREFS_PASSWORD = "Password";
    private final String DefaultUNameVal="";
    private final String DefaultPasswordVal="";
    
    private usermodel uMod;
    private String Code,Name, UserN,Password,Type;
    private FirebaseFirestore db = FirebaseFirestore.getInstance();
    private CollectionReference SchoolColl = db.collection("School");
    private EditText Username,Pass;
    private Button LoginSubmit;
    private FirebaseAuth FsAuth;
    private CheckBox RememberMeBox;
    private String TAG="Datacheck";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        FsAuth = FirebaseAuth.getInstance();
        Username=findViewById(R.id.Username);
        Pass=findViewById(R.id.LoginPass);
        LoginSubmit=findViewById(R.id.Login);
        RememberMeBox=findViewById(R.id.RememberMe);
        loadPrefenreces();
        
        LoginSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(RememberMeBox.isChecked()){
                    savePreferences();
                    loginuser();
                }else {
                    resetPrefernces();
                    loginuser();
                }
            }
        });
    }
    private void resetPrefernces() {
        SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        UserN = "";
        Password = "";
        editor.putString(PREFS_UNAME,UserN);
        editor.putString(PREFS_PASSWORD,Password);
        editor.commit();
    }
    private void loadPrefenreces() {
        SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
        UserN = settings.getString(PREFS_UNAME,DefaultUNameVal);
        Password = settings.getString(PREFS_PASSWORD,DefaultPasswordVal);
        Username.setText(UserN);
        Pass.setText(Password);
        if(UserN != "" && Password != "") {
            RememberMeBox.setChecked(true);
        }
    }
    private void savePreferences() {
        SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        UserN = Username.getText().toString();
        Password = Pass.getText().toString();
        Log.d(TAG,String.format("Saving UserID (%s) & Password (%s)",UserN,Password));
        editor.putString(PREFS_UNAME,UserN);
        editor.putString(PREFS_PASSWORD,Password);
        editor.commit();
    }
    private void loginuser() {
        ProgressDialog Pd=new ProgressDialog(this);
        Pd.setCancelable(false);
        Pd.setMessage("Loading Student Data ...");
        Pd.show();
        UserN = "stpradhan@sparsh.org";
        Password = "stpradhan";
//        if(TextUtils.isEmpty(UserN)){
//
//            Username.setError("Username Cannot be Empty");
//            Username.requestFocus();
//            if(Pd.isShowing()){
//                Pd.dismiss();
//            }
//
//        }else if(TextUtils.isEmpty(Password)){
//
//            Pass.setError("Password Cannot be Empty");
//            Pass.requestFocus();
//            if(Pd.isShowing()){
//                Pd.dismiss();
//            }
//
//        }else{
            getSchoolID(UserN);
            FsAuth.signInWithEmailAndPassword(UserN,Password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if(task.isSuccessful()){
                        Toast.makeText(Login.this, "User : "+UserN+" Login Successful.", Toast.LENGTH_SHORT).show();
                        Log.d(TAG,UserN+"<<===>>"+Password);
                        FirebaseUser user = FsAuth.getCurrentUser();
                        goToSchoolDashboard();
                        if(Pd.isShowing()){
                            Pd.dismiss();
                        }
                        finish();
                    }else{
                        Toast.makeText(Login.this, "User : "+UserN+" Login Unsuccessful.", Toast.LENGTH_SHORT).show();
                        if(Pd.isShowing()){
                            Pd.dismiss();
                        }
                    }
                }
            });
        }
//    }
    private void goToAdminDashboard() {
//        Intent myIntent = new Intent(getApplicationContext(), Dashboard.class);
//        startActivity(myIntent);
    }
    private void goToSchoolDashboard() {
        Intent myIntent = new Intent(this, TeacherDashboard.class);
        Log.d(TAG,Code+"-"+Name);
        myIntent.putExtra("S_ID",Code);
        myIntent.putExtra("Name",Name);
        startActivity(myIntent);
    }
    private void goToStudentDashboard() {
//        Intent myIntent = new Intent(getApplicationContext(), Dashboard.class);
//        startActivity(myIntent);
    }
    private String getType(FirebaseUser user){
        Log.d(TAG, user.getEmail());
        SchoolColl.document(user.getEmail()).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
            @Override
            public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                if (task.isSuccessful()) {
                        Type = task.getResult().get("type").toString();
                        Log.d(TAG,Type);
                }
            }
        });
        return Type;
    }
    private void getSchoolID(String user) {
        SchoolColl.whereEqualTo("id",user).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                if (task.isSuccessful()) {
                    for (QueryDocumentSnapshot document : task.getResult()) {
                        Code = document.get("schoolid").toString();
                        Name = document.get("name").toString();
                        Log.d("Datacheck","<<==>>"+Code);
                    }
                }
            }
        });
    }
}

请帮助解决这个问题。

这是日志的截图,它告诉准确的时间之前,初始化的方法和完成的方法

阅读全文

▼ 版权说明

相关文章也很精彩
推荐内容
更多标签
相关热门
全站排行
随便看看

错说 cuoshuo.com —— 程序员的报错记录

部分内容根据CC版权协议转载;网站内容仅供参考,生产环境使用务必查阅官方文档

辽ICP备19011660号-5

×

扫码关注公众号:职场神器
发送: 1
获取永久解锁本站全部文章的验证码