1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-14 02:08:50 +02:00

domain rules page setup with new APIs

This commit is contained in:
Kyle Spearrin 2017-01-09 22:26:20 -05:00
parent 74945e03ce
commit 605bdd0ea0
8 changed files with 201 additions and 0 deletions

View File

@ -60,6 +60,10 @@ angular
$scope.$broadcast('settingsSessions');
};
$scope.domains = function () {
$scope.$broadcast('settingsDomains');
};
$scope.delete = function () {
$scope.$broadcast('settingsDelete');
};

View File

@ -36,6 +36,8 @@
putPassword: { url: _apiUri + '/accounts/password', method: 'POST', params: {} },
getProfile: { url: _apiUri + '/accounts/profile', method: 'GET', params: {} },
putProfile: { url: _apiUri + '/accounts/profile', method: 'POST', params: {} },
getDomains: { url: _apiUri + '/accounts/domains', method: 'GET', params: {} },
putDomains: { url: _apiUri + '/accounts/domains', method: 'POST', params: {} },
getTwoFactor: { url: _apiUri + '/accounts/two-factor', method: 'GET', params: {} },
putTwoFactor: { url: _apiUri + '/accounts/two-factor', method: 'POST', params: {} },
postTwoFactorRecover: { url: _apiUri + '/accounts/two-factor-recover', method: 'POST', params: {} },

View File

