From e05ed4c1f214e83f3382b43bf938f11f58adabd4 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 2 May 2016 17:50:16 -0400 Subject: [PATCH] updates --- src/Android/Android.csproj | 8 +++ src/Android/MainActivity.cs | 2 + src/Android/packages.config | 1 + src/App/Abstractions/Services/IAuthService.cs | 2 + src/App/App.cs | 16 ++--- src/App/App.csproj | 12 ++++ src/App/Models/Api/ApiError.cs | 1 - src/App/Models/Api/ApiResult.cs | 16 +++-- src/App/Models/Data/FolderData.cs | 4 +- src/App/Models/Data/SiteData.cs | 4 +- src/App/Models/Folder.cs | 4 +- src/App/Models/Site.cs | 4 +- src/App/Pages/LoginNavigationPage.cs | 15 +++++ src/App/Pages/LoginPage.cs | 9 ++- src/App/Pages/MainPage.cs | 26 ++++++++ src/App/Pages/SettingsPage.cs | 34 +++++++++++ src/App/Pages/SyncPage.cs | 14 +++++ src/App/Pages/VaultAddFolderPage.cs | 2 +- src/App/Pages/VaultAddSitePage.cs | 2 +- src/App/Pages/VaultEditFolderPage.cs | 2 +- src/App/Pages/VaultEditSitePage.cs | 2 +- src/App/Pages/VaultListPage.cs | 13 ++-- src/App/Pages/VaultViewSitePage.cs | 2 +- src/App/Services/ApiService.cs | 26 +++++--- src/App/Services/AuthService.cs | 61 +++++++++++++++++-- src/App/Services/CryptoService.cs | 25 +++++++- src/App/Services/FolderService.cs | 19 ++++-- src/App/Services/Repository.cs | 18 +++--- src/App/Services/SiteService.cs | 19 ++++-- src/App/packages.config | 1 + src/iOS/AppDelegate.cs | 2 + src/iOS/iOS.csproj | 8 +++ src/iOS/packages.config | 1 + 33 files changed, 298 insertions(+), 77 deletions(-) create mode 100644 src/App/Pages/LoginNavigationPage.cs create mode 100644 src/App/Pages/MainPage.cs create mode 100644 src/App/Pages/SettingsPage.cs create mode 100644 src/App/Pages/SyncPage.cs diff --git a/src/Android/Android.csproj b/src/Android/Android.csproj index 92328d4d5..ac8bd692b 100644 --- a/src/Android/Android.csproj +++ b/src/Android/Android.csproj @@ -94,6 +94,14 @@ ..\..\packages\modernhttpclient.2.4.2\lib\MonoAndroid\OkHttp.dll True + + ..\..\packages\Xam.Plugins.Settings.2.1.0\lib\MonoAndroid10\Plugin.Settings.dll + True + + + ..\..\packages\Xam.Plugins.Settings.2.1.0\lib\MonoAndroid10\Plugin.Settings.Abstractions.dll + True + ..\..\packages\sqlite-net-pcl.1.1.1\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLite-net.dll True diff --git a/src/Android/MainActivity.cs b/src/Android/MainActivity.cs index 087c27eb7..312f8f3a1 100644 --- a/src/Android/MainActivity.cs +++ b/src/Android/MainActivity.cs @@ -12,6 +12,7 @@ using Bit.App.Services; using XLabs.Ioc.Unity; using XLabs.Ioc; using Bit.Android.Services; +using Plugin.Settings; namespace Bit.Android { @@ -40,6 +41,7 @@ namespace Bit.Android .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) + .RegisterInstance(CrossSettings.Current, new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) diff --git a/src/Android/packages.config b/src/Android/packages.config index 15fbb6f75..0e7c53e42 100644 --- a/src/Android/packages.config +++ b/src/Android/packages.config @@ -5,6 +5,7 @@ + diff --git a/src/App/Abstractions/Services/IAuthService.cs b/src/App/Abstractions/Services/IAuthService.cs index 67f657709..ff7f70cf4 100644 --- a/src/App/Abstractions/Services/IAuthService.cs +++ b/src/App/Abstractions/Services/IAuthService.cs @@ -7,7 +7,9 @@ namespace Bit.App.Abstractions { bool IsAuthenticated { get; } string Token { get; set; } + string UserId { get; set; } + void LogOut(); Task> TokenPostAsync(TokenRequest request); } } diff --git a/src/App/App.cs b/src/App/App.cs index e3c57118c..06b6a33a1 100644 --- a/src/App/App.cs +++ b/src/App/App.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Bit.App.Abstractions; -using Bit.App.Views; +using Bit.App.Pages; using Xamarin.Forms; namespace Bit.App @@ -11,26 +11,20 @@ namespace Bit.App public class App : Application { private readonly IDatabaseService _databaseService; + private readonly IAuthService _authService; public App(IAuthService authService, IDatabaseService databaseService) { _databaseService = databaseService; + _authService = authService; if(authService.IsAuthenticated) { - var nav = new NavigationPage(new VaultListPage()); - nav.BarBackgroundColor = Color.FromHex("3c8dbc"); - nav.BarTextColor = Color.FromHex("ffffff"); - - MainPage = nav; + MainPage = new MainPage(); } else { - var nav = new NavigationPage(new LoginPage()); - nav.BarBackgroundColor = Color.FromHex("3c8dbc"); - nav.BarTextColor = Color.FromHex("ffffff"); - - MainPage = nav; + MainPage = new LoginNavigationPage(); } MainPage.BackgroundColor = Color.FromHex("ecf0f5"); diff --git a/src/App/App.csproj b/src/App/App.csproj index afa30dc04..94de56846 100644 --- a/src/App/App.csproj +++ b/src/App/App.csproj @@ -59,6 +59,10 @@ + + + + @@ -105,6 +109,14 @@ ..\..\packages\Newtonsoft.Json.8.0.3\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll True + + ..\..\packages\Xam.Plugins.Settings.2.1.0\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\Plugin.Settings.dll + True + + + ..\..\packages\Xam.Plugins.Settings.2.1.0\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\Plugin.Settings.Abstractions.dll + True + ..\..\packages\sqlite-net-pcl.1.1.1\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLite-net.dll True diff --git a/src/App/Models/Api/ApiError.cs b/src/App/Models/Api/ApiError.cs index aa861b0f2..d7450ba60 100644 --- a/src/App/Models/Api/ApiError.cs +++ b/src/App/Models/Api/ApiError.cs @@ -5,6 +5,5 @@ namespace Bit.App.Models.Api public class ApiError { public string Message { get; set; } - public HttpStatusCode StatusCode { get; set; } } } diff --git a/src/App/Models/Api/ApiResult.cs b/src/App/Models/Api/ApiResult.cs index de3608b87..19def0ae7 100644 --- a/src/App/Models/Api/ApiResult.cs +++ b/src/App/Models/Api/ApiResult.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Net; namespace Bit.App.Models.Api { @@ -9,19 +10,26 @@ namespace Bit.App.Models.Api public bool Succeeded { get; private set; } public T Result { get; set; } public IEnumerable Errors => m_errors; + public HttpStatusCode StatusCode { get; private set; } - public static ApiResult Success(T result) + public static ApiResult Success(T result, HttpStatusCode statusCode) { return new ApiResult { Succeeded = true, - Result = result + Result = result, + StatusCode = statusCode }; } - public static ApiResult Failed(params ApiError[] errors) + public static ApiResult Failed(HttpStatusCode statusCode, params ApiError[] errors) { - var result = new ApiResult { Succeeded = false }; + var result = new ApiResult + { + Succeeded = false, + StatusCode = statusCode + }; + if(errors != null) { result.m_errors.AddRange(errors); diff --git a/src/App/Models/Data/FolderData.cs b/src/App/Models/Data/FolderData.cs index 4a072c06f..e75cc8bed 100644 --- a/src/App/Models/Data/FolderData.cs +++ b/src/App/Models/Data/FolderData.cs @@ -10,10 +10,11 @@ namespace Bit.App.Models.Data public FolderData() { } - public FolderData(Folder folder) + public FolderData(Folder folder, string userId) { Id = folder.Id; ServerId = folder.ServerId; + UserId = userId; Name = folder.Name?.EncryptedString; } @@ -21,6 +22,7 @@ namespace Bit.App.Models.Data [AutoIncrement] public int Id { get; set; } public string ServerId { get; set; } + public string UserId { get; set; } public string Name { get; set; } public DateTime RevisionDateTime { get; set; } = DateTime.UtcNow; diff --git a/src/App/Models/Data/SiteData.cs b/src/App/Models/Data/SiteData.cs index 6c8c55e0f..e2eba614e 100644 --- a/src/App/Models/Data/SiteData.cs +++ b/src/App/Models/Data/SiteData.cs @@ -10,12 +10,13 @@ namespace Bit.App.Models.Data public SiteData() { } - public SiteData(Site site) + public SiteData(Site site, string userId) { Id = site.Id; ServerId = site.ServerId; FolderId = site.FolderId; ServerFolderId = site.ServerFolderId; + UserId = userId; Name = site.Name?.EncryptedString; Uri = site.Uri?.EncryptedString; Username = site.Username?.EncryptedString; @@ -29,6 +30,7 @@ namespace Bit.App.Models.Data public string ServerId { get; set; } public int? FolderId { get; set; } public string ServerFolderId { get; set; } + public string UserId { get; set; } public string Name { get; set; } public string Uri { get; set; } public string Username { get; set; } diff --git a/src/App/Models/Folder.cs b/src/App/Models/Folder.cs index 4aaffebdd..c8d5915aa 100644 --- a/src/App/Models/Folder.cs +++ b/src/App/Models/Folder.cs @@ -21,9 +21,9 @@ namespace Bit.App.Models Name = response.Name != null ? new CipherString(response.Name) : null; } - public FolderData ToFolderData() + public FolderData ToFolderData(string userId) { - return new FolderData(this); + return new FolderData(this, userId); } } } diff --git a/src/App/Models/Site.cs b/src/App/Models/Site.cs index 846ea4860..454ce0a78 100644 --- a/src/App/Models/Site.cs +++ b/src/App/Models/Site.cs @@ -39,9 +39,9 @@ namespace Bit.App.Models public CipherString Password { get; set; } public CipherString Notes { get; set; } - public SiteData ToSiteData() + public SiteData ToSiteData(string userId) { - return new SiteData(this); + return new SiteData(this, userId); } } } diff --git a/src/App/Pages/LoginNavigationPage.cs b/src/App/Pages/LoginNavigationPage.cs new file mode 100644 index 000000000..c58be2d2e --- /dev/null +++ b/src/App/Pages/LoginNavigationPage.cs @@ -0,0 +1,15 @@ +using Xamarin.Forms; + +namespace Bit.App.Pages +{ + public class LoginNavigationPage : NavigationPage + { + public LoginNavigationPage() + : base(new LoginPage()) + { + BarBackgroundColor = Color.FromHex("3c8dbc"); + BarTextColor = Color.FromHex("ffffff"); + Title = "Login"; + } + } +} diff --git a/src/App/Pages/LoginPage.cs b/src/App/Pages/LoginPage.cs index 0db4d851f..7ff7dfa66 100644 --- a/src/App/Pages/LoginPage.cs +++ b/src/App/Pages/LoginPage.cs @@ -9,7 +9,7 @@ using Bit.App.Models.Api; using Xamarin.Forms; using XLabs.Ioc; -namespace Bit.App.Views +namespace Bit.App.Pages { public class LoginPage : ContentPage { @@ -63,12 +63,15 @@ namespace Bit.App.Views var response = await authService.TokenPostAsync(request); if(!response.Succeeded) { - throw new Exception(); + await DisplayAlert("An error occurred", response.Errors.First().Message, "Ok"); + return; } cryptoService.Key = key; authService.Token = response.Result.Token; - await Navigation.PushAsync(new VaultListPage()); + authService.UserId = response.Result.Profile.Id; + + Application.Current.MainPage = new MainPage(); }) }; diff --git a/src/App/Pages/MainPage.cs b/src/App/Pages/MainPage.cs new file mode 100644 index 000000000..0f0cdb74e --- /dev/null +++ b/src/App/Pages/MainPage.cs @@ -0,0 +1,26 @@ +using System; +using Bit.App.Abstractions; +using Xamarin.Forms; + +namespace Bit.App.Pages +{ + public class MainPage : TabbedPage + { + public MainPage() + { + var vaultNavigation = new NavigationPage(new VaultListPage()); + vaultNavigation.BarBackgroundColor = Color.FromHex("3c8dbc"); + vaultNavigation.BarTextColor = Color.FromHex("ffffff"); + vaultNavigation.Title = "My Vault"; + + var settingsNavigation = new NavigationPage(new SettingsPage()); + settingsNavigation.BarBackgroundColor = Color.FromHex("3c8dbc"); + settingsNavigation.BarTextColor = Color.FromHex("ffffff"); + settingsNavigation.Title = "Settings"; + + Children.Add(vaultNavigation); + Children.Add(new SyncPage()); + Children.Add(settingsNavigation); + } + } +} diff --git a/src/App/Pages/SettingsPage.cs b/src/App/Pages/SettingsPage.cs new file mode 100644 index 000000000..8fba6bb60 --- /dev/null +++ b/src/App/Pages/SettingsPage.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using Bit.App.Abstractions; +using Xamarin.Forms; +using XLabs.Ioc; + +namespace Bit.App.Pages +{ + public class SettingsPage : ContentPage + { + private ListView _listView = new ListView(); + + public SettingsPage() + { + var authService = Resolver.Resolve(); + + var logoutButton = new Button + { + Text = "Log Out", + Command = new Command(() => + { + authService.LogOut(); + Application.Current.MainPage = new LoginNavigationPage(); + }) + }; + + var stackLayout = new StackLayout { }; + stackLayout.Children.Add(logoutButton); + + Title = "Settings"; + Content = stackLayout; + } + } +} diff --git a/src/App/Pages/SyncPage.cs b/src/App/Pages/SyncPage.cs new file mode 100644 index 000000000..28a531030 --- /dev/null +++ b/src/App/Pages/SyncPage.cs @@ -0,0 +1,14 @@ +using System; +using Xamarin.Forms; + +namespace Bit.App.Pages +{ + public class SyncPage : ContentPage + { + public SyncPage() + { + Title = "Sync"; + Content = null; + } + } +} diff --git a/src/App/Pages/VaultAddFolderPage.cs b/src/App/Pages/VaultAddFolderPage.cs index 89da50e61..f845c874a 100644 --- a/src/App/Pages/VaultAddFolderPage.cs +++ b/src/App/Pages/VaultAddFolderPage.cs @@ -8,7 +8,7 @@ using Bit.App.Models; using Xamarin.Forms; using XLabs.Ioc; -namespace Bit.App.Views +namespace Bit.App.Pages { public class VaultAddFolderPage : ContentPage { diff --git a/src/App/Pages/VaultAddSitePage.cs b/src/App/Pages/VaultAddSitePage.cs index 1d7e6ca4a..904ea6552 100644 --- a/src/App/Pages/VaultAddSitePage.cs +++ b/src/App/Pages/VaultAddSitePage.cs @@ -8,7 +8,7 @@ using Bit.App.Models; using Xamarin.Forms; using XLabs.Ioc; -namespace Bit.App.Views +namespace Bit.App.Pages { public class VaultAddSitePage : ContentPage { diff --git a/src/App/Pages/VaultEditFolderPage.cs b/src/App/Pages/VaultEditFolderPage.cs index 70710710d..ff16f2e17 100644 --- a/src/App/Pages/VaultEditFolderPage.cs +++ b/src/App/Pages/VaultEditFolderPage.cs @@ -6,7 +6,7 @@ using System.Text; using Xamarin.Forms; -namespace Bit.App.Views +namespace Bit.App.Pages { public class VaultEditFolderPage : ContentPage { diff --git a/src/App/Pages/VaultEditSitePage.cs b/src/App/Pages/VaultEditSitePage.cs index a6fd95eea..d0921a08a 100644 --- a/src/App/Pages/VaultEditSitePage.cs +++ b/src/App/Pages/VaultEditSitePage.cs @@ -6,7 +6,7 @@ using System.Text; using Xamarin.Forms; -namespace Bit.App.Views +namespace Bit.App.Pages { public class VaultEditSitePage : ContentPage { diff --git a/src/App/Pages/VaultListPage.cs b/src/App/Pages/VaultListPage.cs index f1b4b490b..770892b77 100644 --- a/src/App/Pages/VaultListPage.cs +++ b/src/App/Pages/VaultListPage.cs @@ -7,13 +7,13 @@ using Bit.App.Models.View; using Xamarin.Forms; using XLabs.Ioc; -namespace Bit.App.Views +namespace Bit.App.Pages { public class VaultListPage : ContentPage { private readonly IFolderService _folderService; private readonly ISiteService _siteService; - private ListView _listView; + private ListView _listView = new ListView(); public VaultListPage() { @@ -28,12 +28,8 @@ namespace Bit.App.Views ToolbarItems.Add(addSiteToolBarItem); - _listView = new ListView - { - IsGroupingEnabled = true, - GroupDisplayBinding = new Binding("Name") - }; - + _listView.IsGroupingEnabled = true; + _listView.GroupDisplayBinding = new Binding("Name"); _listView.ItemSelected += FolderSelected; _listView.ItemTemplate = new DataTemplate(() => { @@ -45,7 +41,6 @@ namespace Bit.App.Views Title = "My Vault"; Content = _listView; - NavigationPage.SetHasBackButton(this, false); } protected override void OnAppearing() diff --git a/src/App/Pages/VaultViewSitePage.cs b/src/App/Pages/VaultViewSitePage.cs index bae7eeeab..2e7cb0a2f 100644 --- a/src/App/Pages/VaultViewSitePage.cs +++ b/src/App/Pages/VaultViewSitePage.cs @@ -6,7 +6,7 @@ using System.Text; using Xamarin.Forms; -namespace Bit.App.Views +namespace Bit.App.Pages { public class VaultViewSitePage : ContentPage { diff --git a/src/App/Services/ApiService.cs b/src/App/Services/ApiService.cs index cde2c3e67..306d809dc 100644 --- a/src/App/Services/ApiService.cs +++ b/src/App/Services/ApiService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using Bit.App.Abstractions; @@ -20,21 +21,26 @@ namespace Bit.App.Services public async Task> HandleErrorAsync(HttpResponseMessage response) { - var error = new ApiError - { - Message = "An unknown error has occured.", - StatusCode = response.StatusCode - }; - try { var responseContent = await response.Content.ReadAsStringAsync(); var errorResponseModel = JsonConvert.DeserializeObject(responseContent); - error.Message = errorResponseModel.Message; - } - catch(JsonReaderException) { } - return ApiResult.Failed(error); + var errors = new List(); + foreach(var valError in errorResponseModel.ValidationErrors) + { + foreach(var errorMessage in valError.Value) + { + errors.Add(new ApiError { Message = errorMessage }); + } + } + + return ApiResult.Failed(response.StatusCode, errors.ToArray()); + } + catch(JsonReaderException) + { } + + return ApiResult.Failed(response.StatusCode, new ApiError { Message = "An unknown error has occured." }); } } } diff --git a/src/App/Services/AuthService.cs b/src/App/Services/AuthService.cs index 41cc67aec..53b6f49d5 100644 --- a/src/App/Services/AuthService.cs +++ b/src/App/Services/AuthService.cs @@ -5,23 +5,31 @@ using System.Threading.Tasks; using Bit.App.Abstractions; using Bit.App.Models.Api; using Newtonsoft.Json; +using Plugin.Settings.Abstractions; namespace Bit.App.Services { public class AuthService : IAuthService { private const string TokenKey = "token"; + private const string UserIdKey = "userId"; private readonly ISecureStorageService _secureStorage; + private readonly ISettings _settings; private readonly ICryptoService _cryptoService; private readonly IApiService _apiService; + private string _token; + private string _userId; + public AuthService( - ISecureStorageService secureStorage, + ISecureStorageService secureStorage, + ISettings settings, ICryptoService cryptoService, IApiService apiService) { _secureStorage = secureStorage; + _settings = settings; _cryptoService = cryptoService; _apiService = apiService; } @@ -30,8 +38,19 @@ namespace Bit.App.Services { get { + if(_token != null) + { + return _token; + } + var tokenBytes = _secureStorage.Retrieve(TokenKey); - return Encoding.UTF8.GetString(tokenBytes, 0, tokenBytes.Length); + if(tokenBytes == null) + { + return null; + } + + _token = Encoding.UTF8.GetString(tokenBytes, 0, tokenBytes.Length); + return _token; } set { @@ -43,6 +62,33 @@ namespace Bit.App.Services else { _secureStorage.Delete(TokenKey); + _token = null; + } + } + } + + public string UserId + { + get + { + if(_userId != null) + { + return _userId; + } + + _userId = _settings.GetValueOrDefault(UserIdKey); + return _userId; + } + set + { + if(value != null) + { + _settings.AddOrUpdateValue(UserIdKey, value); + } + else + { + _settings.Remove(UserIdKey); + _userId = null; } } } @@ -51,10 +97,17 @@ namespace Bit.App.Services { get { - return _cryptoService.Key != null && Token != null; + return _cryptoService.Key != null && Token != null && UserId != null; } } + public void LogOut() + { + Token = null; + UserId = null; + _cryptoService.Key = null; + } + public async Task> TokenPostAsync(TokenRequest request) { var requestContent = JsonConvert.SerializeObject(request); @@ -66,7 +119,7 @@ namespace Bit.App.Services var responseContent = await response.Content.ReadAsStringAsync(); var responseObj = JsonConvert.DeserializeObject(responseContent); - return ApiResult.Success(responseObj); + return ApiResult.Success(responseObj, response.StatusCode); } } } diff --git a/src/App/Services/CryptoService.cs b/src/App/Services/CryptoService.cs index 32b9c85b9..e697e4b44 100644 --- a/src/App/Services/CryptoService.cs +++ b/src/App/Services/CryptoService.cs @@ -51,11 +51,30 @@ namespace Bit.App.Services } set { - _secureStorage.Store(KeyKey, value); - _keyParameter = new KeyParameter(value); + if(value != null) + { + _secureStorage.Store(KeyKey, value); + } + else + { + _secureStorage.Delete(KeyKey); + _keyParameter = null; + } + } + } + + public string Base64Key + { + get + { + if(Key == null) + { + return null; + } + + return Convert.ToBase64String(Key); } } - public string Base64Key { get { return Convert.ToBase64String(Key); } } public CipherString Encrypt(string plaintextValue) { diff --git a/src/App/Services/FolderService.cs b/src/App/Services/FolderService.cs index 50815924e..4c28116ce 100644 --- a/src/App/Services/FolderService.cs +++ b/src/App/Services/FolderService.cs @@ -10,18 +10,25 @@ namespace Bit.App.Services { public class FolderService : Repository, IFolderService { - public FolderService(ISqlService sqlite) - : base(sqlite) { } + private readonly IAuthService _authService; - public new async Task> GetAllAsync() + public FolderService( + ISqlService sqlService, + IAuthService authService) + : base(sqlService) { - var data = await base.GetAllAsync(); - return data.Select(f => new Folder(f)); + _authService = authService; + } + + public new Task> GetAllAsync() + { + var data = Connection.Table().Where(f => f.UserId == _authService.UserId).Cast(); + return Task.FromResult(data.Select(f => new Folder(f))); } public async Task SaveAsync(Folder folder) { - var data = new FolderData(folder); + var data = new FolderData(folder, _authService.UserId); data.RevisionDateTime = DateTime.UtcNow; if(folder.Id == 0) diff --git a/src/App/Services/Repository.cs b/src/App/Services/Repository.cs index 907260bc8..197c84cf6 100644 --- a/src/App/Services/Repository.cs +++ b/src/App/Services/Repository.cs @@ -11,38 +11,38 @@ namespace Bit.App.Services where TId : IEquatable where T : class, IDataObject, new() { - protected readonly SQLiteConnection _connection; - - public Repository(ISqlService sqlite) + public Repository(ISqlService sqlService) { - _connection = sqlite.GetConnection(); + Connection = sqlService.GetConnection(); } + protected SQLiteConnection Connection { get; private set; } + protected virtual Task GetByIdAsync(TId id) { - return Task.FromResult(_connection.Get(id)); + return Task.FromResult(Connection.Get(id)); } protected virtual Task> GetAllAsync() { - return Task.FromResult(_connection.Table().Cast()); + return Task.FromResult(Connection.Table().Cast()); } protected virtual Task CreateAsync(T obj) { - _connection.Insert(obj); + Connection.Insert(obj); return Task.FromResult(0); } protected virtual Task ReplaceAsync(T obj) { - _connection.Update(obj); + Connection.Update(obj); return Task.FromResult(0); } protected virtual Task DeleteAsync(T obj) { - _connection.Delete(obj.Id); + Connection.Delete(obj.Id); return Task.FromResult(0); } } diff --git a/src/App/Services/SiteService.cs b/src/App/Services/SiteService.cs index 7b67eeeba..67b6429a6 100644 --- a/src/App/Services/SiteService.cs +++ b/src/App/Services/SiteService.cs @@ -10,18 +10,25 @@ namespace Bit.App.Services { public class SiteService : Repository, ISiteService { - public SiteService(ISqlService sqlite) - : base(sqlite) { } + private readonly IAuthService _authService; - public new async Task> GetAllAsync() + public SiteService( + ISqlService sqlService, + IAuthService authService) + : base(sqlService) { - var data = await base.GetAllAsync(); - return data.Select(s => new Site(s)); + _authService = authService; + } + + public new Task> GetAllAsync() + { + var data = Connection.Table().Where(f => f.UserId == _authService.UserId).Cast(); + return Task.FromResult(data.Select(s => new Site(s))); } public async Task SaveAsync(Site site) { - var data = new SiteData(site); + var data = new SiteData(site, _authService.UserId); data.RevisionDateTime = DateTime.UtcNow; if(site.Id == 0) diff --git a/src/App/packages.config b/src/App/packages.config index 25e33ab47..83b572c13 100644 --- a/src/App/packages.config +++ b/src/App/packages.config @@ -7,6 +7,7 @@ + \ No newline at end of file diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index f69c4c942..1e4ad1afb 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -10,6 +10,7 @@ using Bit.App.Abstractions; using Bit.App.Services; using Microsoft.Practices.Unity; using Bit.iOS.Services; +using Plugin.Settings; namespace Bit.iOS { @@ -48,6 +49,7 @@ namespace Bit.iOS .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) + .RegisterInstance(CrossSettings.Current, new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) diff --git a/src/iOS/iOS.csproj b/src/iOS/iOS.csproj index e433cf7cb..795630a06 100644 --- a/src/iOS/iOS.csproj +++ b/src/iOS/iOS.csproj @@ -130,6 +130,14 @@ ..\..\packages\modernhttpclient.2.4.2\lib\Xamarin.iOS10\ModernHttpClient.dll True + + ..\..\packages\Xam.Plugins.Settings.2.1.0\lib\Xamarin.iOS10\Plugin.Settings.dll + True + + + ..\..\packages\Xam.Plugins.Settings.2.1.0\lib\Xamarin.iOS10\Plugin.Settings.Abstractions.dll + True + ..\..\packages\sqlite-net-pcl.1.1.1\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLite-net.dll True diff --git a/src/iOS/packages.config b/src/iOS/packages.config index f74bf259c..26bb17603 100644 --- a/src/iOS/packages.config +++ b/src/iOS/packages.config @@ -5,6 +5,7 @@ +