use existing role checking system
This commit is contained in:
@@ -8,7 +8,10 @@ import Dialog from 'material-ui/Dialog';
|
|||||||
|
|
||||||
import Instance from '../../../components/Connection';
|
import Instance from '../../../components/Connection';
|
||||||
|
|
||||||
const visitReporterRoleKey = "VIRPT";
|
import {
|
||||||
|
loggedUser,
|
||||||
|
visitReporter,
|
||||||
|
} from 'utils/authorization';
|
||||||
|
|
||||||
class Login extends React.Component {
|
class Login extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -77,23 +80,18 @@ class Login extends React.Component {
|
|||||||
let auth = res.data;
|
let auth = res.data;
|
||||||
state.setCookie('token', auth.token, auth.valid_time);
|
state.setCookie('token', auth.token, auth.valid_time);
|
||||||
localStorage.setItem('loggedUser', JSON.stringify(auth.user));
|
localStorage.setItem('loggedUser', JSON.stringify(auth.user));
|
||||||
console.log(auth.user);
|
|
||||||
|
|
||||||
let isAuthUserVisitReporter = false;
|
console.log("....");
|
||||||
if (auth.user.profiles.length > 0){
|
console.log(loggedUser.anyOf(visitReporter));
|
||||||
isAuthUserVisitReporter = (auth.user.profiles[0].key===visitReporterRoleKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
Instance.setToken(auth.token);
|
if (loggedUser.anyOf(visitReporter)){
|
||||||
|
|
||||||
if (isAuthUserVisitReporter) {
|
|
||||||
location.href = '/#/app/form/visit/' + auth.user.useruuid;
|
location.href = '/#/app/form/visit/' + auth.user.useruuid;
|
||||||
}else{
|
}else{
|
||||||
location.href = '/#/app/table/rides';
|
location.href = '/#/app/table/rides';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
console.log("ERRR");
|
|
||||||
console.log(err);
|
|
||||||
state.setState(Object.assign(state.state, {
|
state.setState(Object.assign(state.state, {
|
||||||
message: (err.response.data.message),
|
message: (err.response.data.message),
|
||||||
open: true,
|
open: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user