Guest User

Untitled

a guest
Jan 8th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. import android.content.Intent;
  2. import android.content.pm.ActivityInfo;
  3. import android.support.annotation.NonNull;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.text.TextUtils;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.Toast;
  11.  
  12. import com.firebase.client.Firebase;
  13. import com.google.android.gms.tasks.OnCompleteListener;
  14. import com.google.android.gms.tasks.Task;
  15. import com.google.firebase.auth.AuthResult;
  16. import com.google.firebase.auth.FirebaseAuth;
  17. import com.google.firebase.auth.FirebaseUser;
  18. import com.google.firebase.database.DatabaseReference;
  19. import com.google.firebase.database.FirebaseDatabase;
  20.  
  21. public class CreateAccountActivity extends AppCompatActivity
  22. {
  23. private DatabaseReference databaseReference;
  24. private FirebaseAuth firebaseAuth;
  25.  
  26. private Button createButton;
  27.  
  28. private EditText firstNameText;
  29. private EditText lastNameText;
  30. private EditText ageText;
  31. private EditText emailText;
  32. private EditText passwordText;
  33. private EditText phoneNumberText;
  34.  
  35. @Override
  36. protected void onCreate(Bundle savedInstanceState)
  37. {
  38. super.onCreate(savedInstanceState);
  39. setContentView(R.layout.activity_create_account);
  40.  
  41. firebaseAuth = FirebaseAuth.getInstance();
  42. databaseReference = FirebaseDatabase.getInstance().getReference();
  43.  
  44. createButton = (Button) findViewById(R.id.CreateNewAccount);
  45.  
  46. firstNameText = (EditText) findViewById(R.id.FirstNameField);
  47. lastNameText = (EditText) findViewById(R.id.LastNameField);
  48. ageText = (EditText) findViewById(R.id.AgeField);
  49. emailText = (EditText) findViewById(R.id.EmailField);
  50. passwordText = (EditText) findViewById(R.id.PasswordField);
  51. phoneNumberText = (EditText) findViewById(R.id.PhoneNumberField);
  52.  
  53. createButton.setOnClickListener(new View.OnClickListener()
  54. {
  55. @Override
  56. public void onClick(View v)
  57. {
  58. databaseReference.child("test2").setValue("Testing");
  59. createAccount();
  60. databaseReference.child("test8").setValue("Testing");
  61. }
  62. });
  63. }
  64.  
  65. private void createAccount()
  66. {
  67. databaseReference.child("test3").setValue("Testing");
  68. final String firstName = firstNameText.getText().toString();
  69. final String lastName = lastNameText.getText().toString();
  70. final String age = ageText.getText().toString();
  71. final String email = emailText.getText().toString();
  72. final String password = passwordText.getText().toString();
  73. final String phoneNumber = phoneNumberText.getText().toString();
  74. databaseReference.child("test4").setValue("Testing");
  75.  
  76. if (!(TextUtils.isEmpty(firstName) || TextUtils.isEmpty(lastName) || TextUtils.isEmpty(age) || TextUtils.isEmpty(email) || TextUtils.isEmpty(password) || TextUtils.isEmpty(phoneNumber)))
  77. {
  78.  
  79. databaseReference.child("test5").setValue("Testing");
  80. firebaseAuth.createUserWithEmailAndPassword(email, password)
  81. .addOnCompleteListener(this, new OnCompleteListener<AuthResult>()
  82. {
  83.  
  84. @Override
  85. public void onComplete(@NonNull Task<AuthResult> task)
  86. {
  87. if (!(task.isSuccessful()))
  88. Toast.makeText(CreateAccountActivity.this, task.getException().getMessage(), Toast.LENGTH_LONG).show();
  89. else
  90. {
  91. databaseReference.child("test6").setValue("Testing");
  92. final FirebaseUser user = firebaseAuth.getCurrentUser();
  93.  
  94. user.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>()
  95. {
  96. @Override
  97. public void onComplete(@NonNull Task<Void> task)
  98. {
  99. if (task.isSuccessful())
  100. {
  101.  
  102. Toast.makeText(CreateAccountActivity.this, "Verification email was sent", Toast.LENGTH_LONG).show();
  103. databaseReference.child("test7").setValue("Testing");
  104.  
  105. firebaseAuth.signOut();
  106.  
  107. startActivity(new Intent(CreateAccountActivity.this, MainActivity.class));
  108. finish();
  109. }
  110. else
  111. {
  112. Toast.makeText(CreateAccountActivity.this, "Email could not be verified", Toast.LENGTH_LONG).show();
  113. finish();
  114. }
  115. }
  116. });
  117. }
  118. }
  119. });
  120. }
  121. else
  122. Toast.makeText(CreateAccountActivity.this, "Field(s) cannot be left empty", Toast.LENGTH_LONG).show();
  123. }
Add Comment
Please, Sign In to add comment