Skip to content
Snippets Groups Projects
Commit 19679113 authored by Ndèye Anna Ndiaye's avatar Ndèye Anna Ndiaye Committed by Adrien Béraud
Browse files

Define Scope for redirecting user to profile page if not admin

Change-Id: I1adbe14b2caf21829c0665a8812a41306190d728
parent 8a9313df
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,8 @@ class Auth {
this.admin = false
this.installed = false
this.uri = ''
this.adminScope = true
this.username = ''
}
setJWT(access_token) {
......@@ -30,6 +32,9 @@ class Auth {
axios(configApiCall(api_path_post_auth_login, "POST", jsonData, null)).then((response) => {
if(response.status == 200){
this.setJWT(response.data['access_token'])
this.adminScope = JSON.parse(atob(response.data['access_token'].split('.')[1])).scope == "ADMIN" ? true : false;
if(!this.adminScope)
this.username= jsonData.username
this.authenticated = true
}
cb()
......@@ -41,6 +46,8 @@ class Auth {
logout(cb) {
this.deleteJWT()
this.authenticated = false
this.username=''
this.adminScope = true
cb()
}
......@@ -101,6 +108,14 @@ class Auth {
return this.admin
}
hasAdminScope(){
return this.adminScope
}
getUsername(){
return this.username
}
isInstalled() {
return this.installed
}
......
......@@ -90,7 +90,7 @@ const styles = {
const useStyles = makeStyles(styles);
export default function UserProfile() {
export default function UserProfile(props) {
const classes = useStyles();
const [value, setValue] = React.useState(0);
......
......@@ -22,6 +22,7 @@ import BusinessOutlinedIcon from '@material-ui/icons/BusinessOutlined';
import MailOutlineIcon from '@material-ui/icons/MailOutline';
import axios from "axios";
import configApiCall from "api.js";
import auth from "auth.js"
import { api_path_get_user_directory_search } from "globalUrls";
import AddCircleOutlineIcon from '@material-ui/icons/AddCircleOutline';
......@@ -84,13 +85,13 @@ export default function Users() {
return new File([u8arr], filename, {type:mime});
}
if (selectedProfile) {
if (selectedProfile || !auth.hasAdminScope()) {
return (
<div>
<Button variant="contained" color="info" href="#contained-buttons" onClick={redirectToUsers}>
{auth.hasAdminScope() && <Button variant="contained" color="info" href="#contained-buttons" onClick={redirectToUsers}>
<KeyboardReturnIcon />
</Button>
<UserProfile />
</Button>}
<UserProfile username={auth.getUsername()}/>
</div>
)
} else {
......
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