master
Luis Angel Rendon Arrazola 1 year ago
parent d3c427d01b
commit 8e8f6ac5c4
  1. 703
      package-lock.json
  2. 9
      package.json
  3. 58
      src/App.css
  4. 150
      src/App.tsx
  5. 12
      src/Componentes/AmazonInvoice.tsx
  6. 86
      src/Componentes/Formulario.tsx
  7. 29
      src/Componentes/Home.tsx
  8. 0
      src/Componentes/Tabla.AmazonInvoice.ts
  9. 4
      src/Contants/jsonwebtoken.d.ts
  10. 38
      src/Contants/token.ts
  11. 5
      src/DTos/DTOLogin.ts
  12. 5
      src/DTos/DTOLoginReset.ts
  13. 113
      src/HojasDeEstilo/Formulario.css
  14. 44
      src/HojasDeEstilo/Home.css
  15. 26
      src/HojasDeEstilo/Navbar.css
  16. BIN
      src/Imagenes/descarga.png
  17. BIN
      src/Imagenes/fondo.jpg
  18. 1
      src/logo.svg
  19. 9656
      yarn.lock

703
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -10,10 +10,17 @@
"@types/node": "^16.18.31", "@types/node": "^16.18.31",
"@types/react": "^18.2.6", "@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4", "@types/react-dom": "^18.2.4",
"axios": "^1.4.0",
"bootstrap": "^5.2.3",
"buffer": "^6.0.3",
"jsonwebtoken": "^9.0.0",
"jwt-decode": "^3.1.2",
"react": "^18.2.0", "react": "^18.2.0",
"react-bootstrap": "^2.7.4",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-router-dom": "^6.11.2",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"typescript": "^4.9.5", "typescript": "^5.0.4",
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4"
}, },
"scripts": { "scripts": {

@ -1,38 +1,46 @@
.App { *{
text-align: center;
padding: 0;
margin: 0;
box-sizing: border-box;
} }
.App-logo { html, body{
height: 40vmin; background-color: white;
pointer-events: none;
} }
@media (prefers-reduced-motion: no-preference) { .App {
.App-logo { position: relative;
animation: App-logo-spin infinite 20s linear; height: 100vh;
} width: 100vw;
background-image: url(${ImagenFondo});
background-size: cover;
background-position: center;
background-repeat: no-repeat;
} }
.App-header {
background-color: #282c34;
min-height: 100vh; .Formulario{
display: flex; height: 550px;
min-width: 600px;
display:flex;
flex-wrap: wrap;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
} }
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from { .Home{
transform: rotate(0deg); height: 550px;
} min-width: 600px;
to { display:flex;
transform: rotate(360deg); flex-wrap: wrap;
} flex-direction: column;
align-items: center;
justify-content: center;
} }

@ -1,26 +1,136 @@
import React from 'react'; import React, { useEffect, useState } from 'react';
import logo from './logo.svg'; import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom';
import './App.css'; import axios from 'axios';
import DTOLogin from './DTos/DTOLogin';
import DTOLoginReset from './DTos/DTOLoginReset';
import Home from './Componentes/Home';
import Formulario from './Componentes/Formulario';
import AmazonInvoice from './Componentes/AmazonInvoice';
import ImagenLogo from './Imagenes/descarga.png';
import ImagenFondo from './Imagenes/fondo.jpg';
axios.interceptors.response.use(
function (response) {
const newToken = response.data.token;
if (newToken) {
localStorage.setItem('jwtToken', newToken);
axios.defaults.headers.common['Authorization'] = `Bearer ${newToken}`;
}
return response;
},
function (error) {
if (error.response && error.response.status === 401) {
window.location.href = '/login';
}
return Promise.reject(error);
}
);
const App: React.FC = () => {
const [user, setUser] = useState<any>(null);
const [isLoading, setIsLoading] = useState<boolean>(false);
const handleLogin = async (Usuario: string, Contrasena: string) => {
setIsLoading(true);
try {
if (!Usuario || !Contrasena) {
alert('Ingrese un usuario y contraseña válidos');
setIsLoading(false);
return;
}
const data: DTOLogin = { usuario: Usuario, contrasena: Contrasena };
const response = await axios.post("https://localhost:5051/api/Usuario/Loging", data);
if (response.status === 200) {
setUser(response.data);
alert('Inicio de sesión correcto');
localStorage.setItem('jwtToken', response.data.token);
}
} catch (error) {
console.log(error);
} finally {
setIsLoading(false);
}
};
useEffect(() => {
const checkTokenValidity = async () => {
const token = localStorage.getItem('jwtToken');
if (token) {
try {
const response = await axios.get('https://localhost:5051/api/Usuario/Validate', {
headers: {
Authorization: `Bearer ${token}`,
},
});
if (response.status === 200) {
setUser(response.data);
}
} catch (error) {
console.log(error);
handleLogout();
}
}
};
checkTokenValidity();
}, []);
const handleLogout = () => {
setUser(null);
localStorage.removeItem('jwtToken');
};
const handlePasswordReset = async (Usuario: string, Contrasena: string, NuevaContrasena: string) => {
setIsLoading(true);
try {
const data1: DTOLoginReset = { usuario: Usuario, contrasena: Contrasena, nuevacontrasena: NuevaContrasena };
const response = await axios.put("https://localhost:5051/api/Usuario/ResetPassword", data1);
if (response.status === 200) {
alert('Contraseña restablecida correctamente');
}
} catch (error) {
console.log(error);
alert('Se ha producido un error al restablecer la contraseña.');
} finally {
setIsLoading(false);
}
};
const handleLoginFormSubmit = (userObject: any) => {
handleLogin(userObject.usuario, userObject.contrasena);
};
function App() {
return ( return (
<div className="App"> <div className='App' style={{ backgroundImage: `url(${ImagenFondo})`, backgroundSize: 'cover', backgroundPosition: 'center', backgroundRepeat: 'no-repeat', height: '100vh' }}>
<header className="App-header"> <Router>
<img src={logo} className="App-logo" alt="logo" /> {isLoading ? (
<p> <p>Loading...</p>
Edit <code>src/App.tsx</code> and save to reload. ) : (
</p> <Routes>
<a <Route
className="App-link" path='/login'
href="https://reactjs.org" element={
target="_blank" !user ? (
rel="noopener noreferrer" <Formulario handleLogin={handleLoginFormSubmit} handlePasswordReset={handlePasswordReset} />
> ) : (
Learn React <Navigate to='/home' />
</a> )
</header> }
/>
<Route path='/home' element={user ? <Home user={user} handleLogout={handleLogout} /> : <Navigate to='/login' />} />
<Route path='/amazon-invoice' element={user ? <AmazonInvoice /> : <Navigate to='/login' />} />
<Route path='/*' element={<Navigate to='/login' />} />
</Routes>
)}
{!user && (
<div className='logo'>
<img className='ILogo' src={ImagenLogo} alt='Logo de Imagem' />
</div>
)}
</Router>
</div> </div>
); );
} };
export default App; export default App;

@ -0,0 +1,12 @@
import React from 'react';
const AmazonInvoice: React.FC = () => {
return (
<div>
<h1>Bienvenidos a Amazon Invoiceee</h1>
</div>
);
};
export default AmazonInvoice;

@ -0,0 +1,86 @@
import '../HojasDeEstilo/Formulario.css';
import { useState } from 'react';
interface FormularioProps {
handleLogin: (userObject: any) => void;
handlePasswordReset: (usuario: string, contrasena: string, nuevaContrasena: string) => void;
}
function Formulario({ handleLogin, handlePasswordReset }: FormularioProps) {
const [usuario, setUsuario] = useState('');
const [contrasena, setContrasena] = useState('');
const [resetMode, setResetMode] = useState(false);
const [resetError, setResetError] = useState(false);
const [nuevaContrasena, setNuevaContrasena] = useState('');
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (resetMode) {
if (usuario === '' || contrasena === '' || nuevaContrasena === '') {
setResetError(true);
alert('Todos los campos son obligatorios');
return;
}
setResetError(false);
handlePasswordReset(usuario, contrasena, nuevaContrasena);
} else {
if (usuario === '' || contrasena === '') {
alert('Todos los campos son obligatorios');
return;
}
const userObject = {
usuario,
contrasena
};
handleLogin(userObject);
}
};
return (
<section>
<form className='Formulario' onSubmit={handleSubmit}>
<h2>Usuario</h2>
<input
type='text'
id='usuario-input' // ID para el cuadro de texto del usuario
value={usuario}
onChange={(e) => setUsuario(e.target.value)}
/>
<h3>Contraseña</h3>
<input
type='password'
id='contrasena-input' // ID para el cuadro de texto de la contraseña
value={contrasena}
onChange={(e) => setContrasena(e.target.value)}
/>
{resetMode && (
<>
<h3>Nueva Contraseña</h3>
<input
type='password'
id='nuevaContrasena-input' // ID para el cuadro de texto de la nueva contraseña
value={nuevaContrasena}
onChange={(e) => setNuevaContrasena(e.target.value)}
/>
<button type="submit" id='submit-reset-button' className='primary'>
Restablecer Contraseña
</button>
</>
)}
{!resetMode && (
<button type="submit" id='submit-login-button' className='primary'>
Iniciar Sesión
</button>
)}
</form>
<button onClick={() => setResetMode(!resetMode)} id='reset-button'>
{resetMode ? 'Cancelar Restablecer Contraseña' : 'Restablecer Contraseña'}
</button>
{resetError && <p>Todos los campos son obligatorios para restablecer la contraseña</p>}
</section>
);
}
export default Formulario;

