segunda forma de inicio de sesión, realizad

This commit is contained in:
Mariela 2022-08-09 17:04:40 -06:00
parent e56665ff79
commit e059363d53
4 changed files with 42 additions and 25 deletions

View File

@ -53,7 +53,7 @@ class LoginLocalStorage extends Component {
cookies.set('name', user.name, { path: "/" }); cookies.set('name', user.name, { path: "/" });
cookies.set('email', user.email, { path: "/" }); cookies.set('email', user.email, { path: "/" });
alert(`Bienvenido ${user.name}`); alert(`Bienvenido ${user.name}`);
window.location.href = "./"; window.location.href = "/";
} else { } else {
alert('El usuario o la contraseña no son correctos'); alert('El usuario o la contraseña no son correctos');
} }
@ -68,7 +68,7 @@ class LoginLocalStorage extends Component {
componentDidMount() { componentDidMount() {
if (cookies.get('email')) { if (cookies.get('email')) {
window.location.href = "./"; window.location.href = "/";
} }
} }
@ -106,7 +106,7 @@ class LoginLocalStorage extends Component {
<div className="field col-12 "> <div className="field col-12 ">
<label htmlFor="password">Contraseña</label> <label htmlFor="password">Contraseña</label>
<InputText id="password" <InputText id="password"
type="text" type="password"
name="password" name="password"
onChange={this.handleChange} onChange={this.handleChange}
placeholder='Contraseña' placeholder='Contraseña'

View File

@ -5,8 +5,9 @@ import AdministradoresSistema from '../components/AdministradoresSistema';
import Communities from '../components/ComunidadViviendas'; import Communities from '../components/ComunidadViviendas';
import Dashboard from '../templates/Dashboard'; import Dashboard from '../templates/Dashboard';
import { BrowserRouter, Switch, Route } from 'react-router-dom'; import { BrowserRouter, Switch, Route } from 'react-router-dom';
const cookies = new Cookies(); import { AppMenu } from '../AppMenu';
const cookies = new Cookies();
const menu = [ const menu = [
{ {
@ -16,38 +17,54 @@ const menu = [
{ label: 'Administradores del sistema', icon: 'pi pi-fw pi-id-card', to: '/administradoresSistema' }, { 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: 'Administradores de comunidad', icon: 'pi pi-fw pi-id-card', to: '/administradoresComunidad' },
{ label: 'Comunidadades', icon: 'pi pi-fw pi-id-card', to: '/comunidadesViviendas' }, { label: 'Comunidadades', icon: 'pi pi-fw pi-id-card', to: '/comunidadesViviendas' },
{ label: 'Log out', icon: 'pi pi-fw pi-id-card', to: '/logOut' }
] ]
}, },
]; ];
const handleLogout = () => {
cookies.remove('id', { path: "/" });
cookies.remove('email', { path: "/" });
cookies.remove('name', { path: "/" });
window.location.href = '/';
}
class MenuAdmin extends Component { class MenuAdmin extends Component {
state = { constructor(){
super()
this.state = {
layoutColorMode: 'light', layoutColorMode: 'light',
layoutMode: 'static', layoutMode: 'static',
menuClick: false,
mobileTopbarMenuClick: false,
overlayMenuActive: false,
mobileMenuActive: false
}
} }
onSidebarClick = () => {
this.setState({
menuClick: true
})
}
onMenuItemClick = (event) => {
if (!event.item.items) {
this.state.overlayMenuActive = false;
this.state.mobileMenuActive = false;
this.setState({
overlayMenuActive: true,
mobileMenuActive:false
})
}
}
cerrarSesion = () => { cerrarSesion = () => {
cookies.remove('id', { path: "/" }); cookies.remove('id', { path: "/" });
cookies.remove('email', { path: "/" }); cookies.remove('email', { path: "/" });
cookies.remove('name', { path: "/" }); cookies.remove('name', { path: "/" });
window.location.href = '/'; window.location.href = '/login';
} }
componentDidMount() { componentDidMount() {
if (!cookies.get('email')) { if (!cookies.get('email')) {
window.location.href = "./"; window.location.href = "/login";
} }
} }
@ -56,8 +73,10 @@ class MenuAdmin extends Component {
return ( return (
<div> <div>
Menu Principal Menu Principal
<div className="layout-sidebar" onClick={onSidebarClick}> <div className="layout-sidebar" onClick={this.onSidebarClick}>
<AppMenu model={menu} onMenuItemClick={onMenuItemClick} layoutColorMode={layoutColorMode} /> <AppMenu model={menu} onMenuItemClick={this.onMenuItemClick} layoutColorMode={this.state.layoutColorMode} />
<button type="button" onClick={() => this.cerrarSesion()}>Logout</button>
</div> </div>
<div className="layout-main-container"> <div className="layout-main-container">
@ -66,12 +85,10 @@ class MenuAdmin extends Component {
<Route exact path="/administradoresSistema" component={AdministradoresSistema} /> <Route exact path="/administradoresSistema" component={AdministradoresSistema} />
<Route path="/administradoresComunidad" component={AdministradoresComunidad} /> <Route path="/administradoresComunidad" component={AdministradoresComunidad} />
<Route path="/comunidadesViviendas" component={Communities} /> <Route path="/comunidadesViviendas" component={Communities} />
<button onClick={this.cerrarSesion}>Logout</button>
</div> </div>
</div> </div>
<br /> <br />
<button onClick={() => this.cerrarSesion()}>Cerrar Sesión</button>
</div> </div>
); );
} }

View File

@ -13,7 +13,7 @@ class Menu extends Component {
componentDidMount() { componentDidMount() {
if(!cookies.get('email')){ if(!cookies.get('email')){
window.location.href="./"; window.location.href="./login";
} }
} }

View File

@ -11,7 +11,7 @@ function Routes() {
<BrowserRouter> <BrowserRouter>
<Switch> <Switch>
<Route exact path="/login" component={LoginLocalStorage}/> <Route exact path="/login" component={LoginLocalStorage}/>
<Route exact path="/" component={Menu}/> <Route exact path="/" component={MenuAdmin}/>
</Switch> </Switch>
</BrowserRouter> </BrowserRouter>
); );