[英]FirebaseAuth is not creating user
When I try to register it says registration failed. 当我尝试注册时,它说注册失败。 this is a updated version of the code after some tweaks.
经过一些调整后,这是代码的更新版本。 I have tried to analyze the code with no luck.
我试图分析代码没有运气。
package com.brandshopping.brandshopping; 打包com.brandshopping.brandshopping;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class RegisterActivity extends AppCompatActivity {
private EditText Input_email;
private EditText Input_password;
private EditText Input_confirm_password;
private EditText Input_first_name;
private EditText Input_last_name;
private EditText Input_phonenumber;
private Button SignUpBtn;
private TextView I_Have_An_Account_Btn;
private ProgressDialog LoadingBar;
private FirebaseAuth firebaseAuth;
public class RegisterActivity extends AppCompatActivity {
private EditText Input_email;
private EditText Input_password;
private EditText Input_confirm_password;
private EditText Input_first_name;
private EditText Input_last_name;
private EditText Input_phonenumber;
private Button SignUpBtn;
private TextView I_Have_An_Account_Btn;
private ProgressDialog LoadingBar;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
LoadInGui(); //Loads in GUI
I_Have_An_Account_Btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(RegisterActivity.this, MainActivity.class));
}
});
SignUpBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final String email = Input_email.getText().toString().trim();
final String password = Input_password.getText().toString().trim();
validateCredentialls();
doNormalLogin(email, password);
}
});
}
private void validateCredentialls(){
if(TextUtils.isEmpty(Input_first_name.toString())){
Toast.makeText(RegisterActivity.this, "Please enter you're first name", Toast.LENGTH_SHORT).show();
}
else if(TextUtils.isEmpty(Input_last_name.toString())){
Toast.makeText(RegisterActivity.this, "Please enter you're last name", Toast.LENGTH_SHORT).show();
}
else if(TextUtils.isEmpty(Input_email.toString())){
Toast.makeText(RegisterActivity.this, "Please enter you're e-mail", Toast.LENGTH_SHORT).show();
}
else if(TextUtils.isEmpty(Input_phonenumber.toString())){
Toast.makeText(RegisterActivity.this, "Please enter you're phone number", Toast.LENGTH_SHORT).show();
}
else if(TextUtils.isEmpty(Input_password.toString())){
Toast.makeText(RegisterActivity.this, "Please enter you're password", Toast.LENGTH_SHORT).show();
}
else if(TextUtils.isEmpty(Input_confirm_password.toString())){
Toast.makeText(RegisterActivity.this, "Please write you're password again", Toast.LENGTH_SHORT).show();
}
}
private void doNormalLogin(String email, String password){
FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(RegisterActivity.this, "Registration successful", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(RegisterActivity.this, "Registration failed", Toast.LENGTH_SHORT).show();
Log.e("SignUpError :", task.getException().getMessage());
}
}
});
}
private void LoadInGui()
{
Input_email = (EditText) findViewById(R. id. input_email);
Input_password = (EditText) findViewById(R. id. input_password);
Input_confirm_password = (EditText) findViewById(R. id. input_confirm_password);
Input_first_name = (EditText) findViewById(R. id. Input_First_Name);
Input_last_name = (EditText) findViewById(R. id. Input_Last_Name);
Input_phonenumber = (EditText) findViewById(R. id. input_phonenumber);
SignUpBtn = (Button) findViewById(R. id. register_btn);
I_Have_An_Account_Btn = (TextView) findViewById(R. id. I_Have_An_Account_Btn);
}
} }
i expect the program to register me and it doesent. 我希望该程序可以注册我,并且确实可以。 Some help would be very appreciated, thanks in advance.
在此先感谢您的帮助。
You are calling RegisterUser()
method from onCreate()
, that's why this method is called before inserting any info. 您正在从
onCreate()
调用RegisterUser()
方法,这就是在插入任何信息之前调用此方法的原因。
So remove RegisterUser()
call from onCreate()
only call it when user clicks on SignUp button. 因此,仅当用户单击“注册”按钮时才从
onCreate()
删除RegisterUser()
调用。
Remove RegisterUser(); from onCreate
and try this -
private void doNormalLogin(String email, String password){
FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(RegisterActivity.this, "Registration successful", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(RegisterActivity.this, "Registration failed", Toast.LENGTH_SHORT).show();
}
}
});
}
Make sure you added this in your app gradle dependencies and the bottom plugin also -
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.firebase:firebase-auth:11.2.2'
implementation 'com.google.firebase:firebase-database:11.2.2'
}
apply plugin: 'com.google.gms.google-services'
And in your Project gradle -
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.