@ -0,0 +1,29 @@
import React from 'react';
import { Navbar, Nav } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import '../HojasDeEstilo/Navbar.css'
interface HomeProps {
user: any;
handleLogout: () => void;
}
const Home: React.FC<HomeProps> = ({ user, handleLogout }) => {
return (
<div className="home-container">
<h1>BIENVENIDOS AL HOME</h1>
<Navbar bg="dark" variant="dark" className="navbar-custom">
<Nav.Link href="#amazon">No Le Click</Nav.Link>
<Nav className="ml-auto">
<Nav.Link as={Link} to="/amazon-invoice">
Amazon Invoice
</Nav.Link>
</Nav>
<Nav.Link onClick={handleLogout}>Cerrar Sesión</Nav.Link>
</Navbar>
</div>
);
};
export default Home;

@ -0,0 +1,4 @@
declare module 'jsonwebtoken' {
export function decode(token: string): any;
}

@ -0,0 +1,38 @@
import axios from 'axios';
axios.interceptors.response.use(
function (response) {
const newToken = response.data.token;
if (newToken) {
localStorage.setItem('jwtToken', newToken); // Guardar el token en el localStorage
}
return response;
},
function (error) {
// Manejar el error aquí
if (error.response && error.response.status === 401) {
// Si el estado de respuesta es 401 (No autorizado), redirigir al formulario de inicio de sesión
window.location.href = '/login';
}
return Promise.reject(error);
}
);
// axios.interceptors.response.use(
// function (response) {
// const newToken = response.data.token;
// if (newToken) {
// localStorage.setItem('jwtToken', newToken);
// }
// return response;
// },
// function (error) {
// // Manejar el error aquí
// if (error.response && error.response.status === 401) {
// // Si el estado de respuesta es 401 (No autorizado), redirigir al formulario de inicio de sesión
// window.location.href = '/login';
// }
// return Promise.reject(error);
// }
// );

