mirror of
https://github.com/bitwarden/desktop.git
synced 2024-11-14 10:16:02 +01:00
Cipher service setup. Bind data for site view.
This commit is contained in:
parent
e83d09ff6d
commit
0402ec648d
77
src/popup/app/services/cipherService.js
Normal file
77
src/popup/app/services/cipherService.js
Normal file
@ -0,0 +1,77 @@
|
||||
angular
|
||||
.module('bit.services')
|
||||
|
||||
.factory('cipherService', function (cryptoService, $q) {
|
||||
var _service = {};
|
||||
|
||||
_service.encryptSite = function (site, callback) {
|
||||
var model = {};
|
||||
|
||||
cryptoService.encrypt(site.name, function (nameCipherString) {
|
||||
model.name = nameCipherString;
|
||||
cryptoService.encrypt(site.uri, function (uriCipherString) {
|
||||
model.uri = uriCipherString;
|
||||
cryptoService.encrypt(site.username, function (usernameCipherString) {
|
||||
model.username = usernameCipherString;
|
||||
cryptoService.encrypt(site.password, function (passwordCipherString) {
|
||||
model.password = passwordCipherString;
|
||||
cryptoService.encrypt(site.notes, function (notesCipherString) {
|
||||
model.notes = notesCipherString;
|
||||
callback(model);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_service.decryptSite = function (site) {
|
||||
var model = {
|
||||
id: site.id,
|
||||
folderId: site.folderId,
|
||||
favorite: site.favorite
|
||||
};
|
||||
|
||||
return $q(function (resolve, reject) {
|
||||
decrypt(site.name).then(function (obj) {
|
||||
model.name = obj.val;
|
||||
return decrypt(site.uri);
|
||||
}).then(function (obj) {
|
||||
model.uri = obj.val;
|
||||
return decrypt(site.username);
|
||||
}).then(function (obj) {
|
||||
model.username = obj.val;
|
||||
return decrypt(site.password);
|
||||
}).then(function (obj) {
|
||||
model.password = obj.val;
|
||||
return decrypt(site.notes);
|
||||
}).then(function (obj) {
|
||||
model.notes = obj.val;
|
||||
resolve(model);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_service.decrypt = decrypt;
|
||||
|
||||
function decrypt(cipherString, index) {
|
||||
return $q(function (resolve, reject) {
|
||||
if (!cipherString) {
|
||||
resolve({
|
||||
val: null,
|
||||
index: index
|
||||
});
|
||||
}
|
||||
else {
|
||||
cipherString.decrypt(function (decVal) {
|
||||
resolve({
|
||||
val: decVal,
|
||||
index: index
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return _service;
|
||||
});
|
@ -1,13 +1,13 @@
|
||||
angular
|
||||
.module('bit.vault')
|
||||
|
||||
.controller('vaultAddSiteController', function ($scope, siteService, cryptoService) {
|
||||
.controller('vaultAddSiteController', function ($scope, siteService, cipherService) {
|
||||
$scope.site = {
|
||||
folderId: null
|
||||
};
|
||||
|
||||
$scope.createSite = function (model) {
|
||||
encryptSite(model, function (siteModel) {
|
||||
cipherService.encryptSite(model, function (siteModel) {
|
||||
var site = new Site(siteModel, true);
|
||||
siteService.save(site, function () {
|
||||
$scope.close();
|
||||
@ -18,24 +18,4 @@
|
||||
$scope.close = function () {
|
||||
$scope.parentScope.closeAddSite();
|
||||
};
|
||||
|
||||
function encryptSite(model, callback) {
|
||||
var siteModel = {};
|
||||
cryptoService.encrypt(model.name, function (nameCipherString) {
|
||||
siteModel.name = nameCipherString;
|
||||
cryptoService.encrypt(model.uri, function (uriCipherString) {
|
||||
siteModel.uri = uriCipherString;
|
||||
cryptoService.encrypt(model.username, function (usernameCipherString) {
|
||||
siteModel.username = usernameCipherString;
|
||||
cryptoService.encrypt(model.password, function (passwordCipherString) {
|
||||
siteModel.password = passwordCipherString;
|
||||
cryptoService.encrypt(model.notes, function (notesCipherString) {
|
||||
siteModel.notes = notesCipherString;
|
||||
callback(siteModel);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -1,10 +1,11 @@
|
||||
angular
|
||||
.module('bit.vault')
|
||||
|
||||
.controller('vaultController', function ($scope, $ionicModal, siteService, folderService, $q) {
|
||||
.controller('vaultController', function ($scope, $ionicModal, siteService, folderService, $q, cipherService) {
|
||||
$scope.parentScope = $scope;
|
||||
$scope.sites = [];
|
||||
$scope.folders = [];
|
||||
$scope.focusedSiteId = null;
|
||||
|
||||
$scope.$on("$ionicView.enter", function (event, data) {
|
||||
loadVault();
|
||||
@ -29,7 +30,7 @@
|
||||
id: folders[i].id
|
||||
});
|
||||
|
||||
var folderNamePromise = decrypt(sites[i].name, i);
|
||||
var folderNamePromise = cipherService.decrypt(sites[i].name, i);
|
||||
promises.push(folderNamePromise);
|
||||
folderNamePromise.then(function (obj) {
|
||||
decFolders[obj.index].name = obj.val;
|
||||
@ -43,13 +44,13 @@
|
||||
favorite: sites[j].favorite
|
||||
});
|
||||
|
||||
var namePromise = decrypt(sites[j].name, j);
|
||||
var namePromise = cipherService.decrypt(sites[j].name, j);
|
||||
promises.push(namePromise);
|
||||
namePromise.then(function (obj) {
|
||||
decSites[obj.index].name = obj.val;
|
||||
});
|
||||
|
||||
var usernamePromise = decrypt(sites[j].username, j);
|
||||
var usernamePromise = cipherService.decrypt(sites[j].username, j);
|
||||
promises.push(usernamePromise);
|
||||
usernamePromise.then(function (obj) {
|
||||
decSites[obj.index].username = obj.val;
|
||||
@ -64,26 +65,8 @@
|
||||
});
|
||||
}
|
||||
|
||||
function decrypt(cipherString, index) {
|
||||
return $q(function (resolve, reject) {
|
||||
if (!cipherString) {
|
||||
resolve({
|
||||
val: null,
|
||||
index: index
|
||||
});
|
||||
}
|
||||
else {
|
||||
cipherString.decrypt(function (decString) {
|
||||
resolve({
|
||||
val: decString,
|
||||
index: index
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$scope.viewSite = function (site) {
|
||||
$scope.focusedSiteId = site.id;
|
||||
$ionicModal.fromTemplateUrl('app/vault/views/vaultViewSite.html', {
|
||||
scope: $scope,
|
||||
animation: 'slide-in-up'
|
||||
@ -94,6 +77,7 @@
|
||||
};
|
||||
|
||||
$scope.editSite = function (site) {
|
||||
$scope.focusedSiteId = site.id;
|
||||
$ionicModal.fromTemplateUrl('app/vault/views/vaultEditSite.html', {
|
||||
scope: $scope,
|
||||
animation: 'slide-in-up'
|
||||
@ -119,10 +103,12 @@
|
||||
|
||||
$scope.closeViewSite = function () {
|
||||
$scope.viewSiteModal.hide();
|
||||
$scope.focusedSiteId = null;
|
||||
};
|
||||
|
||||
$scope.closeEditSite = function () {
|
||||
$scope.editSiteModal.hide();
|
||||
$scope.focusedSiteId = null;
|
||||
};
|
||||
|
||||
$scope.$on('modal.hidden', function () {
|
||||
|
@ -1,13 +1,16 @@
|
||||
angular
|
||||
.module('bit.vault')
|
||||
|
||||
.controller('vaultViewSiteController', function ($scope, siteService, cryptoService) {
|
||||
$scope.site = {
|
||||
folderId: null
|
||||
};
|
||||
.controller('vaultViewSiteController', function ($scope, siteService, cipherService) {
|
||||
$scope.site = null;
|
||||
siteService.get($scope.parentScope.focusedSiteId, function (site) {
|
||||
cipherService.decryptSite(site).then(function (model) {
|
||||
$scope.site = model;
|
||||
});
|
||||
});
|
||||
|
||||
$scope.editSite = function () {
|
||||
|
||||
// TODO
|
||||
};
|
||||
|
||||
$scope.close = function () {
|
||||
|
@ -5,6 +5,35 @@
|
||||
<button class="button button-clear button-primary" ng-click="editSite()">Edit</button>
|
||||
</ion-header-bar>
|
||||
<ion-content>
|
||||
View site
|
||||
<div class="list">
|
||||
<div class="item item-divider">
|
||||
Site Information
|
||||
</div>
|
||||
<div class="item">
|
||||
<div>Name</div>
|
||||
{{site.name}}
|
||||
</div>
|
||||
<div class="item">
|
||||
<div>Website</div>
|
||||
{{site.uri}}
|
||||
</div>
|
||||
<div class="item">
|
||||
<div>Username</div>
|
||||
{{site.username}}
|
||||
</div>
|
||||
<div class="item">
|
||||
<div>Password</div>
|
||||
{{site.password}}
|
||||
</div>
|
||||
<div class="item item-divider">
|
||||
Notes
|
||||
</div>
|
||||
<div class="item">
|
||||
{{site.notes}}
|
||||
</div>
|
||||
<div class="item item-divider">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</ion-content>
|
||||
</ion-modal-view>
|
||||
|
@ -22,6 +22,7 @@
|
||||
<script src="app/services/servicesModule.js"></script>
|
||||
<script src="app/services/backgroundService.js"></script>
|
||||
<script src="app/services/loginService.js"></script>
|
||||
<script src="app/services/cipherService.js"></script>
|
||||
|
||||
<script src="app/accounts/accountsModule.js"></script>
|
||||
<script src="app/accounts/accountsLoginController.js"></script>
|
||||
|
Loading…
Reference in New Issue
Block a user