| 1 |
www |
1 |
import React from 'react'
|
|
|
2 |
import { useForm } from 'react-hook-form';
|
|
|
3 |
import Recaptcha from "react-recaptcha";
|
|
|
4 |
import {axios} from '../../../../utils';
|
|
|
5 |
import FormErrorFeedback from "../../../../shared/form-error-feedback/FormErrorFeedback";
|
| 662 |
steven |
6 |
import CryptoJSAesJson from '../../../../utils/crypto-js/cryptojs-aes-format';
|
| 1 |
www |
7 |
|
|
|
8 |
export default (props) => {
|
|
|
9 |
const {
|
|
|
10 |
captchaKey,
|
|
|
11 |
aes,
|
|
|
12 |
} = props.backendVars;
|
|
|
13 |
|
|
|
14 |
const {
|
|
|
15 |
register,
|
|
|
16 |
handleSubmit,
|
|
|
17 |
errors,
|
|
|
18 |
setError,
|
|
|
19 |
clearErrors,
|
|
|
20 |
getValues,
|
|
|
21 |
setValue,
|
|
|
22 |
} = useForm();
|
|
|
23 |
|
|
|
24 |
// Recaptcha
|
|
|
25 |
const reCaptchaToken = React.useRef("");
|
|
|
26 |
const [isVerified, setIsVerified] = React.useState(false);
|
|
|
27 |
const reCaptchaInstance = React.useRef();
|
|
|
28 |
// states
|
|
|
29 |
const [rememberChecked, setRememberChecked] = React.useState(false);
|
|
|
30 |
const [isLoading, setIsLoading] = React.useState(false);
|
|
|
31 |
// const [password, setPassword ] = React.useState('')
|
|
|
32 |
// const [confirmation, setConfirmation] = React.useState('')
|
|
|
33 |
const loginVerifyCallbackHandler = (response) => {
|
|
|
34 |
reCaptchaToken.current = response;
|
|
|
35 |
setIsVerified(true);
|
|
|
36 |
};
|
|
|
37 |
const loginExpiredCallbackHandler = () => {
|
|
|
38 |
reCaptchaToken.current = "";
|
|
|
39 |
setIsVerified(false);
|
|
|
40 |
};
|
|
|
41 |
const handleOnRecaptchaLoad = () => {
|
|
|
42 |
reCaptchaToken.current = "";
|
|
|
43 |
};
|
|
|
44 |
|
|
|
45 |
const resetCaptcha = () => {
|
|
|
46 |
reCaptchaInstance.current.reset();
|
|
|
47 |
}
|
|
|
48 |
React.useEffect(() => {
|
|
|
49 |
resetCaptcha()
|
|
|
50 |
}, []);
|
|
|
51 |
const submit = (data, event) => {
|
|
|
52 |
const formData = new FormData();
|
|
|
53 |
Object.entries(data).map(([key, value]) => {
|
|
|
54 |
if (key === "confirmation" && value)
|
|
|
55 |
return formData.append(key, CryptoJSAesJson.encrypt(value, aes));
|
|
|
56 |
if (key === "password" && value)
|
|
|
57 |
return formData.append(key, CryptoJSAesJson.encrypt(value, aes));
|
|
|
58 |
});
|
|
|
59 |
formData.append("captcha", reCaptchaToken.current);
|
|
|
60 |
axios.post('', formData).then(res => {
|
|
|
61 |
if(res.data.success){
|
|
|
62 |
window.location.href = "/"
|
|
|
63 |
}else{
|
|
|
64 |
setError('password', {
|
|
|
65 |
type: "manual",
|
|
|
66 |
message: typeof res.data.data === 'string' ? res.data.data : res.data.data.confirmation[0],
|
|
|
67 |
});
|
|
|
68 |
}
|
|
|
69 |
}).catch(err => {
|
|
|
70 |
('>>: err > ', err)
|
|
|
71 |
}).finally(() => {
|
|
|
72 |
resetCaptcha()
|
|
|
73 |
})
|
|
|
74 |
formData.append("captcha", reCaptchaToken.current);
|
|
|
75 |
}
|
| 2268 |
steven |
76 |
|
|
|
77 |
|
|
|
78 |
|
| 1 |
www |
79 |
return (
|
|
|
80 |
<div className="signin-popup">
|
|
|
81 |
<div className="signin-pop">
|
|
|
82 |
<div className="row">
|
|
|
83 |
<div className="col-lg-12">
|
|
|
84 |
<div className="login-sec">
|
|
|
85 |
<div className="sign_in_sec current" id="tab-1">
|
|
|
86 |
<h3>Reiniciar clave</h3>
|
|
|
87 |
<form
|
|
|
88 |
onSubmit={handleSubmit(submit)}
|
|
|
89 |
>
|
|
|
90 |
<div className="row">
|
|
|
91 |
<div className="col-lg-12 no-pdd">
|
|
|
92 |
<div className="inputContainer">
|
|
|
93 |
<div className="sn-field">
|
|
|
94 |
<input
|
|
|
95 |
type="password"
|
|
|
96 |
name="password"
|
|
|
97 |
ref={register({
|
|
|
98 |
required: "Este campo es requerido",
|
|
|
99 |
})}
|
|
|
100 |
pattern="^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$^x%x*-]).{6,16}$"
|
|
|
101 |
title="La clave debe contener entre 6 y 16 caracteres, incluida una letra mayúscula, un número y un carácter especial #?!@$^%*-"
|
|
|
102 |
placeholder="Nueva clave"
|
|
|
103 |
maxLength="16"
|
|
|
104 |
/>
|
|
|
105 |
<i className="la la-lock"></i>
|
|
|
106 |
</div>
|
|
|
107 |
{errors.password && (
|
|
|
108 |
<FormErrorFeedback>{errors.password.message}</FormErrorFeedback>
|
|
|
109 |
)}
|
|
|
110 |
</div>
|
|
|
111 |
</div>
|
|
|
112 |
<div className="col-lg-12 no-pdd">
|
|
|
113 |
<div className="inputContainer">
|
|
|
114 |
<div className="sn-field">
|
|
|
115 |
<input
|
|
|
116 |
type="password"
|
|
|
117 |
name="confirmation"
|
|
|
118 |
ref={register({
|
|
|
119 |
required: "Este campo es requerido",
|
|
|
120 |
})}
|
|
|
121 |
pattern="^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$^x%x*-]).{6,16}$"
|
|
|
122 |
title="La clave debe contener entre 6 y 16 caracteres, incluida una letra mayúscula, un número y un carácter especial #?!@$^%*-"
|
|
|
123 |
placeholder="Repita nueva clave"
|
|
|
124 |
maxLength="16"
|
|
|
125 |
/>
|
|
|
126 |
<i className="la la-lock"></i>
|
|
|
127 |
</div>
|
|
|
128 |
{errors.confirmation && (
|
|
|
129 |
<FormErrorFeedback>{errors.confirmation.message}</FormErrorFeedback>
|
|
|
130 |
)}
|
|
|
131 |
</div>
|
|
|
132 |
</div>
|
|
|
133 |
<div className="col-lg-12 no-pdd">
|
|
|
134 |
<div className="sn-field">
|
|
|
135 |
<Recaptcha
|
|
|
136 |
sitekey={captchaKey}
|
|
|
137 |
verifyCallback={loginVerifyCallbackHandler}
|
|
|
138 |
verifyCallbackName="loginVerifyCallbackHandler"
|
|
|
139 |
expiredCallback={loginExpiredCallbackHandler}
|
|
|
140 |
expiredCallbackName="loginExpiredCallbackHandler"
|
|
|
141 |
ref={reCaptchaInstance}
|
|
|
142 |
render="explicit"
|
|
|
143 |
onloadCallback={handleOnRecaptchaLoad}
|
|
|
144 |
hl="es"
|
|
|
145 |
/>
|
|
|
146 |
</div>
|
|
|
147 |
</div>
|
|
|
148 |
<div className="col-lg-12 no-pdd">
|
|
|
149 |
<button type="submit" value="submit" id="btn-submit" disabled={!isVerified} >Guardar</button>
|
|
|
150 |
</div>
|
|
|
151 |
</div>
|
|
|
152 |
</form>
|
|
|
153 |
</div>
|
|
|
154 |
</div>
|
|
|
155 |
</div>
|
|
|
156 |
</div>
|
|
|
157 |
</div>
|
|
|
158 |
</div>
|
|
|
159 |
)
|
|
|
160 |
}
|