From 549ac1f996d78eb64b3567830615ee0524b8560e Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 9 Jul 2016 13:11:18 -0400 Subject: [PATCH] Save newly added site in extension --- src/App/Models/DomainName.cs | 6 +-- src/iOS.Extension/LoadingViewController.cs | 9 ++-- src/iOS.Extension/SiteAddViewController.cs | 61 +++++++++++++++++++++- src/iOS.Extension/iOS.Extension.csproj | 32 ++++++++++++ src/iOS.Extension/packages.config | 5 ++ 5 files changed, 105 insertions(+), 8 deletions(-) diff --git a/src/App/Models/DomainName.cs b/src/App/Models/DomainName.cs index dd1fd7700..0e837b6f1 100644 --- a/src/App/Models/DomainName.cs +++ b/src/App/Models/DomainName.cs @@ -167,7 +167,7 @@ namespace Bit.App.Models { ruleMatches.Add(result); } - Debug.WriteLine(string.Format("Domain part {0} matched {1} {2} rules", checkAgainst, result == null ? 0 : 1, rule)); + //Debug.WriteLine(string.Format("Domain part {0} matched {1} {2} rules", checkAgainst, result == null ? 0 : 1, rule)); } } @@ -180,11 +180,11 @@ namespace Bit.App.Models TLDRule primaryMatch = results.Take(1).SingleOrDefault(); if(primaryMatch != null) { - Debug.WriteLine(string.Format("Looks like our match is: {0}, which is a(n) {1} rule.", primaryMatch.Name, primaryMatch.Type)); + //Debug.WriteLine(string.Format("Looks like our match is: {0}, which is a(n) {1} rule.", primaryMatch.Name, primaryMatch.Type)); } else { - Debug.WriteLine(string.Format("No rules matched domain: {0}", domainString)); + //Debug.WriteLine(string.Format("No rules matched domain: {0}", domainString)); } return primaryMatch; diff --git a/src/iOS.Extension/LoadingViewController.cs b/src/iOS.Extension/LoadingViewController.cs index aa82c8cb7..8e00fd831 100644 --- a/src/iOS.Extension/LoadingViewController.cs +++ b/src/iOS.Extension/LoadingViewController.cs @@ -16,6 +16,8 @@ using Bit.iOS.Extension.Models; using MobileCoreServices; using Plugin.Settings.Abstractions; using Plugin.Connectivity; +using Acr.UserDialogs; +using Plugin.Fingerprint; namespace Bit.iOS.Extension { @@ -96,6 +98,7 @@ namespace Bit.iOS.Extension .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) + .RegisterType(new ContainerControlledLifetimeManager()) //.RegisterType(new ContainerControlledLifetimeManager()) // Repositories .RegisterType(new ContainerControlledLifetimeManager()) @@ -104,9 +107,9 @@ namespace Bit.iOS.Extension .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) // Other - .RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager()); - //.RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager()) - //.RegisterInstance(CrossFingerprint.Current, new ContainerControlledLifetimeManager()); + .RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager()) + .RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager()) + .RegisterInstance(CrossFingerprint.Current, new ContainerControlledLifetimeManager()); ISettings settings = new Settings("group.com.8bit.bitwarden"); container.RegisterInstance(settings, new ContainerControlledLifetimeManager()); diff --git a/src/iOS.Extension/SiteAddViewController.cs b/src/iOS.Extension/SiteAddViewController.cs index 8e24bbe2f..6bb76a817 100644 --- a/src/iOS.Extension/SiteAddViewController.cs +++ b/src/iOS.Extension/SiteAddViewController.cs @@ -9,6 +9,11 @@ using Bit.iOS.Core.Views; using Bit.iOS.Extension.Models; using Foundation; using UIKit; +using XLabs.Ioc; +using Bit.App; +using Plugin.Connectivity.Abstractions; +using Acr.UserDialogs; +using System.Drawing; namespace Bit.iOS.Extension { @@ -83,14 +88,66 @@ namespace Bit.iOS.Extension base.ViewDidLoad(); } - partial void CancelBarButton_Activated(UIBarButtonItem sender) + async partial void CancelBarButton_Activated(UIBarButtonItem sender) { DismissViewController(true, null); } - partial void SaveBarButton_Activated(UIBarButtonItem sender) + async partial void SaveBarButton_Activated(UIBarButtonItem sender) { + var siteService = Resolver.Resolve(); + var connectivity = Resolver.Resolve(); + var userDialogs = Resolver.Resolve(); + + if(!connectivity.IsConnected) + { + AlertNoConnection(); + return; + } + + if(string.IsNullOrWhiteSpace(PasswordCell.TextField.Text)) + { + DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Password), AppResources.Ok); + return; + } + + if(string.IsNullOrWhiteSpace(NameCell.TextField.Text)) + { + DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Name), AppResources.Ok); + return; + } + + var site = new Site + { + Uri = UriCell.TextField.Text?.Encrypt(), + Name = NameCell.TextField.Text?.Encrypt(), + Username = UsernameCell.TextField.Text?.Encrypt(), + Password = PasswordCell.TextField.Text?.Encrypt(), + Notes = NotesCell.TextView.Text?.Encrypt(), + Favorite = FavoriteCell.Switch.On + }; + + var saveTask = siteService.SaveAsync(site); + userDialogs.ShowLoading("Saving...", MaskType.Black); + await saveTask; + + userDialogs.HideLoading(); DismissViewController(true, null); + userDialogs.SuccessToast(NameCell.TextField.Text, "New site created."); + } + + public void DisplayAlert(string title, string message, string accept) + { + var alert = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert); + var oldFrame = alert.View.Frame; + alert.View.Frame = new RectangleF((float)oldFrame.X, (float)oldFrame.Y, (float)oldFrame.Width, (float)oldFrame.Height - 20); + alert.AddAction(UIAlertAction.Create(accept, UIAlertActionStyle.Default, null)); + PresentViewController(alert, true, null); + } + + private void AlertNoConnection() + { + DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok); } public class TableSource : UITableViewSource diff --git a/src/iOS.Extension/iOS.Extension.csproj b/src/iOS.Extension/iOS.Extension.csproj index a64220991..a250396a7 100644 --- a/src/iOS.Extension/iOS.Extension.csproj +++ b/src/iOS.Extension/iOS.Extension.csproj @@ -26,6 +26,8 @@ None true Entitlements.plist + Legacy + NSUrlSessionHandler none @@ -57,6 +59,8 @@ 9.3 None + Legacy + NSUrlSessionHandler none @@ -124,6 +128,22 @@ + + ..\..\packages\Acr.Support.2.1.0\lib\Xamarin.iOS10\Acr.Support.iOS.dll + True + + + ..\..\packages\Acr.UserDialogs.5.3.0\lib\Xamarin.iOS10\Acr.UserDialogs.dll + True + + + ..\..\packages\Acr.UserDialogs.5.3.0\lib\Xamarin.iOS10\Acr.UserDialogs.Interface.dll + True + + + ..\..\packages\BTProgressHUD.1.2.0.3\lib\Xamarin.iOS10\BTProgressHUD.dll + True + ..\..\packages\Newtonsoft.Json.9.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll True @@ -136,6 +156,14 @@ ..\..\packages\Xam.Plugin.Connectivity.2.2.2\lib\Xamarin.iOS10\Plugin.Connectivity.Abstractions.dll True + + ..\..\packages\Plugin.Fingerprint.1.2.0\lib\Xamarin.iOS10\Plugin.Fingerprint.dll + True + + + ..\..\packages\Plugin.Fingerprint.1.2.0\lib\Xamarin.iOS10\Plugin.Fingerprint.Abstractions.dll + True + ..\..\packages\Xam.Plugins.Settings.2.1.0\lib\Xamarin.iOS10\Plugin.Settings.dll True @@ -144,6 +172,10 @@ ..\..\packages\Xam.Plugins.Settings.2.1.0\lib\Xamarin.iOS10\Plugin.Settings.Abstractions.dll True + + ..\..\packages\Splat.1.6.2\lib\Xamarin.iOS10\Splat.dll + True + ..\..\packages\sqlite-net-pcl.1.1.2\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLite-net.dll True diff --git a/src/iOS.Extension/packages.config b/src/iOS.Extension/packages.config index 350e14b86..4399e825e 100644 --- a/src/iOS.Extension/packages.config +++ b/src/iOS.Extension/packages.config @@ -1,7 +1,12 @@  + + + + +