@ -0,0 +1,5 @@
export default interface DTOLogin {
usuario: string,
contrasena: string,
}

@ -0,0 +1,5 @@
export default interface DTOLoginReset {
usuario: string,
contrasena: string,
nuevacontrasena: string
}

@ -0,0 +1,113 @@
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.contenedor {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.logo {
height: 100px;
min-width: 600px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-bottom: 20px; /* Añade un margen inferior para separar el logotipo de los campos de entrada */
}
.Formulario {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 0rem;
padding: 1rem;
border-radius: 1rem;
margin-top: 5px;
}
h2 {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 1rem;
font-size: 1rem;
color: white;
margin-top: 2rem; /* Ajusta el valor según tu necesidad */
}
h3 {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 1rem;
font-size: 1rem;
color: white;
}
input {
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
font-family: Lato, sans-serif;
height: 50px;
}
#submit-login-button {
background-color: greenyellow;
border: none;
color: #000000;
padding: 12px 24px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 14px 0px;
cursor: pointer;
border-radius: 8px;
transition: background-color 0.3s ease;
height: 10%;
width: 237.5px;
}
button {
background-color: rgb(132, 130, 238);
border: none;
color: white;
padding: 12px 24px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 14px 0px;
cursor: pointer;
border-radius: 8px;
transition: background-color 0.3s ease;
height: 10%;
width: 237.5px;
}

@ -0,0 +1,44 @@
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.Home{
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 1rem;
background-color: green;
padding: 2rem;
border-radius: 1rem;
}
h1{
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 1rem;
font-size: 3rem;
background-color: rgb(255, 255, 255);
text-shadow: 1px 1px #FFFFFF;
}
button{
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 1rem;
font-size: 3rem;
background-color: rgb(255, 255, 255);
text-shadow: 1px 1px #FFFFFF;
}

@ -0,0 +1,26 @@
.navbar-custom {
background-color: #4054bd;
color: #000;
position: fixed;
top: 0;
width: 100%;
z-index: 10;
border-bottom: 1px solid #4f3817;
border-radius: 0;
}
.navbar-custom .navbar-brand {
font-weight: bold;
font-size: 24px;
}
.navbar-custom .nav-link {
color: #f5f5f5;
font-weight: bold;
font-size: 18px;
margin-right: 15px;
}
.navbar-custom .nav-link:hover {
color: #888888;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 515 KiB

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save