問題

我正在使用Andrid Studio和Firebase註冊使用者的電子郵件,名稱,地址和密碼..當我點選將使用者註冊到資料庫時,它成功地註冊並轉到任務不成功的其他宣告...

我在firebase上手動添加了登入電子郵件,但Scenrio與使用者沒有登入...

我很困惑,不知道我做錯了什麼...我正在關注教程,我正在關注的教程也做了同樣的事情...

這是M訊號...

 public class AdminSignUp extends AppCompatActivity {

TextView textLogin;
Button btnSignup;
EditText AdminId,EmailAdmin,AdminName,AdminPassword,PhoneNO,Address;
private ProgressDialog progressDialog;
private FirebaseAuth mAuth;
DatabaseReference databaseAdminRegistration;

@Override
public void onBackPressed() {
    super.onBackPressed();
    startActivity(new Intent(AdminSignUp.this,MainActivity.class));
}

@Override
protected void onRestart() {
    super.onRestart();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_admin_sign_up);

    progressDialog = new ProgressDialog(this);
    mAuth = FirebaseAuth.getInstance();

    textLogin=findViewById(R.id.txtLogin);
    btnSignup=findViewById(R.id.ButtonAdminSignUp);

    AdminId=findViewById(R.id.edtAdminId);
    EmailAdmin=findViewById(R.id.admiemail);
    AdminName=findViewById(R.id.edtAdminName);
    AdminPassword=findViewById(R.id.edtAdminPassword);
    PhoneNO=findViewById(R.id.edtAdminPhNo);
    Address=findViewById(R.id.edtAdminAddress);



    btnSignup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FunRegisterAdmin();
           // Toast.makeText(AdminSignUp.this, "IN PROGRESS", Toast.LENGTH_SHORT).show();
        }
    });

    textLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(AdminSignUp.this,AdminLogin.class));
        }
    });
}

private void FunRegisterAdmin()
{
    String email = EmailAdmin.getText().toString().trim().toLowerCase();
    String password = AdminPassword.getText().toString().trim();
    final String name= AdminName.getText().toString().trim();
    if (TextUtils.isEmpty(email)|| !android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()){
        EmailAdmin.setError("Please Enter a Valid Email");
        return;
    }
    if (TextUtils.isEmpty(password)|| password.length() < 4 || password.length() > 10){
        AdminPassword.setError("Enter The Password");
        return;
    }
    if(TextUtils.isEmpty(name))
    {
        Toast.makeText(this,"Please Enter NAme",Toast.LENGTH_LONG).show();
        return;
    }
    progressDialog.setMessage("Registering User...");
    progressDialog.show();
    mAuth.createUserWithEmailAndPassword(email,password)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()){
                        String id = FirebaseAuth.getInstance().getCurrentUser().getUid();
                        DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("Employee");
                        reference.child(id).child("Name").setValue(name);
                        Toast.makeText(AdminSignUp.this, "Registered Successfully", Toast.LENGTH_LONG).show();
                    }else {

                        Toast.makeText(AdminSignUp.this, "Not Registered...",Toast.LENGTH_LONG).show();
                    }
                    progressDialog.dismiss();
                }
            });
}
 

}

這是我的登入

 public class AdminLogin extends AppCompatActivity {

TextView SignUPText;
EditText AdminEmail,AdminPassword;
Button AdminLoginBtn;

FirebaseAuth mAuth;
ProgressDialog progressDialog;

@Override
public void onBackPressed() {
    super.onBackPressed();
    startActivity(new Intent(AdminLogin.this,MainActivity.class));
}

@Override
protected void onRestart() {
    super.onRestart();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_admin_login);

    progressDialog = new ProgressDialog(this);
    mAuth = FirebaseAuth.getInstance();
    SignUPText= findViewById(R.id.txtSignUp);
    AdminEmail= findViewById(R.id.edtEmailAdminLogin);
    AdminPassword= findViewById(R.id.edtPasswordAdminLogin);
    AdminLoginBtn=findViewById(R.id.ButtonAdminLogin);


    SignUPText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(AdminLogin.this,AdminSignUp.class));
        }
    });
    AdminLoginBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AdminLoginFunc();
            //Toast.makeText(AdminLogin.this, "ADMIN LOGIN IN PROGRESS", Toast.LENGTH_SHORT).show();
        }
    });


}

private void AdminLoginFunc() {

    String email = AdminEmail.getText().toString().trim().toLowerCase();
    String password = AdminPassword.getText().toString().trim();
    if (TextUtils.isEmpty(email)|| !android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()){
        AdminEmail.setError("enter a valid email address");
        return;
    }
    if ((TextUtils.isEmpty(password)|| password.length() < 4 || password.length() > 10)){
        AdminPassword.setError("enter a correct Password");
        return;
    }
    progressDialog.setMessage("Please Wait...");
    progressDialog.show();
    mAuth.signInWithEmailAndPassword(email,password)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {

                        Toast.makeText(AdminLogin.this, "Login Successfully", Toast.LENGTH_SHORT).show();
                    }else {
                        Toast.makeText(AdminLogin.this, "Unable to Login.",Toast.LENGTH_SHORT).show();
                        //updateUI(null);
                    }
                    progressDialog.dismiss();
                }
            });

}
 

}

Manually added users for signin but not working for signin

  最佳答案

  相同標籤的其他問題

androidfirebasefirebase-authentication