1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-31 08:20:37 +01:00

Add/edit equivalent domains

This commit is contained in:
Kyle Spearrin 2017-01-10 21:38:53 -05:00
parent 39559e203a
commit 828b5d8703
6 changed files with 88 additions and 9 deletions

View File

@ -47,6 +47,11 @@
postDelete: { url: _apiUri + '/accounts/delete', method: 'POST', params: {} }
});
_service.settings = $resource(_apiUri + '/settings', {}, {
getDomains: { url: _apiUri + '/settings/domains', method: 'GET', params: {} },
putDomains: { url: _apiUri + '/settings/domains', method: 'POST', params: {} },
});
_service.auth = $resource(_apiUri + '/auth', {}, {
token: { url: _apiUri + '/auth/token', method: 'POST', params: {} },
tokenTwoFactor: { url: _apiUri + '/auth/token/two-factor', method: 'POST', params: {} }

View File

@ -0,0 +1,18 @@
angular
.module('bit.vault')
.controller('settingsAddEditEquivalentDomainController', function ($scope, $uibModalInstance, $analytics, domainIndex, domains) {
$analytics.eventTrack('settingsAddEditEquivalentDomainController', { category: 'Modal' });
$scope.domains = domains;
$scope.index = domainIndex;
$scope.submit = function (form) {
$analytics.eventTrack((domainIndex ? 'Edited' : 'Added') + ' Equivalent Domain');
$uibModalInstance.close({ domains: $scope.domains, index: domainIndex });
};
$scope.close = function () {
$uibModalInstance.dismiss('close');
};
});

View File

@ -1,13 +1,13 @@
angular
.module('bit.settings')
.controller('settingsDomainsController', function ($scope, $state, apiService, $uibModalInstance, toastr, $analytics) {
.controller('settingsDomainsController', function ($scope, $state, apiService, $uibModalInstance, toastr, $analytics, $uibModal) {
$analytics.eventTrack('settingsDomainsController', { category: 'Modal' });
$scope.globalEquivalentDomains = [];
$scope.equivalentDomains = [];
apiService.accounts.getDomains({}, function (response) {
apiService.settings.getDomains({}, function (response) {
if (response.EquivalentDomains) {
for (var i = 0; i < response.EquivalentDomains.length; i++) {
$scope.equivalentDomains.push(response.EquivalentDomains[i].join(', '));
@ -38,7 +38,29 @@
$scope.equivalentDomains.splice(i, 1);
}
$scope.submit = function () {
$scope.addEdit = function (i) {
var addEditModal = $uibModal.open({
animation: true,
templateUrl: 'app/settings/views/settingsAddEditEquivalentDomain.html',
controller: 'settingsAddEditEquivalentDomainController',
size: 'sm',
resolve: {
domainIndex: function () { return i; },
domains: function () { return i !== null ? $scope.equivalentDomains[i] : null; }
}
});
addEditModal.result.then(function (returnObj) {
if (returnObj.index !== null) {
$scope.equivalentDomains[returnObj.index] = returnObj.domains;
}
else {
$scope.equivalentDomains.push(returnObj.domains);
}
});
}
$scope.save = function () {
var request = {
ExcludedGlobalEquivalentDomains: [],
EquivalentDomains: []
@ -51,7 +73,7 @@
}
for (i = 0; i < $scope.equivalentDomains.length; i++) {
request.EquivalentDomains.push($scope.equivalentDomains[i].split(' ').join('').split(', '));
request.EquivalentDomains.push($scope.equivalentDomains[i].split(' ').join('').split(','));
}
if (!request.EquivalentDomains.length) {
@ -62,7 +84,7 @@
request.ExcludedGlobalEquivalentDomains = null;
}
$scope.submitPromise = apiService.accounts.putDomains(request, function (domains) {
$scope.submitPromise = apiService.settings.putDomains(request, function (domains) {
$scope.close();
toastr.success('Domains have been updated.', 'Success!');
}).$promise;

View File

@ -0,0 +1,33 @@
<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> {{index ? 'Edit Equivalent Domain' : 'Add Equivalent Domain'}}</h4>
</div>
<form name="domainAddEditForm" ng-submit="domainAddEditForm.$valid && submit(domainAddEditForm)">
<div class="modal-body">
<div class="callout callout-danger validation-errors" ng-show="domainAddEditForm.$errors">
<h4>Errors have occured</h4>
<ul>
<li ng-repeat="e in domainAddEditForm.$errors">{{e}}</li>
</ul>
</div>
<p>
Enter a list of domains separated by commas.
</p>
<div class="form-group" show-errors>
<label for="name">Domains</label> <span>*</span>
<textarea id="domains" name="Domains" ng-model="domains" class="form-control"
style="height: 100px;" required></textarea>
<p class="help-block">
Only "base" domains are allowed. Do not enter subdomains.
For example, enter "google.com" instead of "www.google.com".
</p>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary btn-flat">
Submit
</button>
<button type="button" class="btn btn-default btn-flat" ng-click="close()">Close</button>
</div>
</form>

View File

@ -2,7 +2,7 @@
<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">
<form name="domainsForm" ng-submit="domainsForm.$valid && save()" 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".
@ -47,7 +47,7 @@
<tr>
<th colspan="2">
Custom Equivalent Domains
<a href="#">
<a href="javascript:void(0)" ng-click="addEdit(null)">
<i class="fa fa-plus"></i> Add New
</a>
</th>
@ -55,8 +55,8 @@
</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">
<td style="width: 80px; min-width: 80px;">
<button type="button" class="btn btn-link btn-table" uib-tooltip="Edit" ng-click="addEdit($index)">
<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)">

View File

@ -126,6 +126,7 @@
<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/settingsAddEditEquivalentDomainController.js"></script>
<script src="app/settings/settingsDeleteController.js"></script>
<script src="app/tools/toolsModule.js"></script>