1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

setting up more models and services

This commit is contained in:
Kyle Spearrin
2016-09-03 12:07:30 -04:00
parent c39aab4ee7
commit c3053ea3a7
7 changed files with 323 additions and 95 deletions

View File

@@ -1,15 +1,15 @@
var SiteRequest = function () {
this.folderId = null;
this.name = null;
this.uri = null;
this.username = null;
this.password = null;
this.notes = null;
this.favorite = false;
var SiteRequest = function (site) {
this.folderId = site.folderId;
this.name = site.name ? site.name.encryptedString : null;
this.uri = site.uri ? site.uri.encryptedString : null;
this.username = site.username ? site.username.encryptedString : null;
this.password = site.password ? site.password.encryptedString : null;
this.notes = site.notes ? site.notes.encryptedString : null;
this.favorite = site.favorite;
};
var FolderRequest = function () {
this.name = null;
var FolderRequest = function (folder) {
this.name = folder.name ? folder.name.encryptedString : null;
};
var TokenRequest = function () {

41
src/models/dataModels.js Normal file
View File

@@ -0,0 +1,41 @@
var FolderData = function (response, userId) {
var data = null;
if (response instanceof FolderResponse) {
data = response;
}
else if (response instanceof CipherResponse) {
data = response.Data;
}
else {
throw 'unsupported instance';
}
this.id = response.Id;
this.userId = userId;
this.name = data.Name;
this.revisionDate = response.RevisionDate;
};
var SiteData = function (response, userId) {
var data = null;
if (response instanceof SiteResponse) {
data = response;
}
else if (response instanceof CipherResponse) {
data = response.Data;
}
else {
throw 'unsupported instance';
}
this.id = response.Id;
this.folderId = response.FolderId;
this.userId = userId;
this.name = data.Name;
this.uri = data.Uri;
this.username = data.Username;
this.password = data.Password;
this.notes = data.Notes;
this.favorite = response.Favorite;
this.revisionDate = response.RevisionDate;
};

View File

@@ -0,0 +1,37 @@
var CipherString = function (encryptedString) {
this.encryptedString = encryptedString;
if (encryptedString) {
this.initializationVector = this.encryptedString.split('|')[0];
this.cipherText = this.encryptedString.split('|')[1];
}
};
!function () {
var _decryptedValue = null;
CipherString.prototype.decrypt = function (callback) {
if (!_decryptedValue) {
var cryptoService = chrome.extension.getBackgroundPage().cryptoService;
_decryptedValue = cryptoService.Decrypt(this);
}
return _decryptedValue;
};
}();
var Site = function (obj) {
this.id = obj.id;
this.folderId = obj.folderId;
this.name = new CipherString(obj.name);
this.uri = new CipherString(obj.uri);
this.username = new CipherString(obj.username);
this.password = new CipherString(obj.password);
this.notes = new CipherString(obj.notes);
this.favorite = new obj.favorite;
};
var Folder = function (obj) {
this.id = obj.id;
this.name = new CipherString(obj.name);
};