diff --git a/src/Android/MainApplication.cs b/src/Android/MainApplication.cs index 2dbb66c81..bef49ba39 100644 --- a/src/Android/MainApplication.cs +++ b/src/Android/MainApplication.cs @@ -220,7 +220,6 @@ namespace Bit.Android container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); - container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); diff --git a/src/App/Abstractions/Repositories/ICipherApiRepository.cs b/src/App/Abstractions/Repositories/ICipherApiRepository.cs index f1c8346e2..e5de591e1 100644 --- a/src/App/Abstractions/Repositories/ICipherApiRepository.cs +++ b/src/App/Abstractions/Repositories/ICipherApiRepository.cs @@ -4,10 +4,8 @@ using Bit.App.Models.Api; namespace Bit.App.Abstractions { - public interface ICipherApiRepository + public interface ICipherApiRepository : IApiRepository { - Task> GetByIdAsync(string id); - Task>> GetAsync(); Task> PostAttachmentAsync(string cipherId, byte[] data, string fileName); Task DeleteAttachmentAsync(string cipherId, string attachmentId); } diff --git a/src/App/Abstractions/Repositories/ILoginApiRepository.cs b/src/App/Abstractions/Repositories/ILoginApiRepository.cs deleted file mode 100644 index ad76b42b0..000000000 --- a/src/App/Abstractions/Repositories/ILoginApiRepository.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Bit.App.Models.Api; - -namespace Bit.App.Abstractions -{ - public interface ILoginApiRepository : IApiRepository - { - } -} \ No newline at end of file diff --git a/src/App/Abstractions/Services/ILoginService.cs b/src/App/Abstractions/Services/ILoginService.cs index 6e8aae311..b4a3ecd4e 100644 --- a/src/App/Abstractions/Services/ILoginService.cs +++ b/src/App/Abstractions/Services/ILoginService.cs @@ -12,7 +12,7 @@ namespace Bit.App.Abstractions Task> GetAllAsync(); Task> GetAllAsync(bool favorites); Task, IEnumerable>> GetAllAsync(string uriString); - Task> SaveAsync(Login login); + Task> SaveAsync(Login login); Task DeleteAsync(string id); Task DownloadAndDecryptAttachmentAsync(string url, string orgId = null); Task> EncryptAndSaveAttachmentAsync(Login login, byte[] data, string fileName); diff --git a/src/App/App.csproj b/src/App/App.csproj index 2e07b6536..131c2d56f 100644 --- a/src/App/App.csproj +++ b/src/App/App.csproj @@ -104,7 +104,7 @@ - + @@ -114,7 +114,6 @@ - @@ -180,13 +179,11 @@ - - diff --git a/src/App/Models/Api/Request/LoginRequest.cs b/src/App/Models/Api/Request/CipherRequest.cs similarity index 80% rename from src/App/Models/Api/Request/LoginRequest.cs rename to src/App/Models/Api/Request/CipherRequest.cs index 1faa594da..243b4d3cd 100644 --- a/src/App/Models/Api/Request/LoginRequest.cs +++ b/src/App/Models/Api/Request/CipherRequest.cs @@ -1,9 +1,12 @@ -namespace Bit.App.Models.Api +using Bit.App.Enums; + +namespace Bit.App.Models.Api { - public class LoginRequest + public class CipherRequest { - public LoginRequest(Login login) + public CipherRequest(Login login) { + Type = CipherType.Login; OrganizationId = login.OrganizationId; FolderId = login.FolderId; Name = login.Name?.EncryptedString; @@ -15,6 +18,7 @@ Favorite = login.Favorite; } + public CipherType Type { get; set; } public string OrganizationId { get; set; } public string FolderId { get; set; } public string Name { get; set; } diff --git a/src/App/Models/Api/Response/LoginResponse.cs b/src/App/Models/Api/Response/LoginResponse.cs deleted file mode 100644 index 18a0cf20e..000000000 --- a/src/App/Models/Api/Response/LoginResponse.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Bit.App.Models.Api -{ - public class LoginResponse - { - public string Id { get; set; } - public string FolderId { get; set; } - public string UserId { get; set; } - public string OrganizationId { get; set; } - public string Name { get; set; } - public string Uri { get; set; } - public string Username { get; set; } - public string Password { get; set; } - public string Notes { get; set; } - public string Totp { get; set; } - public bool Favorite { get; set; } - public bool Edit { get; set; } - public bool OrganizationUseTotp { get; set; } - public IEnumerable Attachments { get; set; } - public DateTime RevisionDate { get; set; } - } -} diff --git a/src/App/Models/Data/LoginData.cs b/src/App/Models/Data/LoginData.cs index 688c13385..0896e588a 100644 --- a/src/App/Models/Data/LoginData.cs +++ b/src/App/Models/Data/LoginData.cs @@ -28,24 +28,6 @@ namespace Bit.App.Models.Data OrganizationUseTotp = login.OrganizationUseTotp; } - public LoginData(LoginResponse login, string userId) - { - Id = login.Id; - FolderId = login.FolderId; - UserId = userId; - OrganizationId = login.OrganizationId; - Name = login.Name; - Uri = login.Uri; - Username = login.Username; - Password = login.Password; - Notes = login.Notes; - Totp = login.Totp; - Favorite = login.Favorite; - RevisionDateTime = login.RevisionDate; - Edit = login.Edit; - OrganizationUseTotp = login.OrganizationUseTotp; - } - public LoginData(CipherResponse cipher, string userId) { if(cipher.Type != Enums.CipherType.Login) diff --git a/src/App/Models/Login.cs b/src/App/Models/Login.cs index 46f08a8aa..de624a105 100644 --- a/src/App/Models/Login.cs +++ b/src/App/Models/Login.cs @@ -28,24 +28,6 @@ namespace Bit.App.Models Attachments = attachments?.Select(a => new Attachment(a)); } - public Login(LoginResponse response) - { - Id = response.Id; - UserId = response.UserId; - OrganizationId = response.OrganizationId; - FolderId = response.FolderId; - Name = response.Name != null ? new CipherString(response.Name) : null; - Uri = response.Uri != null ? new CipherString(response.Uri) : null; - Username = response.Username != null ? new CipherString(response.Username) : null; - Password = response.Password != null ? new CipherString(response.Password) : null; - Notes = response.Notes != null ? new CipherString(response.Notes) : null; - Totp = response.Totp != null ? new CipherString(response.Totp) : null; - Favorite = response.Favorite; - Edit = response.Edit; - OrganizationUseTotp = response.OrganizationUseTotp; - Attachments = response.Attachments?.Select(a => new Attachment(a)); - } - public string Id { get; set; } public string UserId { get; set; } public string OrganizationId { get; set; } @@ -61,11 +43,6 @@ namespace Bit.App.Models public bool OrganizationUseTotp { get; set; } public IEnumerable Attachments { get; set; } - public LoginRequest ToLoginRequest() - { - return new LoginRequest(this); - } - public LoginData ToLoginData(string userId) { return new LoginData(this, userId); diff --git a/src/App/Repositories/CipherApiRepository.cs b/src/App/Repositories/CipherApiRepository.cs index a019a4400..8db7adf8d 100644 --- a/src/App/Repositories/CipherApiRepository.cs +++ b/src/App/Repositories/CipherApiRepository.cs @@ -5,12 +5,11 @@ using Bit.App.Abstractions; using Bit.App.Models.Api; using Newtonsoft.Json; using Plugin.Connectivity.Abstractions; -using System.Globalization; using System.IO; namespace Bit.App.Repositories { - public class CipherApiRepository : BaseApiRepository, ICipherApiRepository + public class CipherApiRepository : ApiRepository, ICipherApiRepository { public CipherApiRepository( IConnectivity connectivity, @@ -21,87 +20,6 @@ namespace Bit.App.Repositories protected override string ApiRoute => "ciphers"; - public virtual async Task> GetByIdAsync(string id) - { - if(!Connectivity.IsConnected) - { - return HandledNotConnected(); - } - - var tokenStateResponse = await HandleTokenStateAsync(); - if(!tokenStateResponse.Succeeded) - { - return tokenStateResponse; - } - - using(var client = HttpService.ApiClient) - { - var requestMessage = new TokenHttpRequestMessage() - { - Method = HttpMethod.Get, - RequestUri = new Uri(string.Concat(client.BaseAddress, ApiRoute, "/", id)), - }; - - try - { - var response = await client.SendAsync(requestMessage).ConfigureAwait(false); - if(!response.IsSuccessStatusCode) - { - return await HandleErrorAsync(response).ConfigureAwait(false); - } - - var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var responseObj = JsonConvert.DeserializeObject(responseContent); - return ApiResult.Success(responseObj, response.StatusCode); - } - catch - { - return HandledWebException(); - } - } - } - - public virtual async Task>> GetAsync() - { - if(!Connectivity.IsConnected) - { - return HandledNotConnected>(); - } - - var tokenStateResponse = await HandleTokenStateAsync>(); - if(!tokenStateResponse.Succeeded) - { - return tokenStateResponse; - } - - using(var client = HttpService.ApiClient) - { - var requestMessage = new TokenHttpRequestMessage() - { - Method = HttpMethod.Get, - RequestUri = new Uri(string.Format("{0}{1}?includeFolders=false&includeShared=true", - client.BaseAddress, ApiRoute)), - }; - - try - { - var response = await client.SendAsync(requestMessage).ConfigureAwait(false); - if(!response.IsSuccessStatusCode) - { - return await HandleErrorAsync>(response).ConfigureAwait(false); - } - - var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var responseObj = JsonConvert.DeserializeObject>(responseContent); - return ApiResult>.Success(responseObj, response.StatusCode); - } - catch - { - return HandledWebException>(); - } - } - } - public virtual async Task> PostAttachmentAsync(string cipherId, byte[] data, string fileName) { diff --git a/src/App/Repositories/LoginApiRepository.cs b/src/App/Repositories/LoginApiRepository.cs deleted file mode 100644 index 7df3c5b45..000000000 --- a/src/App/Repositories/LoginApiRepository.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using Bit.App.Abstractions; -using Bit.App.Models.Api; -using Plugin.Connectivity.Abstractions; - -namespace Bit.App.Repositories -{ - public class LoginApiRepository : ApiRepository, ILoginApiRepository - { - public LoginApiRepository( - IConnectivity connectivity, - IHttpService httpService, - ITokenService tokenService) - : base(connectivity, httpService, tokenService) - { } - - protected override string ApiRoute => "logins"; - } -} diff --git a/src/App/Services/LoginService.cs b/src/App/Services/LoginService.cs index cf2f4ec5f..4896ca50f 100644 --- a/src/App/Services/LoginService.cs +++ b/src/App/Services/LoginService.cs @@ -18,7 +18,6 @@ namespace Bit.App.Services private readonly ILoginRepository _loginRepository; private readonly IAttachmentRepository _attachmentRepository; private readonly IAuthService _authService; - private readonly ILoginApiRepository _loginApiRepository; private readonly ICipherApiRepository _cipherApiRepository; private readonly ISettingsService _settingsService; private readonly ICryptoService _cryptoService; @@ -27,7 +26,6 @@ namespace Bit.App.Services ILoginRepository loginRepository, IAttachmentRepository attachmentRepository, IAuthService authService, - ILoginApiRepository loginApiRepository, ICipherApiRepository cipherApiRepository, ISettingsService settingsService, ICryptoService cryptoService) @@ -35,7 +33,6 @@ namespace Bit.App.Services _loginRepository = loginRepository; _attachmentRepository = attachmentRepository; _authService = authService; - _loginApiRepository = loginApiRepository; _cipherApiRepository = cipherApiRepository; _settingsService = settingsService; _cryptoService = cryptoService; @@ -215,18 +212,18 @@ namespace Bit.App.Services return new Tuple, IEnumerable>(matchingLogins, matchingFuzzyLogins); } - public async Task> SaveAsync(Login login) + public async Task> SaveAsync(Login login) { - ApiResult response = null; - var request = new LoginRequest(login); + ApiResult response = null; + var request = new CipherRequest(login); if(login.Id == null) { - response = await _loginApiRepository.PostAsync(request); + response = await _cipherApiRepository.PostAsync(request); } else { - response = await _loginApiRepository.PutAsync(login.Id, request); + response = await _cipherApiRepository.PutAsync(login.Id, request); } if(response.Succeeded) @@ -253,7 +250,7 @@ namespace Bit.App.Services public async Task DeleteAsync(string id) { - var response = await _loginApiRepository.DeleteAsync(id); + var response = await _cipherApiRepository.DeleteAsync(id); if(response.Succeeded) { await _loginRepository.DeleteAsync(id); diff --git a/src/iOS.Extension/LoadingViewController.cs b/src/iOS.Extension/LoadingViewController.cs index 29ba31b6a..995069cf9 100644 --- a/src/iOS.Extension/LoadingViewController.cs +++ b/src/iOS.Extension/LoadingViewController.cs @@ -294,7 +294,6 @@ namespace Bit.iOS.Extension container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); - container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index c1ee132eb..b2a002f91 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -277,7 +277,6 @@ namespace Bit.iOS container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); - container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton();