access control on orgs pages
This commit is contained in:
parent
77ddc83a04
commit
35e0f27f52
|
@ -232,12 +232,26 @@ angular
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
$state.go('backend.user.vault');
|
$state.go('backend.user.vault');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!authService.isAuthenticated()) {
|
if (!authService.isAuthenticated()) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
authService.logOut();
|
authService.logOut();
|
||||||
$state.go('frontend.login.info');
|
$state.go('frontend.login.info');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// user is guaranteed to be authenticated becuase of previous check
|
||||||
|
if (toState.name.indexOf('backend.org.') > -1 && toParams.orgId) {
|
||||||
|
authService.getUserProfile().then(function (profile) {
|
||||||
|
var orgs = profile.organizations;
|
||||||
|
if (!orgs || !(toParams.orgId in orgs) || orgs[toParams.orgId].status !== 2 ||
|
||||||
|
orgs[toParams.orgId].type === 2) {
|
||||||
|
event.preventDefault();
|
||||||
|
$state.go('backend.user.vault');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
|
@ -7,16 +7,11 @@ angular
|
||||||
|
|
||||||
if ($state.includes('backend.org')) {
|
if ($state.includes('backend.org')) {
|
||||||
authService.getUserProfile().then(function (userProfile) {
|
authService.getUserProfile().then(function (userProfile) {
|
||||||
if (!userProfile.organizations || !userProfile.organizations.length) {
|
if (!userProfile.organizations || !($state.params.orgId in userProfile.organizations)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < userProfile.organizations.length; i++) {
|
$scope.orgProfile = userProfile.organizations[$state.params.orgId];
|
||||||
if (userProfile.organizations[i].id === $state.params.orgId) {
|
|
||||||
$scope.orgProfile = userProfile.organizations[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -93,15 +93,15 @@ angular
|
||||||
};
|
};
|
||||||
|
|
||||||
if (profile.Organizations) {
|
if (profile.Organizations) {
|
||||||
var orgs = [];
|
var orgs = {};
|
||||||
for (var i = 0; i < profile.Organizations.length; i++) {
|
for (var i = 0; i < profile.Organizations.length; i++) {
|
||||||
orgs.push({
|
orgs[profile.Organizations[i].Id] = {
|
||||||
id: profile.Organizations[i].Id,
|
id: profile.Organizations[i].Id,
|
||||||
name: profile.Organizations[i].Name,
|
name: profile.Organizations[i].Name,
|
||||||
key: profile.Organizations[i].Key,
|
key: profile.Organizations[i].Key,
|
||||||
status: profile.Organizations[i].Status,
|
status: profile.Organizations[i].Status,
|
||||||
type: profile.Organizations[i].Type
|
type: profile.Organizations[i].Type
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
_userProfile.organizations = orgs;
|
_userProfile.organizations = orgs;
|
||||||
|
@ -118,8 +118,8 @@ angular
|
||||||
_service.addProfileOrganization = function (org) {
|
_service.addProfileOrganization = function (org) {
|
||||||
return _service.getUserProfile().then(function (profile) {
|
return _service.getUserProfile().then(function (profile) {
|
||||||
if (profile) {
|
if (profile) {
|
||||||
if (!profile.Organizations) {
|
if (!profile.organizations) {
|
||||||
profile.Organizations = [];
|
profile.organizations = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
var o = {
|
var o = {
|
||||||
|
@ -129,7 +129,7 @@ angular
|
||||||
status: 2, // 2 = Confirmed
|
status: 2, // 2 = Confirmed
|
||||||
type: 0 // 0 = Owner
|
type: 0 // 0 = Owner
|
||||||
};
|
};
|
||||||
profile.organizations.push(o);
|
profile.organizations[o.id] = o;
|
||||||
|
|
||||||
_userProfile = profile;
|
_userProfile = profile;
|
||||||
cryptoService.addOrgKey(o.id, o.key);
|
cryptoService.addOrgKey(o.id, o.key);
|
||||||
|
|
|
@ -33,15 +33,18 @@ angular
|
||||||
var orgKeysb64 = {},
|
var orgKeysb64 = {},
|
||||||
_orgKeys = {},
|
_orgKeys = {},
|
||||||
setKey = false;
|
setKey = false;
|
||||||
for (var i = 0; i < orgKeysCt.length; i++) {
|
|
||||||
try {
|
for (var orgId in orgKeysCt) {
|
||||||
var orgKey = _service.rsaDecrypt(orgKeysCt[i].key, privateKey);
|
if (orgKeysCt.hasOwnProperty(orgId)) {
|
||||||
_orgKeys[orgKeysCt[i].id] = orgKey;
|
try {
|
||||||
orgKeysb64[orgKeysCt[i].id] = forge.util.encode64(orgKey);
|
var orgKey = _service.rsaDecrypt(orgKeysCt[orgId].key, privateKey);
|
||||||
setKey = true;
|
_orgKeys[orgId] = orgKey;
|
||||||
}
|
orgKeysb64[orgId] = forge.util.encode64(orgKey);
|
||||||
catch (e) {
|
setKey = true;
|
||||||
console.log('Cannot set org key ' + i + '. Decryption failed.');
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.log('Cannot set org key ' + i + '. Decryption failed.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,15 +24,20 @@
|
||||||
return authService.getUserProfile();
|
return authService.getUserProfile();
|
||||||
}).then(function (profile) {
|
}).then(function (profile) {
|
||||||
if (profile && profile.organizations) {
|
if (profile && profile.organizations) {
|
||||||
var orgs = [];
|
var orgs = [],
|
||||||
for (var i = 0; i < profile.organizations.length; i++) {
|
setFirstOrg = false;
|
||||||
orgs.push({
|
|
||||||
id: profile.organizations[i].id,
|
|
||||||
name: profile.organizations[i].name
|
|
||||||
});
|
|
||||||
|
|
||||||
if (i === 0) {
|
for (var i in profile.organizations) {
|
||||||
$scope.model.organizationId = profile.organizations[i].id;
|
if (profile.organizations.hasOwnProperty(i)) {
|
||||||
|
orgs.push({
|
||||||
|
id: profile.organizations[i].id,
|
||||||
|
name: profile.organizations[i].name
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!setFirstOrg) {
|
||||||
|
setFirstOrg = true;
|
||||||
|
$scope.model.organizationId = profile.organizations[i].id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue