mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 05:13:29 +00:00
api models and services
This commit is contained in:
@@ -17,6 +17,9 @@
|
|||||||
"node_modules/sjcl/sjcl.js",
|
"node_modules/sjcl/sjcl.js",
|
||||||
"node_modules/sjcl/core/cbc.js",
|
"node_modules/sjcl/core/cbc.js",
|
||||||
"node_modules/sjcl/core/bitArray.js",
|
"node_modules/sjcl/core/bitArray.js",
|
||||||
|
"models/api/requestModels.js",
|
||||||
|
"models/api/responseModels.js",
|
||||||
|
"services/cryptoService.js",
|
||||||
"services/cryptoService.js",
|
"services/cryptoService.js",
|
||||||
"services/tokenService.js",
|
"services/tokenService.js",
|
||||||
"services/apiService.js",
|
"services/apiService.js",
|
||||||
|
|||||||
47
src/models/api/requestModels.js
Normal file
47
src/models/api/requestModels.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
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 FolderRequest = function () {
|
||||||
|
this.name = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
var TokenRequest = function () {
|
||||||
|
this.email = null;
|
||||||
|
this.masterPasswordHash = null;
|
||||||
|
this.device = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
var RegisterRequest = function () {
|
||||||
|
this.name = null;
|
||||||
|
this.email = null;
|
||||||
|
this.masterPasswordHash = null;
|
||||||
|
this.masterPasswordHint = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
var PasswordHintRequest = function () {
|
||||||
|
this.email = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
var TokenTwoFactorRequest = function () {
|
||||||
|
this.code = null;
|
||||||
|
this.provider = null;
|
||||||
|
this.device = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
var DeviceTokenRequest = function () {
|
||||||
|
this.pushToken = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
var DeviceRequest = function () {
|
||||||
|
this.type = null;
|
||||||
|
this.name = null;
|
||||||
|
this.identifier = null;
|
||||||
|
this.pushToken = null;
|
||||||
|
};
|
||||||
75
src/models/api/responseModels.js
Normal file
75
src/models/api/responseModels.js
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
var CipherResponse = function (response) {
|
||||||
|
this.id = response.Id;
|
||||||
|
this.folderId = response.FolderId;
|
||||||
|
this.type = response.Type;
|
||||||
|
this.favorite = response.favorite;
|
||||||
|
this.data = response.Data;
|
||||||
|
this.revisionDate = response.RevisionDate;
|
||||||
|
};
|
||||||
|
|
||||||
|
var FolderResponse = function (response) {
|
||||||
|
this.id = response.Id;
|
||||||
|
this.name = response.Name;
|
||||||
|
this.revisionDate = response.RevisionDate;
|
||||||
|
};
|
||||||
|
|
||||||
|
var SiteResponse = function (response) {
|
||||||
|
this.id = response.Id;
|
||||||
|
this.folderId = response.FolderId;
|
||||||
|
this.name = response.Name;
|
||||||
|
this.uri = response.Uri;
|
||||||
|
this.username = response.Username;
|
||||||
|
this.password = response.Password;
|
||||||
|
this.notes = response.Notes;
|
||||||
|
this.favorite = response.favorite;
|
||||||
|
this.revisionDate = response.RevisionDate;
|
||||||
|
|
||||||
|
if(response.Folder) {
|
||||||
|
this.folder = new FolderResponse(response.Folder);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var ProfileResponse = function (response) {
|
||||||
|
this.id = response.Id;
|
||||||
|
this.name = response.Name;
|
||||||
|
this.email = response.Email;
|
||||||
|
this.masterPasswordHint = response.MasterPasswordHint;
|
||||||
|
this.culture = response.Culture;
|
||||||
|
this.twoFactorEnabled = response.TwoFactorEnabled;
|
||||||
|
};
|
||||||
|
|
||||||
|
var TokenResponse = function (response) {
|
||||||
|
this.token = response.Token;
|
||||||
|
|
||||||
|
if (response.Profile) {
|
||||||
|
this.profile = new ProfileResponse(response.Profile);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var ListResponse = function (data) {
|
||||||
|
this.Data = data;
|
||||||
|
};
|
||||||
|
|
||||||
|
var ErrorResponse = function (response) {
|
||||||
|
this.message = response.Message;
|
||||||
|
this.validationErrors = response.ValidationErrors;
|
||||||
|
};
|
||||||
|
|
||||||
|
var DeviceResponse = function (response) {
|
||||||
|
this.id = response.Id;
|
||||||
|
this.name = response.Name;
|
||||||
|
this.identifier = response.Identifier;
|
||||||
|
this.type = response.Type;
|
||||||
|
this.creationDate = response.CreationDate;
|
||||||
|
};
|
||||||
|
|
||||||
|
var CipherHistoryResponse = function (response) {
|
||||||
|
this.revised = [];
|
||||||
|
|
||||||
|
var revised = response.Revised;
|
||||||
|
for (var i = 0; i < revised.length; i++) {
|
||||||
|
revised.push(new CipherResponse(revised[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.deleted = response.Deleted;
|
||||||
|
};
|
||||||
@@ -4,17 +4,72 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
!function () {
|
!function () {
|
||||||
|
// Account APIs
|
||||||
ApiService.prototype.getProfile = function (success, error) {
|
ApiService.prototype.getProfile = function (success, error) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.tokenService.getToken(function(token) {
|
this.tokenService.getToken(function (token) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: self.baseUrl + '/accounts/profile',
|
url: self.baseUrl + '/accounts/profile',
|
||||||
data: 'access_token=' + token,
|
data: 'access_token=' + token,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: success,
|
success: function (response) {
|
||||||
error: error
|
success(new ProfileResponse(response))
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
handleError(error, jqXHR, textStatus, errorThrown);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Site APIs
|
||||||
|
|
||||||
|
// Folder APIs
|
||||||
|
|
||||||
|
// Cipher APIs
|
||||||
|
ApiService.prototype.getCipher = function (id, success, error) {
|
||||||
|
var self = this;
|
||||||
|
this.tokenService.getToken(function (token) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: self.baseUrl + '/ciphers/' + id,
|
||||||
|
data: 'access_token=' + token,
|
||||||
|
dataType: 'json',
|
||||||
|
success: function (response) {
|
||||||
|
success(new CipherResponse(response))
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
handleError(error, jqXHR, textStatus, errorThrown);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
ApiService.prototype.getCiphers = function (success, error) {
|
||||||
|
var self = this;
|
||||||
|
this.tokenService.getToken(function (token) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: self.baseUrl + '/ciphers',
|
||||||
|
data: 'access_token=' + token,
|
||||||
|
dataType: 'json',
|
||||||
|
success: function (response) {
|
||||||
|
var data = [];
|
||||||
|
for (var i = 0; i < response.length; i++) {
|
||||||
|
data.push(new CipherResponse(response[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
success(new ListResponse(data))
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
handleError(error, jqXHR, textStatus, errorThrown);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function handleError(errorCallback, jqXHR, textStatus, errorThrown) {
|
||||||
|
errorCallback(new ErrorResponse(jqXHR));
|
||||||
|
}
|
||||||
}();
|
}();
|
||||||
|
|||||||
@@ -52,9 +52,9 @@
|
|||||||
|
|
||||||
function loadProfile(profile, callback) {
|
function loadProfile(profile, callback) {
|
||||||
_userProfile.extended = {
|
_userProfile.extended = {
|
||||||
name: profile.Name,
|
name: profile.name,
|
||||||
twoFactorEnabled: profile.TwoFactorEnabled,
|
twoFactorEnabled: profile.twoFactorEnabled,
|
||||||
culture: profile.Culture
|
culture: profile.culture
|
||||||
};
|
};
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
|
|||||||
Reference in New Issue
Block a user