iniciar sesion funcionalidad frontend

This commit is contained in:
Mariela 2022-08-09 13:42:47 -06:00
parent 8e98739f99
commit 770bbfed43
7 changed files with 424 additions and 35 deletions

View File

@ -7118,3 +7118,10 @@
.p-button.p-button-danger:enabled:focus { .p-button.p-button-danger:enabled:focus {
box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #f7a2a2, 0 1px 2px 0 black; box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #f7a2a2, 0 1px 2px 0 black;
} }
.login-wrapper {
display: flex;
flex-direction: column;
align-items: center;
}

View File

@ -1,8 +1,7 @@
import React, { useState, useEffect, useRef } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { Route, useLocation, BrowserRouter} from 'react-router-dom'; import { Route, useLocation } from 'react-router-dom';
import { CSSTransition } from 'react-transition-group'; import { CSSTransition } from 'react-transition-group';
import Routes from './routes/Routes'
import { AppTopbar } from './AppTopbar'; import { AppTopbar } from './AppTopbar';
import { AppFooter } from './AppFooter'; import { AppFooter } from './AppFooter';
@ -51,7 +50,6 @@ import './assets/demo/Demos.scss';
import './assets/layout/layout.scss'; import './assets/layout/layout.scss';
import './App.scss'; import './App.scss';
import LogIn from './components/LogIn'; import LogIn from './components/LogIn';
import LoginLocalStorage from './components/LoginLocalStorage';
const App = () => { const App = () => {
const [layoutMode, setLayoutMode] = useState('static'); const [layoutMode, setLayoutMode] = useState('static');
@ -70,10 +68,6 @@ const App = () => {
window.location.reload(); window.location.reload();
} }
PrimeReact.ripple = true; PrimeReact.ripple = true;
let menuClick = false; let menuClick = false;
@ -301,10 +295,59 @@ const App = () => {
}); });
return ( return (
<div> <div className={wrapperClass} onClick={onWrapperClick}>
<BrowserRouter> <Tooltip ref={copyTooltipRef} target=".block-action-copy" position="bottom" content="Copied to clipboard" event="focus" />
<Routes />
</BrowserRouter> <AppTopbar onToggleMenuClick={onToggleMenuClick} layoutColorMode={layoutColorMode}
mobileTopbarMenuActive={mobileTopbarMenuActive} onMobileTopbarMenuClick={onMobileTopbarMenuClick} onMobileSubTopbarMenuClick={onMobileSubTopbarMenuClick} />
<div className="layout-sidebar" onClick={onSidebarClick}>
<AppMenu model={menu} onMenuItemClick={onMenuItemClick} layoutColorMode={layoutColorMode} />
</div>
<div className="layout-main-container">
<div className="layout-main">
<Route path="/" exact render={() => <Dashboard colorMode={layoutColorMode} location={location} />} />
<Route path="/formlayout" component={FormLayoutDemo} />
<Route path="/input" component={InputDemo} />
<Route path="/floatlabel" component={FloatLabelDemo} />
<Route path="/invalidstate" component={InvalidStateDemo} />
<Route path="/button" component={ButtonDemo} />
<Route path="/table" component={TableDemo} />
<Route path="/list" component={ListDemo} />
<Route path="/tree" component={TreeDemo} />
<Route path="/panel" component={PanelDemo} />
<Route path="/overlay" component={OverlayDemo} />
<Route path="/media" component={MediaDemo} />
<Route path="/menu" component={MenuDemo} />
<Route path="/messages" component={MessagesDemo} />
<Route path="/blocks" component={BlocksDemo} />
<Route path="/icons" component={IconsDemo} />
<Route path="/file" component={FileDemo} />
<Route path="/chart" render={() => <ChartDemo colorMode={layoutColorMode} location={location} />} />
<Route path="/misc" component={MiscDemo} />
<Route path="/timeline" component={TimelineDemo} />
<Route path="/crud" component={Crud} />
<Route path="/empty" component={EmptyPage} />
<Route path="/documentation" component={Documentation} />
<Route path="/administradoresSistema" component={AdministradoresSistema} />
<Route path="/administradoresComunidad" component={AdministradoresComunidad} />
<Route path="/guardasSeguridad" component={GuardasSeguridad} />
<Route path="/comunidadesViviendas" component={Communities} />
<Route path="/inquilinos" component={Inquilinos} />
<Route path="/logIn" component={LogIn} />
<button onClick={handleLogout}>Logout</button>
</div>
<AppFooter layoutColorMode={layoutColorMode} />
</div>
<AppConfig rippleEffect={ripple} onRippleEffect={onRipple} inputStyle={inputStyle} onInputStyleChange={onInputStyleChange}
layoutMode={layoutMode} onLayoutModeChange={onLayoutModeChange} layoutColorMode={layoutColorMode} onColorModeChange={onColorModeChange} />
<CSSTransition classNames="layout-mask" timeout={{ enter: 200, exit: 200 }} in={mobileMenuActive} unmountOnExit>
<div className="layout-mask p-component-overlay"></div>
</CSSTransition>
</div> </div>
); );

View File

@ -2,6 +2,7 @@ import DashboardAdmin from "./DashboardAdmin";
import React, { Component, Fragment } from 'react'; import React, { Component, Fragment } from 'react';
import Cookies from 'universal-cookie'; import Cookies from 'universal-cookie';
import { InputText } from 'primereact/inputtext'; import { InputText } from 'primereact/inputtext';
import { Button } from 'primereact/button';
const baseUrl = "http://localhost:4000/user/loginUser"; const baseUrl = "http://localhost:4000/user/loginUser";
const cookies = new Cookies(); const cookies = new Cookies();
@ -10,9 +11,10 @@ const cookies = new Cookies();
class LoginLocalStorage extends Component { class LoginLocalStorage extends Component {
state = { state = {
form: { form: {
username: '', email: '',
password: '' password: ''
} },
errorMessages:{}
} }
handleChange = async e => { handleChange = async e => {
@ -30,6 +32,8 @@ class LoginLocalStorage extends Component {
password: this.state.form.password password: this.state.form.password
} }
console.log(data);
await fetch(baseUrl, { await fetch(baseUrl, {
cache: 'no-cache', cache: 'no-cache',
method: 'POST', method: 'POST',
@ -47,7 +51,7 @@ class LoginLocalStorage extends Component {
const user = response.message; const user = response.message;
cookies.set('id', user._id, { path: "/" }); cookies.set('id', user._id, { path: "/" });
cookies.set('name', user.name, { path: "/" }); cookies.set('name', user.name, { path: "/" });
cookies.set('email', user.username, { path: "/" }); cookies.set('email', user.email, { path: "/" });
alert(`Bienvenido ${user.name}`); alert(`Bienvenido ${user.name}`);
window.location.href = "./menu"; window.location.href = "./menu";
} else { } else {
@ -68,31 +72,54 @@ class LoginLocalStorage extends Component {
} }
} }
renderErrorMessage = (name) =>
name === this.state.errorMessages.name && (
<div className="error">{this.state.errorMessages.message}</div>
);
errors = {
email: "Correo requerido",
pass: "Contraseña requerida"
};
render() { render() {
return ( return (
<Fragment> <Fragment>
<div className="grid">
<div className="col-12"> <div className="login-wrapper">
<div className="grid form justify-content-center my-5">
<div className="col-5">
<div className="card"> <div className="card">
<h5>Iniciar Sesión</h5> <h5>Iniciar Sesión</h5>
<div className="p-fluid formgrid grid"> <div className="p-fluid formgrid grid">
<div className="field col-12"> <div className="field col-12">
<label htmlFor="correo">Correo electrónico</label> <label htmlFor="email">Correo electrónico</label>
<InputText id="correo" type="email" placeholder='Correo electrónico' onChange={this.handleChange} /> <InputText id="email"
type="email"
name="email"
onChange={this.handleChange}
placeholder='Correo electrónico' />
{this.renderErrorMessage("email")}
</div> </div>
<div className="field col-12 "> <div className="field col-12 ">
<label htmlFor="contrasenna">Contraseña</label> <label htmlFor="password">Contraseña</label>
<InputText id="contrasenna" type="password" placeholder='Contraseña' onChange={this.handleChange} /> <InputText id="password"
type="text"
name="password"
onChange={this.handleChange}
placeholder='Contraseña'
/>
{this.renderErrorMessage("password")}
</div> </div>
<button className="btn btn-primary" onClick={() => this.iniciarSesion()}>Iniciar Sesión</button> <Button label="Iniciar sesión" type="button" onClick={() => this.iniciarSesion()}></Button>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</Fragment> </Fragment>

View File

@ -0,0 +1,308 @@
import React, { Component } from 'react';
import Cookies from 'universal-cookie';
import AdministradoresComunidad from './AdministradoresComunidad';
import AdministradoresSistema from './AdministradoresSistema';
import Communities from './components/ComunidadViviendas';
class MenuAdmin extends Component {
state = {
layoutMode
}
}
const [layoutMode, setLayoutMode] = useState('static');
const [layoutColorMode, setLayoutColorMode] = useState('light')
const [inputStyle, setInputStyle] = useState('outlined');
const [ripple, setRipple] = useState(true);
const [staticMenuInactive, setStaticMenuInactive] = useState(false);
const [overlayMenuActive, setOverlayMenuActive] = useState(false);
const [mobileMenuActive, setMobileMenuActive] = useState(false);
const [mobileTopbarMenuActive, setMobileTopbarMenuActive] = useState(false);
const copyTooltipRef = useRef();
const location = useLocation();
const [cookies, setCookies] = useRef();
const handleLogout = () => {
cookies.remove('id', {path: "/"});
cookies.remove('email', {path: "/"});
cookies.remove('name', {path: "/"});
window.location.href='/';
}
useEffect(() => {
if(!cookies.get('email')){
window.location.href="./";
}
}, [])
PrimeReact.ripple = true;
let menuClick = false;
let mobileTopbarMenuClick = false;
useEffect(() => {
if (mobileMenuActive) {
addClass(document.body, "body-overflow-hidden");
} else {
removeClass(document.body, "body-overflow-hidden");
}
}, [mobileMenuActive]);
useEffect(() => {
copyTooltipRef && copyTooltipRef.current && copyTooltipRef.current.updateTargetEvents();
}, [location]);
const onInputStyleChange = (inputStyle) => {
setInputStyle(inputStyle);
}
const onRipple = (e) => {
PrimeReact.ripple = e.value;
setRipple(e.value)
}
const onLayoutModeChange = (mode) => {
setLayoutMode(mode)
}
const onColorModeChange = (mode) => {
setLayoutColorMode(mode)
}
const onWrapperClick = (event) => {
if (!menuClick) {
setOverlayMenuActive(false);
setMobileMenuActive(false);
}
if (!mobileTopbarMenuClick) {
setMobileTopbarMenuActive(false);
}
mobileTopbarMenuClick = false;
menuClick = false;
}
const onToggleMenuClick = (event) => {
menuClick = true;
if (isDesktop()) {
if (layoutMode === 'overlay') {
if (mobileMenuActive === true) {
setOverlayMenuActive(true);
}
setOverlayMenuActive((prevState) => !prevState);
setMobileMenuActive(false);
}
else if (layoutMode === 'static') {
setStaticMenuInactive((prevState) => !prevState);
}
}
else {
setMobileMenuActive((prevState) => !prevState);
}
event.preventDefault();
}
const onSidebarClick = () => {
menuClick = true;
}
const onMobileTopbarMenuClick = (event) => {
mobileTopbarMenuClick = true;
setMobileTopbarMenuActive((prevState) => !prevState);
event.preventDefault();
}
const onMobileSubTopbarMenuClick = (event) => {
mobileTopbarMenuClick = true;
event.preventDefault();
}
const onMenuItemClick = (event) => {
if (!event.item.items) {
setOverlayMenuActive(false);
setMobileMenuActive(false);
}
}
const isDesktop = () => {
return window.innerWidth >= 992;
}
const menu = [
{
label: 'Home',
items: [
{ label: 'Dashboard', icon: 'pi pi-fw pi-home', to: '/' },
{ label: 'Administradores del sistema', icon: 'pi pi-fw pi-id-card', to: '/administradoresSistema' },
{ label: 'Administradores de comunidad', icon: 'pi pi-fw pi-id-card', to: '/administradoresComunidad' },
{ label: 'Guardas de seguridad', icon: 'pi pi-fw pi-id-card', to: '/guardasSeguridad' },
{ label: 'Comunidadades', icon: 'pi pi-fw pi-id-card', to: '/comunidadesViviendas' },
{ label: 'Inquilinos', icon: 'pi pi-fw pi-id-card', to: '/inquilinos' },
{ label: 'Log in', icon: 'pi pi-fw pi-id-card', to: '/logIn' },
{ label: 'Log out', icon: 'pi pi-fw pi-id-card', to: '/logOut' }
]
},
{
label: 'UI Components', icon: 'pi pi-fw pi-sitemap',
items: [
{ label: 'Form Layout', icon: 'pi pi-fw pi-id-card', to: '/formlayout' },
{ label: 'Input', icon: 'pi pi-fw pi-check-square', to: '/input' },
{ label: "Float Label", icon: "pi pi-fw pi-bookmark", to: "/floatlabel" },
{ label: "Invalid State", icon: "pi pi-fw pi-exclamation-circle", to: "invalidstate" },
{ label: 'Button', icon: 'pi pi-fw pi-mobile', to: '/button' },
{ label: 'Table', icon: 'pi pi-fw pi-table', to: '/table' },
{ label: 'List', icon: 'pi pi-fw pi-list', to: '/list' },
{ label: 'Tree', icon: 'pi pi-fw pi-share-alt', to: '/tree' },
{ label: 'Panel', icon: 'pi pi-fw pi-tablet', to: '/panel' },
{ label: 'Overlay', icon: 'pi pi-fw pi-clone', to: '/overlay' },
{ label: "Media", icon: "pi pi-fw pi-image", to: "/media" },
{ label: 'Menu', icon: 'pi pi-fw pi-bars', to: '/menu' },
{ label: 'Message', icon: 'pi pi-fw pi-comment', to: '/messages' },
{ label: 'File', icon: 'pi pi-fw pi-file', to: '/file' },
{ label: 'Chart', icon: 'pi pi-fw pi-chart-bar', to: '/chart' },
{ label: 'Misc', icon: 'pi pi-fw pi-circle-off', to: '/misc' },
]
},
{
label: 'UI Blocks',
items: [
{ label: 'Free Blocks', icon: 'pi pi-fw pi-eye', to: '/blocks', badge: "NEW" },
{ label: 'All Blocks', icon: 'pi pi-fw pi-globe', url: 'https://www.primefaces.org/primeblocks-react' }
]
},
{
label: 'Icons',
items: [
{ label: 'PrimeIcons', icon: 'pi pi-fw pi-prime', to: '/icons' }
]
},
{
label: 'Pages', icon: 'pi pi-fw pi-clone',
items: [
{ label: 'Crud', icon: 'pi pi-fw pi-user-edit', to: '/crud' },
{ label: 'Timeline', icon: 'pi pi-fw pi-calendar', to: '/timeline' },
{ label: 'Empty', icon: 'pi pi-fw pi-circle-off', to: '/empty' }
]
},
{
label: 'Menu Hierarchy', icon: 'pi pi-fw pi-search',
items: [
{
label: 'Submenu 1', icon: 'pi pi-fw pi-bookmark',
items: [
{
label: 'Submenu 1.1', icon: 'pi pi-fw pi-bookmark',
items: [
{ label: 'Submenu 1.1.1', icon: 'pi pi-fw pi-bookmark' },
{ label: 'Submenu 1.1.2', icon: 'pi pi-fw pi-bookmark' },
{ label: 'Submenu 1.1.3', icon: 'pi pi-fw pi-bookmark' },
]
},
{
label: 'Submenu 1.2', icon: 'pi pi-fw pi-bookmark',
items: [
{ label: 'Submenu 1.2.1', icon: 'pi pi-fw pi-bookmark' },
{ label: 'Submenu 1.2.2', icon: 'pi pi-fw pi-bookmark' }
]
},
]
},
{
label: 'Submenu 2', icon: 'pi pi-fw pi-bookmark',
items: [
{
label: 'Submenu 2.1', icon: 'pi pi-fw pi-bookmark',
items: [
{ label: 'Submenu 2.1.1', icon: 'pi pi-fw pi-bookmark' },
{ label: 'Submenu 2.1.2', icon: 'pi pi-fw pi-bookmark' },
{ label: 'Submenu 2.1.3', icon: 'pi pi-fw pi-bookmark' },
]
},
{
label: 'Submenu 2.2', icon: 'pi pi-fw pi-bookmark',
items: [
{ label: 'Submenu 2.2.1', icon: 'pi pi-fw pi-bookmark' },
{ label: 'Submenu 2.2.2', icon: 'pi pi-fw pi-bookmark' }
]
}
]
}
]
}
];
const addClass = (element, className) => {
if (element.classList)
element.classList.add(className);
else
element.className += ' ' + className;
}
const removeClass = (element, className) => {
if (element.classList)
element.classList.remove(className);
else
element.className = element.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
}
const wrapperClass = classNames('layout-wrapper', {
'layout-overlay': layoutMode === 'overlay',
'layout-static': layoutMode === 'static',
'layout-static-sidebar-inactive': staticMenuInactive && layoutMode === 'static',
'layout-overlay-sidebar-active': overlayMenuActive && layoutMode === 'overlay',
'layout-mobile-sidebar-active': mobileMenuActive,
'p-input-filled': inputStyle === 'filled',
'p-ripple-disabled': ripple === false,
'layout-theme-light': layoutColorMode === 'light'
});
class Menu extends Component {
cerrarSesion=()=>{
cookies.remove('id', {path: "/"});
cookies.remove('email', {path: "/"});
cookies.remove('name', {path: "/"});
window.location.href='/';
}
componentDidMount() {
if(!cookies.get('email')){
window.location.href="./app";
}
}
render() {
console.log('id: '+ cookies.get('id'));
console.log('name: '+cookies.get('name'));
console.log('email: '+cookies.get('email'));
return (
<div>
Menu Principal
<div className="layout-main-container">
<div className="layout-main">
<Route path="/administradoresSistema" component={AdministradoresSistema} />
<Route path="/administradoresComunidad" component={AdministradoresComunidad} />
<Route path="/comunidadesViviendas" component={Communities} />
<button onClick={this.cerrarSesion}>Logout</button>
</div>
</div>
<br />
<button onClick={()=>this.cerrarSesion()}>Cerrar Sesión</button>
</div>
);
}
}
export default Menu;

View File

@ -3,14 +3,16 @@ import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import App from './App'; import App from './App';
//import * as serviceWorker from './serviceWorker'; //import * as serviceWorker from './serviceWorker';
import { HashRouter } from 'react-router-dom' import { HashRouter, Route } from 'react-router-dom'
import ScrollToTop from './ScrollToTop'; import ScrollToTop from './ScrollToTop';
import Routes from './routes/Routes';
ReactDOM.render( ReactDOM.render(
<HashRouter> <HashRouter>
<ScrollToTop> <ScrollToTop>
<App /> <Routes/>
</ScrollToTop> </ScrollToTop>
</HashRouter>, </HashRouter>,
document.getElementById('root') document.getElementById('root')

View File

@ -6,8 +6,8 @@ const cookies = new Cookies();
class Menu extends Component { class Menu extends Component {
cerrarSesion=()=>{ cerrarSesion=()=>{
cookies.remove('id', {path: "/"}); cookies.remove('id', {path: "/"});
cookies.remove('name', {path: "/"});
cookies.remove('email', {path: "/"}); cookies.remove('email', {path: "/"});
cookies.remove('name', {path: "/"});
window.location.href='/'; window.location.href='/';
} }

View File

@ -1,9 +1,11 @@
import React from 'react'; import React from 'react';
import {BrowserRouter, Switch, Route} from 'react-router-dom'; import {BrowserRouter, Switch, Route} from 'react-router-dom';
import App from '../App';
import LoginLocalStorage from '../components/LoginLocalStorage'; import LoginLocalStorage from '../components/LoginLocalStorage';
import Menu from '../pages/Menu'; import Menu from '../pages/Menu';
function Routes() { function Routes() {
return ( return (
<BrowserRouter> <BrowserRouter>
<Switch> <Switch>