@ -70,6 +70,18 @@
$scope.sessions();
});
$scope.domains = function () {
$uibModal.open({
animation: true,
templateUrl: 'app/settings/views/settingsDomains.html',
controller: 'settingsDomainsController'
});
};
$scope.$on('settingsDomains', function (event, args) {
$scope.domains();
});
$scope.delete = function () {
$uibModal.open({
animation: true,

View File

@ -0,0 +1,87 @@
angular
.module('bit.settings')
.controller('settingsDomainsController', function ($scope, $state, apiService, $uibModalInstance, toastr, $analytics) {
$analytics.eventTrack('settingsDomainsController', { category: 'Modal' });
$scope.globalEquivalentDomains = [];
$scope.equivalentDomains = [];
apiService.accounts.getDomains({}, function (response) {
if (response.EquivalentDomains) {
for (var i = 0; i < response.EquivalentDomains.length; i++) {
$scope.equivalentDomains.push(response.EquivalentDomains[i].join(', '));
}
}
if (response.GlobalEquivalentDomains) {
for (var globalDomain in response.GlobalEquivalentDomains) {
if (response.GlobalEquivalentDomains.hasOwnProperty(globalDomain)) {
var domain = {
values: response.GlobalEquivalentDomains[globalDomain],
excluded: false,
key: globalDomain
};
if (response.ExcludedGlobalEquivalentDomains) {
for (i = 0; i < response.ExcludedGlobalEquivalentDomains.length; i++) {
if (response.ExcludedGlobalEquivalentDomains[i] === globalDomain) {
domain.excluded = true;
break;
}
}
}
$scope.globalEquivalentDomains.push(domain);
}
}
}
});
$scope.toggleExclude = function (globalDomain) {
globalDomain.excluded = !globalDomain.excluded;
}
$scope.customize = function (globalDomain) {
globalDomain.excluded = true;
$scope.equivalentDomains.push(globalDomain.values.join(', '));
}
$scope.delete = function (i) {
$scope.equivalentDomains.splice(i, 1);
}
$scope.submit = function () {
var request = {
ExcludedGlobalEquivalentDomains: [],
EquivalentDomains: []
};
for (var i = 0; i < $scope.globalEquivalentDomains.length; i++) {
if ($scope.globalEquivalentDomains[i].excluded) {
request.ExcludedGlobalEquivalentDomains.push($scope.globalEquivalentDomains[i].key);
}
}
for (i = 0; i < $scope.equivalentDomains.length; i++) {
request.EquivalentDomains.push($scope.equivalentDomains[i].split(' ').join('').split(', '));
}
if (!request.EquivalentDomains.length) {
request.EquivalentDomains = null;
}
if (!request.ExcludedGlobalEquivalentDomains.length) {
request.ExcludedGlobalEquivalentDomains = null;
}
$scope.submitPromise = apiService.accounts.putDomains(request, function (domains) {
$scope.close();
toastr.success('Domains have been updated.', 'Success!');
}).$promise;
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
});

View File

@ -0,0 +1,83 @@
<div class="modal-header">
<button type="button" class="close" ng-click="close()" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title"><i class="fa fa-globe"></i> Domain Rules</h4>
</div>
<form name="domainsForm" ng-submit="domainsForm.$valid && submit()" api-form="submitPromise">
<div class="modal-body">
<p>
If you have the same login across multiple different website domains, you can mark the website as "equivalent".
"Global" domains are ones created for you by bitwarden.
</p>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th colspan="2">Global Equivalent Domains</th>
</tr>
</thead>
<tbody ng-if="globalEquivalentDomains.length">
<tr ng-repeat="globalDomain in globalEquivalentDomains">
<td style="width: 80px; min-width: 80px;">
<button type="button" class="btn btn-link btn-table" uib-tooltip="Exclude"
ng-if="!globalDomain.excluded" ng-click="toggleExclude(globalDomain)">
<i class="fa fa-lg fa-ban"></i>
</button>
<button type="button" class="btn btn-link btn-table" uib-tooltip="Include"
ng-if="globalDomain.excluded" ng-click="toggleExclude(globalDomain)">
<i class="fa fa-lg fa-plus"></i>
</button>
<button type="button" class="btn btn-link btn-table" uib-tooltip="Customize"
ng-click="customize(globalDomain)">
<i class="fa fa-lg fa-cut"></i>
</button>
</td>
<td ng-class="{strike: globalDomain.excluded}">{{globalDomain.values.join(', ')}}</td>
</tr>
</tbody>
<tbody ng-if="!globalEquivalentDomains.length">
<tr>
<td>No domains to list.</td>
</tr>
</tbody>
</table>
</div>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th colspan="2">
Custom Equivalent Domains
<a href="#">
<i class="fa fa-plus"></i> Add New
</a>
</th>
</tr>
</thead>
<tbody ng-if="equivalentDomains.length">
<tr ng-repeat="customDomain in equivalentDomains track by $index">
<td style="width: 75px; min-width: 75px;">
<button type="button" class="btn btn-link btn-table" uib-tooltip="Edit">
<i class="fa fa-lg fa-pencil"></i>
</button>
<button type="button" class="btn btn-link btn-table" uib-tooltip="Delete" ng-click="delete($index)">
<i class="fa fa-lg fa-trash"></i>
</button>
</td>
<td>{{customDomain}}</td>
</tr>
</tbody>
<tbody ng-if="!equivalentDomains.length">
<tr>
<td>No domains to list.</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary btn-flat" ng-disabled="domainsForm.$loading">
<i class="fa fa-refresh fa-spin loading-icon" ng-show="domainsForm.$loading"></i>Save
</button>
<button type="button" class="btn btn-default btn-flat" ng-click="close()">Close</button>
</div>
</form>

View File

@ -79,6 +79,11 @@
<i class="fa fa-circle-o"></i> Two-step Login
</a>
</li>
<li>
<a href="javascript:void(0)" ng-click="domains()">
<i class="fa fa-circle-o"></i> Domain Rules
</a>
</li>
<li>
<a href="javascript:void(0)" ng-click="delete()">
<i class="fa fa-circle-o"></i> Delete Account

View File

@ -125,6 +125,7 @@
<script src="app/settings/settingsChangeEmailController.js"></script>
<script src="app/settings/settingsTwoFactorController.js"></script>
<script src="app/settings/settingsSessionsController.js"></script>
<script src="app/settings/settingsDomainsController.js"></script>
<script src="app/settings/settingsDeleteController.js"></script>
<script src="app/tools/toolsModule.js"></script>

View File

@ -199,3 +199,10 @@ form .btn .loading-icon {
}
}
}
/* Misc */
.strike {
text-decoration: line-through;
color: @text-muted;
}