From b66da76e393e3efdbf485d314acfb8b514671371 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Jun 2023 17:58:08 -0500 Subject: [PATCH] Codigo falarta terminar de implementar proceso de validacion PIN --- package.json | 1 + src/App.tsx | 2 +- src/Components/Login/ForgotPassword.tsx | 177 +++++++++++++++++++ src/Components/Login/PIN.tsx | 127 ++++++++++++++ src/Components/Login/ResetCredentials.tsx | 197 ++++++++++++++++++++++ src/Components/Login/login.tsx | 9 +- src/DTO/DTOPINUsuario.ts | 4 + src/DTO/DTOResetPassword.ts | 4 + src/Services/Auth/Auth.Service.ts | 26 ++- src/Services/common/http-common.ts | 26 ++- src/css/reactCaptcha.css | 12 ++ src/index.tsx | 4 + yarn.lock | 23 ++- 13 files changed, 582 insertions(+), 30 deletions(-) create mode 100644 src/Components/Login/ForgotPassword.tsx create mode 100644 src/Components/Login/PIN.tsx create mode 100644 src/Components/Login/ResetCredentials.tsx create mode 100644 src/DTO/DTOPINUsuario.ts create mode 100644 src/DTO/DTOResetPassword.ts create mode 100644 src/css/reactCaptcha.css diff --git a/package.json b/package.json index 7bd717d..a235a81 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "react": "^17.0.2", "react-apexcharts": "^1.4.0", "react-bootstrap": "^2.2.0", + "react-captchaa": "^1.0.13", "react-currency-format": "^1.1.0", "react-data-export": "^0.6.0", "react-data-table-component": "^7.5.2", diff --git a/src/App.tsx b/src/App.tsx index f93b08a..bd935d4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -96,7 +96,7 @@ function App() { {!userLogued ? ( <> Login - Reset + {/* Reset */} ) : ( <> diff --git a/src/Components/Login/ForgotPassword.tsx b/src/Components/Login/ForgotPassword.tsx new file mode 100644 index 0000000..cb70f55 --- /dev/null +++ b/src/Components/Login/ForgotPassword.tsx @@ -0,0 +1,177 @@ +import * as React from 'react' +import { Button, Card, Col, Form, Row } from 'react-bootstrap' +import logo from '../../images/GEMCO.png' +import { MsgInformativo } from '../Utils/Toast/msgInformativo' +import ReactCaptchaa from 'react-captchaa' +import AuthDS from '../../Services/Auth/Auth.Service' +import 'react-captchaa/dist/index.css' +import '../../css/reactCaptcha.css' +import ILogin from '../../Interfaces/Ilogin' +import { AxiosError } from 'axios' +import { useNavigate } from 'react-router-dom' +import { useState } from 'react' + +export interface IForgotPasswordProps {} + +export default function ForgotPassword(props: IForgotPasswordProps) { + const navigate = useNavigate() + const [Usuario, setUsuario] = useState('') + const [Contrasenia, setContrasenia] = useState('') + const [Captcha, setCaptcha] = useState('') + const [CaptchaText, setCaptchaText] = useState('') + const [show, setShow] = useState(false) + const [msg, setMsg] = useState('') + const [header, setHeader] = useState('') + const [msgColor, setMsgColor] = useState('primary') + + const validateCaptcha = () => { + if (!Usuario.length) { + setShow(true) + setMsg('El campo usuario no puede estar vacio') + setHeader('Error') + return + } + if (Captcha !== CaptchaText) { + setShow(true) + setMsg('Captcha o usuario incorrecto') + setHeader('Error') + return + } + const data: ILogin = { + Usuario: Usuario, + Contrasena: Contrasenia, + } + AuthDS.forgotPassword(data) + .then((response: any) => { + localStorage.setItem('User', JSON.stringify(Usuario)) + navigate('/PIN') + }) + .catch((e: AxiosError) => { + setShow(true) + setMsg('Usuario no existe') + setHeader('Error') + }) + } + + return ( +
+ + + + +   + +
+ + + + + + GEMCO + + + + + + + +   + +
+ + + { + setUsuario(e.target.value) + }} + /> + + + +   + + + + { + setCaptchaText(captchaText) + }} + captchaLength={6} + captchaButtonClick={(e: any) => {}} + onCanvasClick={(e: any) => {}} + height={150} + width={200} + iconName={'FiRefreshCw'} + iconColor={'#fff'} + fontSize={'3em'} + iconSize={'1em'} + containerClassName={'react-captcha'} + iconWrapperClassName={'react-captcha-icon-wrapper'} + canvasClassName={'react-captcha-canvas'} + iconClassName={'react-captcha-icon'} + charactersInclude={ + '0123456789abcdefghijklmnopqrstuvwxzABCDEFGHIJKLMNOPQRSTUVWXYZ' + } + /> + + + + + { + setCaptcha(e.target.value) + }} + /> + + + +   + +
+
+
+
+ +
+
+
+
+ +   +
+ +
+ ) +} diff --git a/src/Components/Login/PIN.tsx b/src/Components/Login/PIN.tsx new file mode 100644 index 0000000..29e5cf7 --- /dev/null +++ b/src/Components/Login/PIN.tsx @@ -0,0 +1,127 @@ +import * as React from 'react' +import { Button, Card, Col, Form, Row } from 'react-bootstrap' +import logo from '../../images/GEMCO_logo_min.png' +import { MsgInformativo } from '../Utils/Toast/msgInformativo' +import AuthDS from '../../Services/Auth/Auth.Service' +import { useState } from 'react' +import { DTOPINUsuario } from '../../DTO/DTOPINUsuario' +import { useNavigate } from 'react-router-dom' +import { AxiosError } from 'axios' + +export interface IPINProps {} + +export default function PIN(props: IPINProps) { + const navigate = useNavigate() + const [User, setUser] = useState(() => { + const stickyValue = window.localStorage.getItem('User') + return stickyValue !== null ? JSON.parse(stickyValue) : '' + }) + const [Usuario, setUsuario] = useState(User) + const [PIN, setPIN] = useState('') + const [show, setShow] = useState(false) + const [msg, setMsg] = useState('') + const [header, setHeader] = useState('') + const [msgColor, setMsgColor] = useState('primary') + + const validatePIN = () => { + if (!PIN.length) { + setShow(true) + setMsg('El campo PIN no puede estar vacio') + setHeader('Error') + return false + } + const data: DTOPINUsuario = { + pin: parseInt(PIN), + usuario: Usuario, + } + console.log(JSON.stringify(data)) + AuthDS.validatePIN(data) + .then((response: any) => { + localStorage.removeItem('User') + localStorage.setItem('PIN', PIN) + navigate('/Reset') + }) + .catch((e: any) => { + setShow(true) + setMsg('PIN invalido!') + setHeader('Error') + return false + }) + } + + return ( +
+ + + + +   + +
+ + + + + ZINC Internacional + + + + + + +   + +
+ + + { + setPIN(e.target.value) + }} + /> + + + +   + +
+
+
+
+ +
+
+
+
+ +   +
+ +
+ ) +} diff --git a/src/Components/Login/ResetCredentials.tsx b/src/Components/Login/ResetCredentials.tsx new file mode 100644 index 0000000..7ee7f03 --- /dev/null +++ b/src/Components/Login/ResetCredentials.tsx @@ -0,0 +1,197 @@ +import React, { FC, useState } from 'react' +import { + Button, + Card, + Col, + Form, + Row, + Toast, + ToastContainer, +} from 'react-bootstrap' +import { MsgInformativo } from '../Utils/Toast/msgInformativo' +import DTOUsuario from '../../DTO/DTOUsuario' +import logo from '../../images/grupo-promax-b.png' +import AuthDS from '../../Services/Auth/Auth.Service' +import { DTOResetPassword } from '../../DTO/DTOResetPassword' + +interface IProps {} + +export default function ResetCredentials(props: IProps) { + const [User, setUser] = useState(() => { + const stickyValue = window.localStorage.getItem('User') + return stickyValue !== null ? JSON.parse(stickyValue) : '' + }) + const [PIN, setPIN] = useState(() => { + const stickyValue = window.localStorage.getItem('PIN') + return stickyValue !== null ? JSON.parse(stickyValue) : '' + }) + const [header, setHeader] = useState('Error!') + const [msgColor, setMsgColor] = useState('primary') + const [showMsg, setShowMsg] = useState(false) + const [msg, setMsg] = useState('') + const [Usuario, setUsuario] = useState(User) + const [Contrasena, setContrasena] = useState('') + const [ConfirmaContrasena, setConfirmaContrasena] = useState('') + const [show, setShow] = useState(false) + + const validaFormulario = () => { + if (Contrasena.length===0 || ConfirmaContrasena.length===0) { + setShow(true) + setMsg('La contraseña no puede estar vacia!') + setHeader('Error') + return + } + if (Contrasena !== ConfirmaContrasena) { + setShow(true) + setMsg('Contraseña no coincide con la confirmacion!') + setHeader('Error') + return + } + const data: DTOResetPassword = { + pin: PIN, + contrasena: Contrasena, + } + AuthDS.resetPassword(data) + .then((response) => { + if (response.status == 200) { + setShow(true) + setMsg('La contraseña se cambio exitosamente!') + setHeader('Confirmacion') + return false + } + }) + .catch((e: Error) => { + setShow(true) + setMsg('Ocurrio un error') + setHeader('Error') + return false + }) + } + + const closeToast = (show: boolean): void => { + setShowMsg(false) + } + + return ( +
+
+ + + + +   + +
+ + + + + ZINC Internacional + + + + + + + Proporcione su nueva contraseña? + + +   + +
+ + + + + + + + { + setContrasena(e.target.value) + }} + /> + + + +   + + + + { + setConfirmaContrasena(e.target.value) + }} + /> + + + +   + +
+
+
+ +
+
+
+
+ +   +
+ +
+ {/* */} +
+ ) +} diff --git a/src/Components/Login/login.tsx b/src/Components/Login/login.tsx index 1c126f9..5760621 100644 --- a/src/Components/Login/login.tsx +++ b/src/Components/Login/login.tsx @@ -14,7 +14,7 @@ import { AxiosError } from 'axios' import { MsgInformativo } from '../Utils/Toast/msgInformativo' import logo from '../../images/GEMCO_mini.png' import Dashboard from '../Dashboard/Dashboard' -import { Alert, Card } from 'react-bootstrap' +import { Alert, Card, Nav } from 'react-bootstrap' export const Login: React.FC<{}> = () => { const dispatch = useDispatch() @@ -30,12 +30,6 @@ export const Login: React.FC<{}> = () => {
{!userLogued ? (
-{/*
- Aviso importante! -

- Proximanate esteremos reunicando el contenido de este servidor de aplicaciones, al nuevo dominio de aplicaciones: https://www.gemcousa.mx -

-
*/}
= () => { type='password' />
+ ¿Olvido contraseña?