Reparacion de registrarte con email y recuperacion de contraseña!
This commit is contained in:
parent
73109cfbfb
commit
156a76a009
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.santiparra.yomitrack.ui.fragments.forgotpassword;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
|
|
||||||
|
import com.santiparra.yomitrack.api.ApiClient;
|
||||||
|
import com.santiparra.yomitrack.api.ApiService;
|
||||||
|
import com.santiparra.yomitrack.databinding.FragmentForgotPasswordBinding;
|
||||||
|
import com.santiparra.yomitrack.model.ApiResponse;
|
||||||
|
import com.santiparra.yomitrack.R;
|
||||||
|
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
|
public class ForgotPasswordFragment extends Fragment {
|
||||||
|
private FragmentForgotPasswordBinding binding;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
binding = FragmentForgotPasswordBinding.inflate(inflater, container, false);
|
||||||
|
|
||||||
|
binding.buttonSendRecovery.setOnClickListener(v -> {
|
||||||
|
String email = binding.editEmail.getText().toString().trim();
|
||||||
|
if (email.isEmpty()) {
|
||||||
|
showToast("Ingresa tu correo electrónico");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApiService apiService = ApiClient.getClient().create(ApiService.class);
|
||||||
|
apiService.forgotPassword(email).enqueue(new Callback<ApiResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<ApiResponse> call, Response<ApiResponse> response) {
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
showToast("Revisa tu correo para restablecer la contraseña");
|
||||||
|
NavHostFragment.findNavController(ForgotPasswordFragment.this)
|
||||||
|
.navigate(R.id.action_forgotPasswordFragment_to_resetPasswordFragment);
|
||||||
|
} else {
|
||||||
|
showToast("No se pudo enviar el correo. Verifica tu email.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<ApiResponse> call, Throwable t) {
|
||||||
|
showToast("Error: " + t.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return binding.getRoot();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showToast(String msg) {
|
||||||
|
Toast.makeText(requireContext(), msg, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
package com.santiparra.yomitrack.ui.fragments.resetpassword;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
|
|
||||||
|
import com.santiparra.yomitrack.api.ApiClient;
|
||||||
|
import com.santiparra.yomitrack.api.ApiService;
|
||||||
|
import com.santiparra.yomitrack.databinding.FragmentResetPasswordBinding;
|
||||||
|
import com.santiparra.yomitrack.model.ApiResponse;
|
||||||
|
import com.santiparra.yomitrack.R;
|
||||||
|
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
|
public class ResetPasswordFragment extends Fragment {
|
||||||
|
|
||||||
|
private FragmentResetPasswordBinding binding;
|
||||||
|
|
||||||
|
public ResetPasswordFragment() {}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
binding = FragmentResetPasswordBinding.inflate(inflater, container, false);
|
||||||
|
return binding.getRoot();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
binding.buttonResetPassword.setOnClickListener(v -> resetPassword());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetPassword() {
|
||||||
|
String email = binding.editEmail.getText().toString().trim();
|
||||||
|
String token = binding.editToken.getText().toString().trim();
|
||||||
|
String newPassword = binding.editNewPassword.getText().toString().trim();
|
||||||
|
|
||||||
|
if (email.isEmpty() || token.isEmpty() || newPassword.isEmpty()) {
|
||||||
|
showToast("Completa todos los campos");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApiService apiService = ApiClient.getClient().create(ApiService.class);
|
||||||
|
apiService.resetPassword(email, token, newPassword).enqueue(new Callback<ApiResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull Response<ApiResponse> response) {
|
||||||
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
|
showToast("Contraseña restablecida correctamente");
|
||||||
|
NavHostFragment.findNavController(ResetPasswordFragment.this)
|
||||||
|
.navigate(R.id.action_resetPasswordFragment_to_loginFragment);
|
||||||
|
} else {
|
||||||
|
showToast("Token inválido o expirado");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {
|
||||||
|
showToast("Error de red: " + t.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showToast(String message) {
|
||||||
|
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
binding = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="24dp">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editEmail"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/edit_text_background"
|
||||||
|
android:hint="Correo electrónico"
|
||||||
|
android:inputType="textEmailAddress"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textColorHint="@android:color/white" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonSendRecovery"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="Enviar recuperación" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonGoToReset"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="Ya tengo el código" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="24dp">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editEmail"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Correo electrónico" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editToken"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Código de recuperación" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editNewPassword"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Nueva contraseña"
|
||||||
|
android:inputType="textPassword" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonResetPassword"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Restablecer contraseña"
|
||||||
|
android:layout_marginTop="16dp" />
|
||||||
|
</LinearLayout>
|
||||||
Loading…
Reference in New Issue