1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 23:03:32 +00:00

move api services to background page. wire up log in and log out.

This commit is contained in:
Kyle Spearrin
2016-09-03 15:44:32 -04:00
parent c3053ea3a7
commit 79860da28c
11 changed files with 90 additions and 61 deletions

View File

@@ -4,6 +4,42 @@
};
!function () {
// Auth APIs
ApiService.prototype.postToken = function (tokenRequest, success, error) {
var self = this;
$.ajax({
type: 'POST',
url: self.baseUrl + '/auth/token',
data: JSON.stringify(tokenRequest),
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (response) {
success(new TokenResponse(response))
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, textStatus, errorThrown);
}
});
};
ApiService.prototype.postTokenTwoFactor = function (twoFactorTokenRequest, success, error) {
var self = this;
$.ajax({
type: 'POST',
url: self.baseUrl + '/auth/token/two-factor',
data: JSON.stringify(twoFactorTokenRequest),
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (response) {
success(new TokenResponse(response))
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, textStatus, errorThrown);
}
});
};
// Account APIs
ApiService.prototype.getProfile = function (success, error) {
@@ -48,7 +84,8 @@
$.ajax({
type: 'POST',
url: self.baseUrl + '/sites?access_token=' + token,
data: siteRequest,
data: JSON.stringify(siteRequest),
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (response) {
success(new SiteResponse(response))
@@ -66,7 +103,8 @@
$.ajax({
type: 'POST',
url: self.baseUrl + '/sites/' + id + '?access_token=' + token,
data: siteRequest,
data: JSON.stringify(siteRequest),
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (response) {
success(new SiteResponse(response))
@@ -103,7 +141,8 @@
$.ajax({
type: 'POST',
url: self.baseUrl + '/folders?access_token=' + token,
data: folderRequest,
data: JSON.stringify(folderRequest),
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (response) {
success(new FolderResponse(response))
@@ -121,7 +160,8 @@
$.ajax({
type: 'POST',
url: self.baseUrl + '/folders/' + id + '?access_token=' + token,
data: folderRequest,
data: JSON.stringify(folderRequest),
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (response) {
success(new FolderResponse(response))
@@ -180,6 +220,7 @@
$.ajax({
type: 'POST',
url: self.baseUrl + '/ciphers/' + id + '/delete?access_token=' + token,
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: success,
error: function (jqXHR, textStatus, errorThrown) {