diff --git a/servicio-usuarios/src/schemas/user.schema.ts b/servicio-usuarios/src/schemas/user.schema.ts index f09a3231..160a5951 100644 --- a/servicio-usuarios/src/schemas/user.schema.ts +++ b/servicio-usuarios/src/schemas/user.schema.ts @@ -39,6 +39,9 @@ export class User { @Prop() number_house?: string; + + @Prop() + token?: string; } export const UserSchema = SchemaFactory.createForClass(User); diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 2015ef45..b9e289a1 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -101,13 +101,14 @@ export class UsersService { let passwordEncriptada = Md5.init(password); if (res[0].password == passwordEncriptada) { resolve(res[0]); + console.log(res[0]) } else { resolve(null); } } }); }); - + console.log(await userReturn); return userReturn; } diff --git a/web-ui/web-react/public/assets/themes/khaki/theme.css b/web-ui/web-react/public/assets/themes/khaki/theme.css index 10393ffd..cbdfe8aa 100644 --- a/web-ui/web-react/public/assets/themes/khaki/theme.css +++ b/web-ui/web-react/public/assets/themes/khaki/theme.css @@ -7156,4 +7156,11 @@ .status.status--1 { background: #565656; color: #f7f9f7; +} + + +.login-wrapper { + display: flex; + flex-direction: column; + align-items: center; } \ No newline at end of file diff --git a/web-ui/web-react/src/App.js b/web-ui/web-react/src/App.js index 46d3b946..01c0e9ac 100644 --- a/web-ui/web-react/src/App.js +++ b/web-ui/web-react/src/App.js @@ -1,6 +1,7 @@ import React, { useState, useEffect, useRef } from 'react'; import classNames from 'classnames'; import { Route, useLocation } from 'react-router-dom'; +import { BrowserRouter, Switch } from 'react-router-dom' import { CSSTransition } from 'react-transition-group'; import { AppTopbar } from './AppTopbar'; @@ -33,7 +34,7 @@ import AdministradoresComunidad from './components/AdministradoresComunidad'; import GuardasSeguridad from './components/GuardasSeguridad'; import Communities from './components/ComunidadViviendas'; import Inquilinos from './components/Inquilinos'; - +import Dashboard2 from './components/Dashboard'; import Crud from './pages/Crud'; import EmptyPage from './pages/EmptyPage'; import TimelineDemo from './pages/TimelineDemo'; @@ -53,6 +54,7 @@ import LogIn from './components/LogIn'; import { PrimeIcons } from 'primereact/api'; import AreasComunes from './components/AreasComunes'; + const App = () => { const [layoutMode, setLayoutMode] = useState('static'); const [layoutColorMode, setLayoutColorMode] = useState('light'); @@ -348,105 +350,26 @@ const App = () => { 'layout-theme-light': layoutColorMode === 'light', }); + + const [token, setToken] = useState(); + + if(!token) { + return + } + + return ( -
- - - -
- -
- -
-
- ( - - )} - /> - - - - - - - - - - - - - - - - - ( - - )} - /> - - - - - - - - - - - - -
- - -
- - - - -
-
+
+

Application

+ + + + + + + +
); }; diff --git a/web-ui/web-react/src/components/Dashboard.js b/web-ui/web-react/src/components/Dashboard.js new file mode 100644 index 00000000..f9016737 --- /dev/null +++ b/web-ui/web-react/src/components/Dashboard.js @@ -0,0 +1,7 @@ +import React from 'react'; + +export default function Dashboard() { + return( +

Dashboard

+ ); +} diff --git a/web-ui/web-react/src/components/LogIn.js b/web-ui/web-react/src/components/LogIn.js index 466bf3d6..29361404 100644 --- a/web-ui/web-react/src/components/LogIn.js +++ b/web-ui/web-react/src/components/LogIn.js @@ -1,48 +1,99 @@ import React, { useState } from 'react'; import { InputText } from 'primereact/inputtext'; +import { Button } from 'primereact/button'; -const LogIn = () => { +import PropTypes from 'prop-types'; - const [email, setEmail] = useState(""); - const [password, setPassword] = useState(""); +const LogIn = ({ setToken }) => { + + let emptyLogin = { + _id: null, + name: '', + email: '', + password: '', + status: '1', + status_text: '', + } - const iniciarSesion = () =>{ + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [errorMessages, setErrorMessages] = useState({}); + const [isSubmitted, setIsSubmitted] = useState(false) + const [login, setLogin] = useState(emptyLogin); - } - + async function loginUser(credentials) { + return fetch('http://localhost:4000/user/loginUser', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(credentials) + }) + .then(data => data.json()) + .then(data => console.log(data.message)) + } - return ( -
-
-
-
Iniciar Sesión
-
-
- - -
-
- - -
+ const handleSubmit = async e => { + e.preventDefault(); + const token = await loginUser({ + email: email, + password: password + }); + setToken(await token); + } - {/* */} -
-
+ const renderErrorMessage = (name) => + name === errorMessages.name && ( +
{errorMessages.message}
+ ); + + const errors = { + email: "coreo requerido", + pass: "contraseña requerida" + }; + + return ( +
+ +
+
+
+
Iniciar Sesión
+
+
+ + setEmail(e.target.value)} + placeholder='Correo electrónico' /> + {renderErrorMessage("email")} +
+
+ + setPassword(e.target.value)} + placeholder='Contraseña' + /> + {renderErrorMessage("password")} +
+ +
-
- - -
- - {/* */} -
+
+ + + {/* */}
); }; +LogIn.propTypes = { + setToken: PropTypes.func.isRequired +} + export default LogIn \ No newline at end of file