Advertisement
Guest User

Untitled

a guest
Oct 10th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. private void startLogin() {
  2. final ProgressDialog progressDialog;
  3. progressDialog = new ProgressDialog(this, R.style.AppCompatAlertDialogStyle);
  4.  
  5. String email = mEmailField.getText().toString();
  6. String password = mPasswordField.getText().toString();
  7.  
  8. if(TextUtils.isEmpty(email) || TextUtils.isEmpty(password)){
  9. Toast.makeText(LoginActivity.this, "Campo vazio", Toast.LENGTH_LONG).show();
  10. }else{
  11. progressDialog.setMessage("Aguarde, entrando no aplicativo!");
  12. progressDialog.show();
  13.  
  14. mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
  15. @Override
  16. public void onComplete(@NonNull Task<AuthResult> task) {
  17. if(!task.isSuccessful()){
  18. Toast.makeText(LoginActivity.this, "Erro no login", Toast.LENGTH_LONG).show();
  19. }else{
  20. startActivity(new Intent(LoginActivity.this, DashActivity.class));
  21. }
  22.  
  23. progressDialog.dismiss();
  24. }
  25. });
  26. }
  27. }
  28.  
  29. if (task.isSuccessful()) {
  30.  
  31. FirebaseUser user = mAuth.getCurrentUser();
  32. Toast.makeText(SignInActivity.this, "Seja bem vindo: " + user.getDisplayName(), Toast.LENGTH_SHORT).show();
  33. if (user != null) {// Verifica se o usuario está logado
  34. startActivity(new Intent(SignInActivity.this, MainActivity.class));
  35. }
  36. } else {
  37. // Se não estiver logado
  38. Log.w(TAG, "signInWithCredential:failure", task.getException());
  39. Toast.makeText(SignInActivity.this, "Authentication failed.",
  40. Toast.LENGTH_SHORT).show();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement