0% found this document useful (0 votes)
38 views2 pages

SignupActivity Java

This document defines a Signup class that extends AppCompatActivity. It imports necessary Firebase and Android libraries. The class declares FirebaseAuth and FirebaseDatabase objects. It inflates a signup binding and sets an onClickListener for the register button. This listener gets email and password from EditTexts and calls FirebaseAuth's createUserWithEmailAndPassword method to create a new user. If successful, it sends an email verification and shows a snackbar success message. Otherwise, it shows an error snackbar.

Uploaded by

Odds World
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views2 pages

SignupActivity Java

This document defines a Signup class that extends AppCompatActivity. It imports necessary Firebase and Android libraries. The class declares FirebaseAuth and FirebaseDatabase objects. It inflates a signup binding and sets an onClickListener for the register button. This listener gets email and password from EditTexts and calls FirebaseAuth's createUserWithEmailAndPassword method to create a new user. If successful, it sends an email verification and shows a snackbar success message. Otherwise, it shows an error snackbar.

Uploaded by

Odds World
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

package whats.app.

myapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.FirebaseDatabase;

import java.util.Objects;

import whats.app.myapplication.databinding.ActivitySigninBinding;
import whats.app.myapplication.databinding.ActivitySignupBinding;

public class Signup extends AppCompatActivity {


ActivitySignupBinding binding;
private FirebaseAuth auth;
private FirebaseDatabase database;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding=ActivitySignupBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

auth=FirebaseAuth.getInstance();
database=FirebaseDatabase.getInstance();

binding.register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

String email=binding.signupEmail.getText().toString();
String password=binding.signupPassword.getText().toString();

if (TextUtils.isEmpty(email) && TextUtils.isEmpty(password)){


Snackbar.make(binding.signupLayout,"please fill all
fields.",Snackbar.LENGTH_SHORT).show();
}
else {

auth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new
OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {

if (task.isSuccessful()){

// verification of email address ( after creation


of account that user will get a email of verification
// if it will be verify then the user can go ahead
FirebaseUser firebaseUser=auth.getCurrentUser();
//

firebaseUser.sendEmailVerification().addOnCompleteListener(new
OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void>
task) {
if (task.isSuccessful()){

Snackbar.make(binding.signupLayout,"User Created Successfully. Please check your


email for verification.email sent to "+firebaseUser.getEmail(),
Snackbar.LENGTH_LONG).show();

binding.signupEmail.setText("");
binding.signupPassword.setText("");

}
else {

Snackbar.make(binding.signupLayout,
task.getException().getMessage(),
Snackbar.LENGTH_SHORT).show();
}
}
});

}
else {

Snackbar.make(binding.signupLayout,task.getException().getMessage(),Snackbar.LENGTH
_SHORT).show();
}
}
});
}

}
});
}
}

You might also like