diff --git a/src/components/FormChangePassword.vue b/src/components/FormChangePassword.vue
index b542f0c..55893f7 100644
--- a/src/components/FormChangePassword.vue
+++ b/src/components/FormChangePassword.vue
@@ -2,17 +2,30 @@
import {reactive, ref} from 'vue';
import CustomInput from './ui/CustomInput.vue';
import Spiner from './ui/Spiner.vue';
-import NotificationBadge from './ui/NotificationBadge.vue';
+ import NotificationBadge from './ui/NotificationBadge.vue';
+ import { recoveryPassword, recoveryPasswordConfirm, regiter } from '../services/auth';
+ import { useAuthStore } from '../stores/auth';
+ import { useRouter } from 'vue-router';
+ import { useNotificationsStore } from '../stores/notifications';
+
const pwdForm = reactive({
pwd: '',
pwd2: '',
+ code: '',
+ checksum: '',
})
+ const step = ref(1);
+
+ const auth = useAuthStore();
+ const router = useRouter();
+ const notifications = useNotificationsStore()
+
const loading = ref(false)
const msgError = ref('');
const msgSuccess = ref('');
- const hangleSave = () => {
+ const hangleSave = async() => {
msgError.value = '';
msgSuccess.value = '';
let resp = validations();
@@ -21,10 +34,88 @@ import NotificationBadge from './ui/NotificationBadge.vue';
clearMessages();
return;
} else {
-
+ loading.value = true;
+ msgError.value = '';
+ const data = {
+ email: auth.user.email,
+ password: pwdForm.pwd
+ }
+ const result = await recoveryPassword(data);
+ if(result.msg === 'success' && result.data !== null) {
+ msgSuccess.value = 'Te enviamos un código al correo, ingresado!';
+ pwdForm.checksum = result.data.checksum;
+ step.value = 2;
+ clearMessages();
+ } else {
+ msgError.value = result.msg;
+ clearMessages();
+ }
+ loading.value = false;
}
}
+ const handleConfirmChange = async() => {
+ msgError.value = '';
+ msgSuccess.value = '';
+ if(pwdForm.code.length < 6) {
+ msgError.value = 'Ingresa código valido';
+ clearMessages();
+ return;
+ } else {
+ loading.value = true;
+ msgError.value = '';
+ const data = {
+ email: auth.user.email,
+ password: pwdForm.pwd,
+ otp: pwdForm.code,
+ checksum: pwdForm.checksum
+ }
+ const result = await recoveryPasswordConfirm(data);
+ // console.log(result);
+ if(result.msg === 'success' && result.data !== null){
+ Object.assign(pwdForm, {
+ pwd: '',
+ retryPwd: '',
+ code: '',
+ checksum: '',
+ });
+ clearMessages();
+ notifications.$patch({
+ text : 'Contraseña se ha cambiando exitosamente!',
+ show : true,
+ error: false
+ });
+ router.push({name: 'login'});
+ } else {
+ msgError.value = result.msg;
+ clearMessages()
+ }
+ loading.value = false;
+ }
+ }
+
+ const resendCode = async() => {
+ // loading.value = true;
+ // const data = {
+ // email: pwdForm.email,
+ // password: pwdForm.pwd
+ // }
+ // const result = await regiter(data);
+ // if(result.msg === 'success' && result.data !== null) {
+ // msgSuccess.value = 'Te enviamos un código al correo, ingresado!';
+ // checksum.value = result.data.checksum;
+ // clearMessages();
+ // } else {
+ // msgError.value = result.msg;
+ // clearMessages();
+ // }
+ // loading.value = false;
+ }
+
+ const handleBack = (val) => {
+ step.value = val;
+ }
+
const validations = () => {
const pass = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/;
@@ -51,6 +142,7 @@ import NotificationBadge from './ui/NotificationBadge.vue';
autocomplete="off"
method="post"
ref="formRef1"
+ v-if="step === 1"
>