Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.85 KB | None | 0 0
  1. public class CheckLogin extends AsyncTask<String,String,String>
  2. {
  3. String z = "";
  4. String mails = email.getText().toString().trim();
  5. String passwordd = password.getText().toString().trim();
  6. String nombres = user.getText().toString().trim();
  7.  
  8.  
  9. @Override
  10. protected void onPreExecute()
  11. {
  12.  
  13. }
  14.  
  15. @Override
  16. protected void onPostExecute(String r)
  17. {
  18. Log.d("valor final z",z);
  19.  
  20. if(z.equals("Debes completar los 3 campos solicitados")){
  21. TastyToast.makeText(Registro.this,z, TastyToast.LENGTH_LONG, TastyToast.ERROR).show();
  22. simulateErrorProgress(adding);
  23. }else if (z.equals("El nombre debe tener al menos 10 caracteres")){
  24. TastyToast.makeText(Registro.this, z, TastyToast.LENGTH_LONG, TastyToast.ERROR).show();
  25. simulateErrorProgress(adding);
  26. }else if(z.equals("Usuario ya existe")){
  27. TastyToast.makeText(Registro.this, z, TastyToast.LENGTH_LONG, TastyToast.INFO).show();
  28. simulateErrorProgress(adding);
  29. }else if (z.equals("Formato de correo invalido")){
  30. TastyToast.makeText(Registro.this,z , TastyToast.LENGTH_LONG, TastyToast.INFO).show();
  31. simulateErrorProgress(adding);
  32. }else if(z.equals("Contraseña debil, Intenta con almenos 6 caracteres")){
  33. TastyToast.makeText(Registro.this, z, TastyToast.LENGTH_LONG, TastyToast.INFO).show();
  34. simulateErrorProgress(adding);
  35. }else if(z.equals("Conexión a internet perdida")){
  36. TastyToast.makeText(Registro.this, z, TastyToast.LENGTH_LONG, TastyToast.ERROR).show();
  37. simulateErrorProgress(adding);
  38. }else if(z.equals( "Ops, un error inesperado ha ocurrido, vuelve a intentarlo mas tarde")){
  39. TastyToast.makeText(Registro.this,z, TastyToast.LENGTH_LONG, TastyToast.ERROR).show();
  40. simulateErrorProgress(adding);
  41. }else if(z.equals("funciono")){
  42. simulateSuccessProgress(adding);
  43. email.setText("");
  44. password.setText("");
  45. user.setText("");
  46. }
  47. }
  48. @Override
  49. protected String doInBackground(String... params)
  50. {
  51. if (mails.trim().equals("") || passwordd.trim().equals("") || nombres.trim().equals("")) {
  52. z="Debes completar los 3 campos solicitados";
  53. }
  54. if (nombres.length() < 10) {
  55. z="El nombre debe tener al menos 10 caracteres";
  56. }else {
  57. mAuth.createUserWithEmailAndPassword(mails, passwordd)
  58. .addOnCompleteListener(Registro.this, new OnCompleteListener<AuthResult>() {
  59. @Override
  60. public void onComplete(@NonNull Task<AuthResult> task) {
  61. if (task.isSuccessful()) {
  62. Log.d("funciona", "pase por aqui");
  63. try {
  64. con = connectionclass(un, pass, db, ip);
  65. if (con == null) {
  66. } else {
  67. try {
  68. String encryptedps = AESCrypt.encrypt("encryp", passwordd);
  69. String query = "insert into usuarios (email, nombre, pass,fecha_creacion) values ('" + mails + "','" + nombres + "','" + encryptedps + "',((SELECT CONVERT (date, SYSDATETIME()))));";
  70. PreparedStatement preparedStatement = con.prepareStatement(query);
  71. preparedStatement.setQueryTimeout(2);
  72. preparedStatement.executeUpdate();
  73. con.close();
  74. simulateSuccessProgress(adding);
  75. Uri imageUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +
  76. "://" + getResources().getResourcePackageName(R.drawable.perfilvacio)
  77. + '/' + getResources().getResourceTypeName(R.drawable.perfilvacio) + '/' + getResources().getResourceEntryName(R.drawable.perfilvacio) );
  78. FirebaseUser update =FirebaseAuth.getInstance().getCurrentUser();
  79.  
  80. UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
  81. .setDisplayName(nombres)
  82. .setPhotoUri(imageUri)
  83. .build();
  84. update.updateProfile(profileUpdates).addOnCompleteListener(new OnCompleteListener<Void>() {
  85. @Override
  86. public void onComplete(@NonNull Task<Void> task) {
  87. if (task.isSuccessful()) {
  88. FirebaseAuth.getInstance().signOut();
  89. }else {
  90. FirebaseAuth.getInstance().signOut();
  91. }
  92. }
  93. });
  94.  
  95. z="funciono";
  96. } catch (GeneralSecurityException e) {
  97. Log.d("error de encriptacion", e.getMessage());
  98. }
  99. }
  100. } catch (Exception ex) {
  101. Log.d("error base de datos: ", ex.getMessage());
  102. }
  103. }
  104. else {
  105. Log.d("no funciono", task.getException().toString());
  106.  
  107. if (task.getException().toString().trim().equals("com.google.firebase.auth.FirebaseAuthUserCollisionException: The email address is already in use by another account.".trim())) {
  108. z="Usuario ya existe";
  109. } else if (task.getException().toString().trim().equals("com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The email address is badly formatted".trim())) {
  110. z="Formato de correo invalido";
  111. } else if (task.getException().toString().trim().equals("com.google.firebase.FirebaseException: An internal error has occurred. [ WEAK_PASSWORD ]".trim())) {
  112. z="Contraseña debil, Intenta con almenos 6 caracteres";
  113. } else if (task.getException().toString().trim().equals("com.google.firebase.FirebaseNetworkException: A network error (such as timeout, interrupted connection or unreachable host) has occurred.".trim())) {
  114. z="Conexión a internet perdida";
  115. } else {
  116. z="Ops, un error inesperado ha ocurrido, vuelve a intentarlo mas tarde";
  117. }
  118. }
  119.  
  120. }
  121. });
  122. }
  123. return z;
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement