1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-10 21:33:36 +00:00

refactoring code for login => cipher support

This commit is contained in:
Kyle Spearrin
2017-10-18 20:55:33 -04:00
parent 37f05f0a12
commit 1d6ec0f953
46 changed files with 731 additions and 410 deletions

View File

@@ -277,7 +277,7 @@ namespace Bit.iOS.Extension
container.RegisterSingleton<IKeyDerivationService, CommonCryptoKeyDerivationService>();
container.RegisterSingleton<IAuthService, AuthService>();
container.RegisterSingleton<IFolderService, FolderService>();
container.RegisterSingleton<ILoginService, LoginService>();
container.RegisterSingleton<ICipherService, CipherService>();
container.RegisterSingleton<ISyncService, SyncService>();
container.RegisterSingleton<IPasswordGenerationService, PasswordGenerationService>();
container.RegisterSingleton<IAppIdService, AppIdService>();
@@ -294,7 +294,7 @@ namespace Bit.iOS.Extension
// Repositories
container.RegisterSingleton<IFolderRepository, FolderRepository>();
container.RegisterSingleton<IFolderApiRepository, FolderApiRepository>();
container.RegisterSingleton<ILoginRepository, LoginRepository>();
container.RegisterSingleton<ICipherRepository, CipherRepository>();
container.RegisterSingleton<IAttachmentRepository, AttachmentRepository>();
container.RegisterSingleton<IConnectApiRepository, ConnectApiRepository>();
container.RegisterSingleton<ISettingsRepository, SettingsRepository>();

View File

@@ -19,7 +19,7 @@ namespace Bit.iOS.Extension
{
public partial class LoginAddViewController : ExtendedUITableViewController
{
private ILoginService _loginService;
private ICipherService _cipherService;
private IFolderService _folderService;
private IConnectivity _connectivity;
private IEnumerable<Folder> _folders;
@@ -49,7 +49,7 @@ namespace Bit.iOS.Extension
public override void ViewDidLoad()
{
_loginService = Resolver.Resolve<ILoginService>();
_cipherService = Resolver.Resolve<ICipherService>();
_connectivity = Resolver.Resolve<IConnectivity>();
_folderService = Resolver.Resolve<IFolderService>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
@@ -151,18 +151,21 @@ namespace Bit.iOS.Extension
return;
}
var login = new Login
var cipher = new Cipher
{
Uri = string.IsNullOrWhiteSpace(UriCell.TextField.Text) ? null : UriCell.TextField.Text.Encrypt(),
Name = string.IsNullOrWhiteSpace(NameCell.TextField.Text) ? null : NameCell.TextField.Text.Encrypt(),
Username = string.IsNullOrWhiteSpace(UsernameCell.TextField.Text) ? null : UsernameCell.TextField.Text.Encrypt(),
Password = string.IsNullOrWhiteSpace(PasswordCell.TextField.Text) ? null : PasswordCell.TextField.Text.Encrypt(),
Notes = string.IsNullOrWhiteSpace(NotesCell.TextView.Text) ? null : NotesCell.TextView.Text.Encrypt(),
Favorite = FavoriteCell.Switch.On,
FolderId = FolderCell.SelectedIndex == 0 ? null : _folders.ElementAtOrDefault(FolderCell.SelectedIndex - 1)?.Id
FolderId = FolderCell.SelectedIndex == 0 ? null : _folders.ElementAtOrDefault(FolderCell.SelectedIndex - 1)?.Id,
Login = new Login
{
Uri = string.IsNullOrWhiteSpace(UriCell.TextField.Text) ? null : UriCell.TextField.Text.Encrypt(),
Username = string.IsNullOrWhiteSpace(UsernameCell.TextField.Text) ? null : UsernameCell.TextField.Text.Encrypt(),
Password = string.IsNullOrWhiteSpace(PasswordCell.TextField.Text) ? null : PasswordCell.TextField.Text.Encrypt()
}
};
var saveTask = _loginService.SaveAsync(login);
var saveTask = _cipherService.SaveAsync(cipher);
var loadingAlert = Dialogs.CreateLoadingAlert(AppResources.Saving);
PresentViewController(loadingAlert, true, null);
await saveTask;

View File

@@ -105,7 +105,7 @@ namespace Bit.iOS.Extension
private IEnumerable<LoginViewModel> _tableItems = new List<LoginViewModel>();
private Context _context;
private LoginListViewController _controller;
private ILoginService _loginService;
private ICipherService _cipherService;
private ISettings _settings;
private bool _isPremium;
@@ -114,15 +114,15 @@ namespace Bit.iOS.Extension
_context = controller.Context;
_controller = controller;
_isPremium = Resolver.Resolve<ITokenService>()?.TokenPremium ?? false;
_loginService = Resolver.Resolve<ILoginService>();
_cipherService = Resolver.Resolve<ICipherService>();
_settings = Resolver.Resolve<ISettings>();
}
public async Task LoadItemsAsync()
{
var combinedLogins = new List<Login>();
var combinedLogins = new List<Cipher>();
var logins = await _loginService.GetAllAsync(_context.UrlString);
var logins = await _cipherService.GetAllAsync(_context.UrlString);
if(logins?.Item1 != null)
{
combinedLogins.AddRange(logins.Item1);

View File

@@ -7,7 +7,7 @@ namespace Bit.iOS.Extension.Models
{
public class LoginViewModel
{
public LoginViewModel(Login login)
public LoginViewModel(Cipher login)
{
Id = login.Id;
Name = login.Name?.Decrypt(login.OrganizationId);