Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void checkExistingEmail(){
- firebaseAuth.fetchSignInMethodsForEmail(userEmail.getText().toString()).addOnCompleteListener(new OnCompleteListener<SignInMethodQueryResult>() {
- @Override
- public void onComplete(@NonNull Task<SignInMethodQueryResult> task) {
- boolean check = !task.getResult().getSignInMethods().isEmpty();
- if(check){
- userEmail.setError("Account with same email address already exist!");
- }
- }
- });
- }
- regButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if(validate()){
- String user_email = userEmail.getText().toString().trim();
- String user_password = userPassword.getEditText().getText().toString().trim();
- firebaseAuth.createUserWithEmailAndPassword(user_email, user_password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
- @Override
- public void onComplete(@NonNull Task<AuthResult> task) {
- checkExistingEmail();
- if(task.isSuccessful()){
- sendEmailVerification();
- }else{
- Toast.makeText(RegistrationActivity.this, "Registration is Unsuccessful!", Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- }
- });
- private void sendEmailVerification(){
- FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
- if(firebaseUser != null){
- progressDialog.setMessage("Please hold on. We are testing your patience!");
- progressDialog.setProgressStyle(progressDialog.STYLE_SPINNER);
- progressDialog.show();
- firebaseUser.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
- @Override
- public void onComplete(@NonNull Task<Void> task) {
- if(task.isSuccessful()){
- sendUserData();
- progressDialog.dismiss();
- Toast.makeText(RegistrationActivity.this, "Registration Successful! Verification mail has been sent!", Toast.LENGTH_SHORT).show();
- //after account has been created, by right will straight open next activity. but force signout so user can sign in again
- firebaseAuth .signOut();
- finish();
- startActivity(new Intent(RegistrationActivity.this, MainActivity.class));
- }else{
- progressDialog.dismiss();
- Toast.makeText(RegistrationActivity.this, "Registration Failed!", Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment