Skip to content
Snippets Groups Projects
Commit 57d1a42c authored by lfr20's avatar lfr20
Browse files

Added a logic to prevent the unauthorized user have acess to the admin area

parent 404bad79
No related branches found
No related tags found
4 merge requests!57Merge of develop into master,!56Fixed buttons reportar, seguir, compartilhar, guardar and entrar (in comments...,!40merge admin into develop,!37Merge sistema_admin into Update_Admin_System
...@@ -16,7 +16,7 @@ GNU Affero General Public License for more details. ...@@ -16,7 +16,7 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/ along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/
import React, { useState } from 'react'; import React, { useState, useContext } from 'react';
import clsx from 'clsx'; import clsx from 'clsx';
import { makeStyles } from '@material-ui/core/styles'; import { makeStyles } from '@material-ui/core/styles';
import Drawer from '@material-ui/core/Drawer'; import Drawer from '@material-ui/core/Drawer';
...@@ -29,6 +29,8 @@ import MenuIcon from '@material-ui/icons/Menu'; ...@@ -29,6 +29,8 @@ import MenuIcon from '@material-ui/icons/Menu';
import Fab from '@material-ui/core/Fab'; import Fab from '@material-ui/core/Fab';
import { TabsItens } from '../AdminLabelTabs/LabelTabs'; import { TabsItens } from '../AdminLabelTabs/LabelTabs';
import DisplayContent from '../../Components/Components/DisplayContent'; import DisplayContent from '../../Components/Components/DisplayContent';
import { Store } from '../../../Store';
import Unauthorized from '../../Components/Components/Unauthorized';
const useStyles = makeStyles({ const useStyles = makeStyles({
list: { list: {
...@@ -50,10 +52,15 @@ const fab = { ...@@ -50,10 +52,15 @@ const fab = {
export default function Admin() { export default function Admin() {
const { state, dispatch } = useContext(Store);
const classes = useStyles(); const classes = useStyles();
const [state, setState] = React.useState({
//State of the Drawer
const [State, setState] = React.useState({
left: false left: false
}); });
const [IndexIcon, setIndexIcon] = useState(0); const [IndexIcon, setIndexIcon] = useState(0);
{/**************** Controlls the state of the Drawer ****************/ } {/**************** Controlls the state of the Drawer ****************/ }
...@@ -62,7 +69,7 @@ export default function Admin() { ...@@ -62,7 +69,7 @@ export default function Admin() {
return; return;
} }
setState({ ...state, [anchor]: open }); setState({ ...State, [anchor]: open });
}; };
{/**************** Dsiplay the itens of the Drawer ****************/ } {/**************** Dsiplay the itens of the Drawer ****************/ }
...@@ -79,35 +86,71 @@ export default function Admin() { ...@@ -79,35 +86,71 @@ export default function Admin() {
{TabsItens.map((text, index) => ( {TabsItens.map((text, index) => (
<ListItem button key={text.label} onClick={() => setIndexIcon(index)}> <ListItem button key={text.label} onClick={() => setIndexIcon(index)}>
<IconButton> <IconButton>
<DisplayIcon label={text.label} /> <DisplayIcon i={index} />
</IconButton> </IconButton>
<ListItemText primary={text.label} /> <ListItemText primary={text.label} />
</ListItem> </ListItem>
))} ))}
</List> </List>
</div> </div>
); );
return ( // return (
<div> // <div>
{/**************** Begin of the Drawer ****************/} // {/**************** Begin of the Drawer ****************/}
<React.Fragment> // <React.Fragment>
<Drawer anchor={'left'} open={state['left']} onClose={toggleDrawer('left', false)}> // <Drawer anchor={'left'} open={State['left']} onClose={toggleDrawer('left', false)}>
{list('left')} // {list('left')}
</Drawer> // </Drawer>
</React.Fragment> // </React.Fragment>
{/**************** End of the Drawer****************/} // {/**************** End of the Drawer****************/}
{/**************** Begin of the Content ****************/} // {/**************** Begin of the Content ****************/}
<div style={{ paddingTop: '2em', paddingLeft: '2em', paddingRight: '2em', paddingBottom: '2em', backgroundColor: ' #D3D3D3' }}> // <div style={{ paddingTop: '2em', paddingLeft: '2em', paddingRight: '2em', paddingBottom: '2em', backgroundColor: ' #D3D3D3' }}>
<DisplayContent selectedIcon={IndexIcon} /> // <DisplayContent i={IndexIcon} />
</div> // </div>
{/**************** End of the Content ****************/} // {/**************** End of the Content ****************/}
{/**************** FLoating action Button ****************/} // {/**************** FLoating action Button ****************/}
<Fab color="primary" aria-label="add" style={fab} onClick={toggleDrawer('left', true)}> // <Fab color="primary" aria-label="add" style={fab} onClick={toggleDrawer('left', true)}>
<MenuIcon /> // <MenuIcon />
</Fab> // </Fab>
</div> // </div>
); // );
if (state.userIsLoggedIn) {
var obj = { ...(state.currentUser.roles)[0] }
if (obj.id === 3 || obj.id === 7) {
return (
<div>
{/**************** Begin of the Drawer ****************/}
<React.Fragment>
<Drawer anchor={'left'} open={State['left']} onClose={toggleDrawer('left', false)}>
{list('left')}
</Drawer>
</React.Fragment>
{/**************** End of the Drawer****************/}
{/**************** Begin of the Content ****************/}
<div style={{ paddingTop: '2em', paddingLeft: '2em', paddingRight: '2em', paddingBottom: '2em', backgroundColor: ' #D3D3D3' }}>
<DisplayContent i={IndexIcon} />
</div>
{/**************** End of the Content ****************/}
{/**************** FLoating action Button ****************/}
<Fab color="primary" aria-label="add" style={fab} onClick={toggleDrawer('left', true)}>
<MenuIcon />
</Fab>
</div>
);
} else {
return (
<Unauthorized/>
)
}
} else {
return (
<Unauthorized/>
)
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment