mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-06 09:20:43 +01:00
move from login to cipher apis
This commit is contained in:
parent
b48c86a572
commit
8a1e8678f8
@ -1,13 +1,18 @@
|
|||||||
var LoginRequest = function (login) {
|
var CipherRequest = function (cipher, type) {
|
||||||
this.folderId = login.folderId;
|
this.type = type;
|
||||||
this.organizationId = login.organizationId;
|
this.folderId = cipher.folderId;
|
||||||
this.name = login.name ? login.name.encryptedString : null;
|
this.organizationId = cipher.organizationId;
|
||||||
this.uri = login.uri ? login.uri.encryptedString : null;
|
this.name = cipher.name ? cipher.name.encryptedString : null;
|
||||||
this.username = login.username ? login.username.encryptedString : null;
|
this.favorite = cipher.favorite;
|
||||||
this.password = login.password ? login.password.encryptedString : null;
|
|
||||||
this.notes = login.notes ? login.notes.encryptedString : null;
|
if (type === 1) {
|
||||||
this.totp = login.totp ? login.totp.encryptedString : null;
|
// login
|
||||||
this.favorite = login.favorite;
|
this.uri = cipher.uri ? cipher.uri.encryptedString : null;
|
||||||
|
this.username = cipher.username ? cipher.username.encryptedString : null;
|
||||||
|
this.password = cipher.password ? cipher.password.encryptedString : null;
|
||||||
|
this.totp = cipher.totp ? cipher.totp.encryptedString : null;
|
||||||
|
this.notes = cipher.notes ? cipher.notes.encryptedString : null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var FolderRequest = function (folder) {
|
var FolderRequest = function (folder) {
|
||||||
|
@ -23,33 +23,6 @@ var FolderResponse = function (response) {
|
|||||||
this.revisionDate = response.RevisionDate;
|
this.revisionDate = response.RevisionDate;
|
||||||
};
|
};
|
||||||
|
|
||||||
var LoginResponse = function (response) {
|
|
||||||
this.id = response.Id;
|
|
||||||
this.organizationId = response.OrganizationId;
|
|
||||||
this.folderId = response.FolderId;
|
|
||||||
this.edit = response.Edit;
|
|
||||||
this.name = response.Name;
|
|
||||||
this.uri = response.Uri;
|
|
||||||
this.username = response.Username;
|
|
||||||
this.password = response.Password;
|
|
||||||
this.notes = response.Notes;
|
|
||||||
this.totp = response.Totp;
|
|
||||||
this.favorite = response.Favorite;
|
|
||||||
this.revisionDate = response.RevisionDate;
|
|
||||||
this.organizationUseTotp = response.OrganizationUseTotp;
|
|
||||||
|
|
||||||
if (response.Folder) {
|
|
||||||
this.folder = new FolderResponse(response.Folder);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.Attachments) {
|
|
||||||
this.attachments = [];
|
|
||||||
for (var i = 0; i < response.Attachments.length; i++) {
|
|
||||||
this.attachments.push(new AttachmentResponse(response.Attachments[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var ProfileResponse = function (response) {
|
var ProfileResponse = function (response) {
|
||||||
this.id = response.Id;
|
this.id = response.Id;
|
||||||
this.name = response.Name;
|
this.name = response.Name;
|
||||||
|
@ -22,27 +22,12 @@ var LoginData = function (response, userId) {
|
|||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.edit = response.edit;
|
this.edit = response.edit;
|
||||||
this.organizationUseTotp = response.organizationUseTotp;
|
this.organizationUseTotp = response.organizationUseTotp;
|
||||||
|
|
||||||
if (response instanceof LoginResponse) {
|
|
||||||
this.name = response.name;
|
|
||||||
this.uri = response.uri;
|
|
||||||
this.username = response.username;
|
|
||||||
this.password = response.password;
|
|
||||||
this.notes = response.notes;
|
|
||||||
this.totp = response.totp;
|
|
||||||
}
|
|
||||||
else if (response instanceof CipherResponse) {
|
|
||||||
this.name = response.data.Name;
|
this.name = response.data.Name;
|
||||||
this.uri = response.data.Uri;
|
this.uri = response.data.Uri;
|
||||||
this.username = response.data.Username;
|
this.username = response.data.Username;
|
||||||
this.password = response.data.Password;
|
this.password = response.data.Password;
|
||||||
this.notes = response.notes = response.data.Notes;
|
this.notes = response.notes = response.data.Notes;
|
||||||
this.totp = response.notes = response.data.Totp;
|
this.totp = response.notes = response.data.Totp;
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw 'unsupported instance';
|
|
||||||
}
|
|
||||||
|
|
||||||
this.favorite = response.favorite;
|
this.favorite = response.favorite;
|
||||||
this.revisionDate = response.revisionDate;
|
this.revisionDate = response.revisionDate;
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ function initApiService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Desktop
|
// Desktop
|
||||||
self.baseUrl = 'http://localhost:4000';
|
//self.baseUrl = 'http://localhost:4000';
|
||||||
self.identityBaseUrl = 'http://localhost:33656';
|
//self.identityBaseUrl = 'http://localhost:33656';
|
||||||
|
|
||||||
// Desktop HTTPS
|
// Desktop HTTPS
|
||||||
//self.baseUrl = 'https://localhost:44377';
|
//self.baseUrl = 'https://localhost:44377';
|
||||||
@ -46,8 +46,8 @@ function initApiService() {
|
|||||||
//self.identityBaseUrl = 'https://preview-identity.bitwarden.com';
|
//self.identityBaseUrl = 'https://preview-identity.bitwarden.com';
|
||||||
|
|
||||||
// Production
|
// Production
|
||||||
//self.baseUrl = 'https://api.bitwarden.com';
|
self.baseUrl = 'https://api.bitwarden.com';
|
||||||
//self.identityBaseUrl = 'https://identity.bitwarden.com';
|
self.identityBaseUrl = 'https://identity.bitwarden.com';
|
||||||
};
|
};
|
||||||
|
|
||||||
// Auth APIs
|
// Auth APIs
|
||||||
@ -189,94 +189,8 @@ function initApiService() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Login APIs
|
|
||||||
|
|
||||||
ApiService.prototype.getLogin = function (id, success, error) {
|
|
||||||
var self = this;
|
|
||||||
handleTokenState(self).then(function (tokenHeader) {
|
|
||||||
$.ajax({
|
|
||||||
type: 'GET',
|
|
||||||
url: self.baseUrl + '/logins/' + id,
|
|
||||||
dataType: 'json',
|
|
||||||
headers: tokenHeader,
|
|
||||||
success: function (response) {
|
|
||||||
success(new LoginResponse(response));
|
|
||||||
},
|
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
|
||||||
handleError(error, jqXHR, false, self);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, function (jqXHR) {
|
|
||||||
handleError(error, jqXHR, true, self);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ApiService.prototype.postLogin = function (loginRequest, success, error) {
|
|
||||||
var self = this;
|
|
||||||
handleTokenState(self).then(function (tokenHeader) {
|
|
||||||
$.ajax({
|
|
||||||
type: 'POST',
|
|
||||||
url: self.baseUrl + '/logins',
|
|
||||||
data: JSON.stringify(loginRequest),
|
|
||||||
contentType: 'application/json; charset=utf-8',
|
|
||||||
dataType: 'json',
|
|
||||||
headers: tokenHeader,
|
|
||||||
success: function (response) {
|
|
||||||
success(new LoginResponse(response));
|
|
||||||
},
|
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
|
||||||
handleError(error, jqXHR, false, self);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, function (jqXHR) {
|
|
||||||
handleError(error, jqXHR, true, self);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ApiService.prototype.putLogin = function (id, loginRequest, success, error) {
|
|
||||||
var self = this;
|
|
||||||
handleTokenState(self).then(function (tokenHeader) {
|
|
||||||
$.ajax({
|
|
||||||
type: 'PUT',
|
|
||||||
url: self.baseUrl + '/logins/' + id,
|
|
||||||
data: JSON.stringify(loginRequest),
|
|
||||||
contentType: 'application/json; charset=utf-8',
|
|
||||||
dataType: 'json',
|
|
||||||
headers: tokenHeader,
|
|
||||||
success: function (response) {
|
|
||||||
success(new LoginResponse(response));
|
|
||||||
},
|
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
|
||||||
handleError(error, jqXHR, false, self);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, function (jqXHR) {
|
|
||||||
handleError(error, jqXHR, true, self);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Folder APIs
|
// Folder APIs
|
||||||
|
|
||||||
ApiService.prototype.getFolder = function (id, success, error) {
|
|
||||||
var self = this;
|
|
||||||
handleTokenState(self).then(function (tokenHeader) {
|
|
||||||
$.ajax({
|
|
||||||
type: 'GET',
|
|
||||||
url: self.baseUrl + '/folders/' + id,
|
|
||||||
dataType: 'json',
|
|
||||||
headers: tokenHeader,
|
|
||||||
success: function (response) {
|
|
||||||
success(new FolderResponse(response));
|
|
||||||
},
|
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
|
||||||
handleError(error, jqXHR, false, self);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, function (jqXHR) {
|
|
||||||
handleError(error, jqXHR, true, self);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ApiService.prototype.postFolder = function (folderRequest, success, error) {
|
ApiService.prototype.postFolder = function (folderRequest, success, error) {
|
||||||
var self = this;
|
var self = this;
|
||||||
handleTokenState(self).then(function (tokenHeader) {
|
handleTokenState(self).then(function (tokenHeader) {
|
||||||
@ -343,12 +257,36 @@ function initApiService() {
|
|||||||
|
|
||||||
// Cipher APIs
|
// Cipher APIs
|
||||||
|
|
||||||
ApiService.prototype.getCipher = function (id, success, error) {
|
ApiService.prototype.postCipher = function (cipherRequest, success, error) {
|
||||||
var self = this;
|
var self = this;
|
||||||
handleTokenState(self).then(function (tokenHeader) {
|
handleTokenState(self).then(function (tokenHeader) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'POST',
|
||||||
|
url: self.baseUrl + '/ciphers',
|
||||||
|
data: JSON.stringify(cipherRequest),
|
||||||
|
contentType: 'application/json; charset=utf-8',
|
||||||
|
dataType: 'json',
|
||||||
|
headers: tokenHeader,
|
||||||
|
success: function (response) {
|
||||||
|
success(new CipherResponse(response));
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
handleError(error, jqXHR, false, self);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, function (jqXHR) {
|
||||||
|
handleError(error, jqXHR, true, self);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
ApiService.prototype.putCipher = function (id, cipherRequest, success, error) {
|
||||||
|
var self = this;
|
||||||
|
handleTokenState(self).then(function (tokenHeader) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'PUT',
|
||||||
url: self.baseUrl + '/ciphers/' + id,
|
url: self.baseUrl + '/ciphers/' + id,
|
||||||
|
data: JSON.stringify(cipherRequest),
|
||||||
|
contentType: 'application/json; charset=utf-8',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
headers: tokenHeader,
|
headers: tokenHeader,
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
|
@ -212,15 +212,15 @@ function initLoginService() {
|
|||||||
var deferred = Q.defer();
|
var deferred = Q.defer();
|
||||||
|
|
||||||
var self = this,
|
var self = this,
|
||||||
request = new LoginRequest(login);
|
request = new CipherRequest(login, 1); // 1 = Login
|
||||||
|
|
||||||
if (!login.id) {
|
if (!login.id) {
|
||||||
self.apiService.postLogin(request, apiSuccess, function (response) {
|
self.apiService.postCipher(request, apiSuccess, function (response) {
|
||||||
handleError(response, deferred);
|
handleError(response, deferred);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.apiService.putLogin(login.id, request, apiSuccess, function (response) {
|
self.apiService.putCipher(login.id, request, apiSuccess, function (response) {
|
||||||
handleError(response, deferred);
|
handleError(response, deferred);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user