Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
  2. //Сперва пользователь зарегистрируется
  3. registration = (Button)findViewById(R.id.registration);
  4. mail = (EditText)findViewById(R.id.txtEmailRegistration);
  5. password = (EditText)findViewById(R.id.txtPasswordRegistration);
  6. registration.setOnClickListener(new View.OnClickListener() {
  7. @Override
  8. public void onClick(View view) {
  9. final ProgressDialog progressDialog = ProgressDialog.show(Registration.this, getResources().getString(R.string.loading), getResources().getString(R.string.wait), true);
  10. firebaseAuth.createUserWithEmailAndPassword(mail.getText().toString(), password.getText().toString()).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
  11. @Override
  12. public void onComplete(@NonNull Task<AuthResult> task) {
  13. progressDialog.dismiss();
  14. if (task.isSuccessful()) {
  15. Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.successful), Toast.LENGTH_LONG);
  16. toast.show();
  17. Intent intent = new Intent(Registration.this, Login.class);
  18. startActivity(intent);
  19. DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
  20. FirebaseUser user = firebaseAuth.getCurrentUser();
  21. assert user != null;
  22. user.sendEmailVerification();//После успешной регистрации, отправляется подтверждение на почту
  23. } else {
  24. Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.error), Toast.LENGTH_LONG);
  25. toast.show();
  26. }
  27. }
  28. });
  29. }
  30.  
  31. }
  32. });
  33.  
  34. firebaseAuth = FirebaseAuth.getInstance();
  35. email = (EditText)findViewById(R.id.txtEmailLogin);
  36. password = (EditText)findViewById(R.id.txtPasswordLogin);
  37. login = (Button)findViewById(R.id.btnLogin);
  38. login.setOnClickListener(new View.OnClickListener() {
  39. @Override
  40. public void onClick(View view) {
  41. final ProgressDialog progressDialog = ProgressDialog.show(Login.this, getResources().getString(R.string.loading), getResources().getString(R.string.wait), true);
  42. firebaseAuth.signInWithEmailAndPassword(email.getText().toString(), password.getText().toString()).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
  43. @Override
  44. public void onComplete(@NonNull Task<AuthResult> task) {
  45. if (task.isSuccessful()) {
  46. progressDialog.dismiss();
  47. Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.successful), Toast.LENGTH_LONG);
  48. toast.show();
  49. Intent intent = new Intent(Login.this, MainActivity.class);
  50. startActivity(intent);
  51. if(!user.isEmailVerified()){
  52. final AlertDialog.Builder builder = new AlertDialog.Builder(Login.this);
  53. builder.setTitle("Подтверждение")
  54. .setCancelable(false)
  55. .setMessage("Пожалуйста, подтвердите аккаунт. Затем только нажмите на кнопку потдвердил")
  56. .setNegativeButton("Подтвердил",
  57. new DialogInterface.OnClickListener() {
  58. public void onClick(DialogInterface dialog, int id) {
  59. if(!user.isEmailVerified()){
  60. AlertDialog alert = builder.create();
  61. alert.show();
  62. }else{
  63.  
  64. }
  65. }
  66. });
  67. AlertDialog alert = builder.create();
  68. alert.show();
  69. }else{
  70. Toast.makeText(getApplicationContext(), "Аккаунт подтвержден", Toast.LENGTH_LONG).show();
  71. }
  72. } else {
  73. progressDialog.dismiss();
  74. Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.error), Toast.LENGTH_LONG);
  75. toast.show();
  76. }
  77. }
  78. });
  79.  
  80.  
  81. }
  82. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement