Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CheckLogin extends AsyncTask<String,String,String>
- {
- String z = "";
- String mails = email.getText().toString().trim();
- String passwordd = password.getText().toString().trim();
- String nombres = user.getText().toString().trim();
- @Override
- protected void onPreExecute()
- {
- }
- @Override
- protected void onPostExecute(String r)
- {
- Log.d("valor final z",z);
- if(z.equals("Debes completar los 3 campos solicitados")){
- TastyToast.makeText(Registro.this,z, TastyToast.LENGTH_LONG, TastyToast.ERROR).show();
- simulateErrorProgress(adding);
- }else if (z.equals("El nombre debe tener al menos 10 caracteres")){
- TastyToast.makeText(Registro.this, z, TastyToast.LENGTH_LONG, TastyToast.ERROR).show();
- simulateErrorProgress(adding);
- }else if(z.equals("Usuario ya existe")){
- TastyToast.makeText(Registro.this, z, TastyToast.LENGTH_LONG, TastyToast.INFO).show();
- simulateErrorProgress(adding);
- }else if (z.equals("Formato de correo invalido")){
- TastyToast.makeText(Registro.this,z , TastyToast.LENGTH_LONG, TastyToast.INFO).show();
- simulateErrorProgress(adding);
- }else if(z.equals("Contraseña debil, Intenta con almenos 6 caracteres")){
- TastyToast.makeText(Registro.this, z, TastyToast.LENGTH_LONG, TastyToast.INFO).show();
- simulateErrorProgress(adding);
- }else if(z.equals("Conexión a internet perdida")){
- TastyToast.makeText(Registro.this, z, TastyToast.LENGTH_LONG, TastyToast.ERROR).show();
- simulateErrorProgress(adding);
- }else if(z.equals( "Ops, un error inesperado ha ocurrido, vuelve a intentarlo mas tarde")){
- TastyToast.makeText(Registro.this,z, TastyToast.LENGTH_LONG, TastyToast.ERROR).show();
- simulateErrorProgress(adding);
- }else if(z.equals("funciono")){
- simulateSuccessProgress(adding);
- email.setText("");
- password.setText("");
- user.setText("");
- }
- }
- @Override
- protected String doInBackground(String... params)
- {
- if (mails.trim().equals("") || passwordd.trim().equals("") || nombres.trim().equals("")) {
- z="Debes completar los 3 campos solicitados";
- }
- if (nombres.length() < 10) {
- z="El nombre debe tener al menos 10 caracteres";
- }else {
- mAuth.createUserWithEmailAndPassword(mails, passwordd)
- .addOnCompleteListener(Registro.this, new OnCompleteListener<AuthResult>() {
- @Override
- public void onComplete(@NonNull Task<AuthResult> task) {
- if (task.isSuccessful()) {
- Log.d("funciona", "pase por aqui");
- try {
- con = connectionclass(un, pass, db, ip);
- if (con == null) {
- } else {
- try {
- String encryptedps = AESCrypt.encrypt("encryp", passwordd);
- String query = "insert into usuarios (email, nombre, pass,fecha_creacion) values ('" + mails + "','" + nombres + "','" + encryptedps + "',((SELECT CONVERT (date, SYSDATETIME()))));";
- PreparedStatement preparedStatement = con.prepareStatement(query);
- preparedStatement.setQueryTimeout(2);
- preparedStatement.executeUpdate();
- con.close();
- simulateSuccessProgress(adding);
- Uri imageUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +
- "://" + getResources().getResourcePackageName(R.drawable.perfilvacio)
- + '/' + getResources().getResourceTypeName(R.drawable.perfilvacio) + '/' + getResources().getResourceEntryName(R.drawable.perfilvacio) );
- FirebaseUser update =FirebaseAuth.getInstance().getCurrentUser();
- UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
- .setDisplayName(nombres)
- .setPhotoUri(imageUri)
- .build();
- update.updateProfile(profileUpdates).addOnCompleteListener(new OnCompleteListener<Void>() {
- @Override
- public void onComplete(@NonNull Task<Void> task) {
- if (task.isSuccessful()) {
- FirebaseAuth.getInstance().signOut();
- }else {
- FirebaseAuth.getInstance().signOut();
- }
- }
- });
- z="funciono";
- } catch (GeneralSecurityException e) {
- Log.d("error de encriptacion", e.getMessage());
- }
- }
- } catch (Exception ex) {
- Log.d("error base de datos: ", ex.getMessage());
- }
- }
- else {
- Log.d("no funciono", task.getException().toString());
- if (task.getException().toString().trim().equals("com.google.firebase.auth.FirebaseAuthUserCollisionException: The email address is already in use by another account.".trim())) {
- z="Usuario ya existe";
- } else if (task.getException().toString().trim().equals("com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The email address is badly formatted".trim())) {
- z="Formato de correo invalido";
- } else if (task.getException().toString().trim().equals("com.google.firebase.FirebaseException: An internal error has occurred. [ WEAK_PASSWORD ]".trim())) {
- z="Contraseña debil, Intenta con almenos 6 caracteres";
- } 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())) {
- z="Conexión a internet perdida";
- } else {
- z="Ops, un error inesperado ha ocurrido, vuelve a intentarlo mas tarde";
- }
- }
- }
- });
- }
- return z;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement