1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 02:03:39 +00:00

reorganize project folder structure and remove asp.net dependency

This commit is contained in:
Kyle Spearrin
2016-11-30 23:50:00 -05:00
parent a5b8e703fc
commit b72a52232d
94 changed files with 76 additions and 330 deletions

View File

@@ -0,0 +1,9 @@
angular
.module('bit.tools')
.controller('toolsAuditsController', function ($scope, apiService, $uibModalInstance, toastr, $analytics) {
$analytics.eventTrack('toolsAuditsController', { category: 'Modal' });
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
});

View File

@@ -0,0 +1,42 @@
angular
.module('bit.tools')
.controller('toolsController', function ($scope, $uibModal, apiService, toastr, authService) {
$scope.import = function () {
$uibModal.open({
animation: true,
templateUrl: 'app/tools/views/toolsImport.html',
controller: 'toolsImportController',
size: 'sm'
});
};
$scope.$on('toolsImport', function (event, args) {
$scope.import();
});
$scope.export = function () {
$uibModal.open({
animation: true,
templateUrl: 'app/tools/views/toolsExport.html',
controller: 'toolsExportController',
size: 'sm'
});
};
$scope.$on('toolsExport', function (event, args) {
$scope.export();
});
$scope.audits = function () {
$uibModal.open({
animation: true,
templateUrl: 'app/tools/views/toolsAudits.html',
controller: 'toolsAuditsController'
});
};
$scope.$on('toolsAudits', function (event, args) {
$scope.audits();
});
});

View File

@@ -0,0 +1,73 @@
angular
.module('bit.tools')
.controller('toolsExportController', function ($scope, apiService, authService, $uibModalInstance, cryptoService, cipherService, $q, toastr, $analytics) {
$analytics.eventTrack('toolsExportController', { category: 'Modal' });
$scope.export = function (model) {
$scope.startedExport = true;
apiService.sites.list({ expand: ['folder'] }, function (sites) {
try {
var decSites = cipherService.decryptSites(sites.Data);
var exportSites = [];
for (var i = 0; i < decSites.length; i++) {
var site = {
name: decSites[i].name,
uri: decSites[i].uri,
username: decSites[i].username,
password: decSites[i].password,
notes: decSites[i].notes,
folder: decSites[i].folder ? decSites[i].folder.name : null
};
exportSites.push(site);
}
var csvString = Papa.unparse(exportSites);
var csvBlob = new Blob([csvString]);
if (window.navigator.msSaveOrOpenBlob) { // IE hack. ref http://msdn.microsoft.com/en-us/library/ie/hh779016.aspx
window.navigator.msSaveBlob(csvBlob, makeFileName());
}
else {
var a = window.document.createElement('a');
a.href = window.URL.createObjectURL(csvBlob, { type: 'text/plain' });
a.download = makeFileName();
document.body.appendChild(a);
a.click(); // IE: "Access is denied". ref: https://connect.microsoft.com/IE/feedback/details/797361/ie-10-treats-blob-url-as-cross-origin-and-denies-access
document.body.removeChild(a);
}
$analytics.eventTrack('Exported Data');
toastr.success('Your data has been exported. Check your browser\'s downloads folder.', 'Success!');
$scope.close();
}
catch (err) {
toastr.error('Something went wrong. Please try again.', 'Error!');
$scope.close();
}
}, function () {
toastr.error('Something went wrong. Please try again.', 'Error!');
$scope.close();
});
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
function makeFileName() {
var now = new Date();
var dateString =
now.getFullYear() + '' + padNumber(now.getMonth() + 1, 2) + '' + padNumber(now.getDate(), 2) +
padNumber(now.getHours(), 2) + '' + padNumber(now.getMinutes(), 2) +
padNumber(now.getSeconds(), 2);
return 'bitwarden_export_' + dateString + '.csv';
}
function padNumber(number, width, paddingCharacter) {
paddingCharacter = paddingCharacter || '0';
number = number + '';
return number.length >= width ? number : new Array(width - number.length + 1).join(paddingCharacter) + number;
}
});

View File

@@ -0,0 +1,73 @@
angular
.module('bit.tools')
.controller('toolsImportController', function ($scope, $state, apiService, $uibModalInstance, cryptoService, cipherService, toastr, importService, $analytics) {
$analytics.eventTrack('toolsImportController', { category: 'Modal' });
$scope.model = { source: 'local' };
$scope.import = function (model) {
$scope.processing = true;
var file = document.getElementById('file').files[0];
importService.import(model.source, file, importSuccess, importError);
};
function importSuccess(folders, sites, folderRelationships) {
if (!folders.length && !sites.length) {
$uibModalInstance.dismiss('cancel');
toastr.error('Nothing was imported.');
return;
}
apiService.ciphers.import({
folders: cipherService.encryptFolders(folders, cryptoService.getKey()),
sites: cipherService.encryptSites(sites, cryptoService.getKey()),
folderRelationships: folderRelationships
}, function () {
$uibModalInstance.dismiss('cancel');
$state.go('backend.vault').then(function () {
$analytics.eventTrack('Imported Data', { label: $scope.model.source });
toastr.success('Data has been successfully imported into your vault.', 'Import Success');
});
}, importError);
}
function importError(error) {
$analytics.eventTrack('Import Data Failed', { label: $scope.model.source });
$uibModalInstance.dismiss('cancel');
if (error) {
var data = error.data;
if (data && data.ValidationErrors) {
var message = '';
for (var key in data.ValidationErrors) {
if (!data.ValidationErrors.hasOwnProperty(key)) {
continue;
}
for (var i = 0; i < data.ValidationErrors[key].length; i++) {
message += (key + ': ' + data.ValidationErrors[key][i] + ' ');
}
}
if (message !== '') {
toastr.error(message);
return;
}
}
else if (data && data.Message) {
toastr.error(data.Message);
return;
}
else {
toastr.error(error);
return;
}
}
toastr.error('Something went wrong. Try again.', 'Oh No!');
}
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
});

View File

@@ -0,0 +1,2 @@
angular
.module('bit.tools', ['ui.bootstrap', 'toastr']);

View File

@@ -0,0 +1,9 @@
<section class="content-header">
<h1>
Tools
<small>helpful utilities</small>
</h1>
</section>
<section class="content">
Several tools are available in the menu to the left. More tools coming soon...
</section>

View File

@@ -0,0 +1,10 @@
<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" id="auditsModelLabel"><i class="fa fa-search"></i> Audits</h4>
</div>
<div class="modal-body">
Coming soon...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-flat" ng-click="close()">Close</button>
</div>

View File

@@ -0,0 +1,28 @@
<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" id="exportModelLabel"><i class="fa fa-cloud-download"></i> Export</h4>
</div>
<form name="exportForm" ng-submit="exportForm.$valid && export(model)" api-form="exportPromise" ng-show="!startedExport">
<div class="modal-body">
<p>Export all of your vault data in <code>.csv</code> format. Enter your master password to continue.</p>
<div class="callout callout-danger validation-errors" ng-show="exportForm.$errors">
<h4>Errors have occured</h4>
<ul>
<li ng-repeat="e in exportForm.$errors">{{e}}</li>
</ul>
</div>
<div class="form-group" show-errors>
<label for="masterPassword">Master Password</label>
<input type="password" id="masterPassword" name="MasterPasswordHash" ng-model="model.masterPassword" class="form-control"
master-password required api-field ng-model-options="{ 'updateOn': 'blur'}" />
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary btn-flat">Export</button>
<button type="button" class="btn btn-default btn-flat" ng-click="close()">Close</button>
</div>
</form>
<div class="modal-body text-center" ng-show="startedExport">
<p><i class="fa fa-cog fa-spin fa-3x"></i></p>
<p>Please wait. We are now exporting all of your data to a <code>.csv</code> file.</p>
</div>

View File

@@ -0,0 +1,39 @@
<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" id="importModelLabel"><i class="fa fa-cloud-upload"></i> Import</h4>
</div>
<form name="importForm" ng-submit="importForm.$valid && import(model)" ng-show="!processing">
<div class="modal-body">
<div class="form-group">
<label for="source">Source</label>
<select id="source" name="source" class="form-control" ng-model="model.source">
<option value="local">bitwarden (csv)</option>
<option value="lastpass">LastPass (csv)</option>
<option value="chromecsv">Chrome (csv)</option>
<option value="firefoxpasswordexportercsvxml">Firefox Password Exporter (xml)</option>
<option value="safeincloudxml">SafeInCloud (xml)</option>
<option value="safeincloudcsv">SafeInCloud (csv)</option>
<option value="keypassxml">KeyPass (xml)</option>
<option value="padlockcsv">Padlock (csv)</option>
<option value="1password1pif">1Password (1pif)</option>
<option value="upmcsv">Universal Password Manager (csv)</option>
<option value="keepercsv">Keeper (csv)</option>
<option value="passworddragonxml">Password Dragon (xml)</option>
</select>
</div>
<div class="form-group">
<label for="file">File</label>
<input type="file" id="file" name="file" required />
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary btn-flat">
Import
</button>
<button type="button" class="btn btn-default btn-flat" ng-click="close()">Close</button>
</div>
</form>
<div ng-show="processing" class="modal-body text-center">
<p><i class="fa fa-cog fa-spin fa-3x"></i></p>
<p>Please wait. We are now importing all of your data. Do not close this window. You will be redirected to your vault when the import has completed.</p>
</div>