Skip to content

Commit

Permalink
Archivos finales
Browse files Browse the repository at this point in the history
  • Loading branch information
falconmasters committed May 15, 2021
1 parent beafc91 commit 141b826
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Como implementar re-CAPTCHA con REACT
### [Tutorial: https://youtu.be/](https://youtu.be/)
### [Tutorial: https://youtu.be/gauhWyPaYas](https://youtu.be/gauhWyPaYas)

![Como implementar re-CAPTCHA con REACT](https://raw.githubusercontent.com/falconmasters/google-recaptcha-v2/master/img/thumb.png)

Expand Down
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@testing-library/user-event": "^12.8.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-google-recaptcha": "^2.1.0",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.2"
},
Expand Down
70 changes: 55 additions & 15 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,62 @@
import React from 'react';
import React, {useRef, useState} from 'react';
import ReCAPTCHA from "react-google-recaptcha";

const App = () => {
const [captchaValido, cambiarCaptchaValido] = useState(null);
const [usuarioValido, cambiarUsuarioValido] = useState(false);

const captcha = useRef(null);

const onChange = () => {
if(captcha.current.getValue()){
console.log('El usuario no es un robot');
cambiarCaptchaValido(true);
}
}

const submit = (e) => {
e.preventDefault();

// Validamos los inputs del formulario
// Si son correctos ya podemos enviar el fomulario, actualizar la Interfaz, etc.

if(captcha.current.getValue()){
console.log('El usuario no es un robot');
cambiarUsuarioValido(true);
cambiarCaptchaValido(true);
} else {
console.log('Por favor acepta el captcha');
cambiarUsuarioValido(false);
cambiarCaptchaValido(false);
}
}

return (
<div className="contenedor">
<div className="registrate">
<h1>Registrate</h1>
<form className="formulario" action="" onSubmit={submit}>
<input type="text" name="usuario" id="usuario" placeholder="Usuario" />
<input type="password" name="password" id="password" placeholder="Contraseña" />
<input type="password" name="password2" id="password2" placeholder="Repetir Contraseña" />
<div className="recaptcha">
</div>
<button type="submit">Iniciar Sesion</button>
</form>
</div>
<div>
<h1>Bienvenido</h1>
</div>
{!usuarioValido &&
<div className="registrate">
<h1>Registrate</h1>
<form className="formulario" action="" onSubmit={submit}>
<input type="text" name="usuario" id="usuario" placeholder="Usuario" />
<input type="password" name="password" id="password" placeholder="Contraseña" />
<input type="password" name="password2" id="password2" placeholder="Repetir Contraseña" />
<div className="recaptcha">
<ReCAPTCHA
ref={captcha}
sitekey="TU CLAVE DE CAPTCHA"
onChange={onChange}
/>
</div>
{captchaValido === false && <div className="error-captcha">Por favor acepta el captcha</div>}
<button type="submit">Iniciar Sesion</button>
</form>
</div>
}
{usuarioValido &&
<div>
<h1>Bienvenido</h1>
</div>
}
</div>
);
}
Expand Down

0 comments on commit 141b826

Please sign in to comment.