Guest User

Untitled

a guest
Jan 15th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. private void checkExistingEmail(){
  2. firebaseAuth.fetchSignInMethodsForEmail(userEmail.getText().toString()).addOnCompleteListener(new OnCompleteListener<SignInMethodQueryResult>() {
  3. @Override
  4. public void onComplete(@NonNull Task<SignInMethodQueryResult> task) {
  5.  
  6. boolean check = !task.getResult().getSignInMethods().isEmpty();
  7.  
  8. if(check){
  9. userEmail.setError("Account with same email address already exist!");
  10. }
  11. }
  12. });
  13. }
  14.  
  15. regButton.setOnClickListener(new View.OnClickListener() {
  16. @Override
  17. public void onClick(View view) {
  18. if(validate()){
  19. String user_email = userEmail.getText().toString().trim();
  20. String user_password = userPassword.getEditText().getText().toString().trim();
  21.  
  22. firebaseAuth.createUserWithEmailAndPassword(user_email, user_password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
  23. @Override
  24. public void onComplete(@NonNull Task<AuthResult> task) {
  25.  
  26. checkExistingEmail();
  27.  
  28. if(task.isSuccessful()){
  29. sendEmailVerification();
  30. }else{
  31. Toast.makeText(RegistrationActivity.this, "Registration is Unsuccessful!", Toast.LENGTH_SHORT).show();
  32. }
  33. }
  34. });
  35. }
  36. }
  37. });
  38.  
  39. private void sendEmailVerification(){
  40. FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
  41. if(firebaseUser != null){
  42.  
  43. progressDialog.setMessage("Please hold on. We are testing your patience!");
  44. progressDialog.setProgressStyle(progressDialog.STYLE_SPINNER);
  45. progressDialog.show();
  46.  
  47. firebaseUser.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
  48. @Override
  49. public void onComplete(@NonNull Task<Void> task) {
  50.  
  51. if(task.isSuccessful()){
  52. sendUserData();
  53. progressDialog.dismiss();
  54. Toast.makeText(RegistrationActivity.this, "Registration Successful! Verification mail has been sent!", Toast.LENGTH_SHORT).show();
  55. //after account has been created, by right will straight open next activity. but force signout so user can sign in again
  56. firebaseAuth .signOut();
  57. finish();
  58. startActivity(new Intent(RegistrationActivity.this, MainActivity.class));
  59. }else{
  60. progressDialog.dismiss();
  61. Toast.makeText(RegistrationActivity.this, "Registration Failed!", Toast.LENGTH_SHORT).show();
  62. }
  63. }
  64. });
  65. }
  66. }
Add Comment
Please, Sign In to add comment