Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private TextInputLayout mName;
- private TextInputLayout mEmail;
- private TextInputLayout mPwd;
- private Button mSubmit;
- String username, email,password;
- private FirebaseAuth mAuth;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_reg);
- mAuth = FirebaseAuth.getInstance();
- mName=(TextInputLayout)findViewById(R.id.pName);
- mEmail=(TextInputLayout)findViewById(R.id.pEmail);
- mPwd=(TextInputLayout)findViewById(R.id.pPassword);
- mSubmit=(Button) findViewById(R.id.regStart);
- mSubmit.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- username= mName.getEditText().getText().toString();
- email= mEmail.getEditText().getText().toString();
- password= mPwd.getEditText().getText().toString();
- Toast.makeText(getApplicationContext(), username+" "+email+" "+password,
- Toast.LENGTH_SHORT).show();
- register_user(username,email,password);
- }
- });
- }
- private void register_user(String username, String email, String password)
- {
- mAuth.createUserWithEmailAndPassword(email, password)
- .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
- @Override
- public void onComplete(@NonNull Task<AuthResult> task) {
- if (task.isSuccessful()) {
- // Sign in success, update UI with the signed-in user's information
- Log.d("yaaayy", "createUserWithEmail:success");
- Intent i= new Intent(getApplicationContext(),MainActivity.class);
- startActivity(i);
- finish();
- } else {
- // If sign in fails, display a message to the user.
- Log.w("oops", "createUserWithEmail:failure", task.getException());
- Toast.makeText(getApplicationContext(), "Authentication failed.",
- Toast.LENGTH_SHORT).show();
- }
- // ...
- }
- });
- } }
Add Comment
Please, Sign In to add comment