use existing role checking system

This commit is contained in:
GotPPay
2018-05-28 15:44:44 +02:00
parent 4099c9231a
commit 4070ca2b29

View File

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