Пример #1
0
        public async override void ViewDidLoad()
        {
            base.ViewDidLoad();

            SubscribeSyncCompleted();

            NavItem.Title         = AppResources.Items;
            CancelBarButton.Title = AppResources.Cancel;

            TableView.RowHeight          = UITableView.AutomaticDimension;
            TableView.EstimatedRowHeight = 44;
            TableView.BackgroundColor    = ThemeHelpers.BackgroundColor;
            TableView.Source             = new TableSource(this);
            await((TableSource)TableView.Source).LoadItemsAsync();

            _alreadyLoadItemsOnce = true;

            var storageService           = ServiceContainer.Resolve <IStorageService>("storageService");
            var needsAutofillReplacement = await storageService.GetAsync <bool?>(
                Core.Constants.AutofillNeedsIdentityReplacementKey);

            if (needsAutofillReplacement.GetValueOrDefault())
            {
                await ASHelpers.ReplaceAllIdentities();
            }

            _accountSwitchingOverlayHelper  = new AccountSwitchingOverlayHelper();
            AccountSwitchingBarButton.Image = await _accountSwitchingOverlayHelper.CreateAvatarImageAsync();

            _accountSwitchingOverlayView = _accountSwitchingOverlayHelper.CreateAccountSwitchingOverlayView(OverlayView);
        }
Пример #2
0
        public override void ViewDidLoad()
        {
            var descriptor = UIFontDescriptor.PreferredBody;

            DescriptionLabel.Text      = $@"{AppResources.AutofillSetup}

{AppResources.AutofillSetup2}";
            DescriptionLabel.Font      = UIFont.FromDescriptor(descriptor, descriptor.PointSize);
            DescriptionLabel.TextColor = ThemeHelpers.MutedColor;

            ActivatedLabel.Text = AppResources.AutofillActivated;
            ActivatedLabel.Font = UIFont.FromDescriptor(descriptor, descriptor.PointSize * 1.3f);

            BackButton.Title = AppResources.Back;
            base.ViewDidLoad();
            var task = ASHelpers.ReplaceAllIdentities();
        }
Пример #3
0
        public override void ViewDidLoad()
        {
            View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
            var descriptor = UIFontDescriptor.PreferredBody;

            DescriptionLabel.Text      = $@"{AppResources.AutofillSetup}

{AppResources.AutofillSetup2}";
            DescriptionLabel.Font      = UIFont.FromDescriptor(descriptor, descriptor.PointSize);
            DescriptionLabel.TextColor = new UIColor(red: 0.47f, green: 0.47f, blue: 0.47f, alpha: 1.0f);

            ActivatedLabel.Text = AppResources.AutofillActivated;
            ActivatedLabel.Font = UIFont.FromDescriptor(descriptor, descriptor.PointSize * 1.3f);

            BackButton.Title = AppResources.Back;
            base.ViewDidLoad();

            var tasks = ASHelpers.ReplaceAllIdentities(Resolver.Resolve <ICipherService>());
        }
Пример #4
0
        public async override void ViewDidLoad()
        {
            base.ViewDidLoad();
            NavItem.Title         = AppResources.Items;
            CancelBarButton.Title = AppResources.Cancel;

            TableView.RowHeight          = UITableView.AutomaticDimension;
            TableView.EstimatedRowHeight = 44;
            TableView.Source             = new TableSource(this);
            await((TableSource)TableView.Source).LoadItemsAsync();

            var storageService           = ServiceContainer.Resolve <IStorageService>("storageService");
            var needsAutofillReplacement = await storageService.GetAsync <bool?>(
                Core.Constants.AutofillNeedsIdentityReplacementKey);

            if (needsAutofillReplacement.GetValueOrDefault())
            {
                await ASHelpers.ReplaceAllIdentities();
            }
        }
Пример #5
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Forms.Init();
            InitApp();

            _deviceActionService = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");
            _messagingService    = ServiceContainer.Resolve <IMessagingService>("messagingService");
            _broadcasterService  = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService");
            _storageService      = ServiceContainer.Resolve <IStorageService>("storageService");
            _stateService        = ServiceContainer.Resolve <IStateService>("stateService");
            _eventService        = ServiceContainer.Resolve <IEventService>("eventService");

            LoadApplication(new App.App(null));
            iOSCoreHelpers.AppearanceAdjustments();
            ZXing.Net.Mobile.Forms.iOS.Platform.Init();

            _broadcasterService.Subscribe(nameof(AppDelegate), async(message) =>
            {
                try
                {
                    if (message.Command == "startEventTimer")
                    {
                        StartEventTimer();
                    }
                    else if (message.Command == "stopEventTimer")
                    {
                        var task = StopEventTimerAsync();
                    }
                    else if (message.Command == "updatedTheme")
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            iOSCoreHelpers.AppearanceAdjustments();
                        });
                    }
                    else if (message.Command == "listenYubiKeyOTP")
                    {
                        iOSCoreHelpers.ListenYubiKey((bool)message.Data, _deviceActionService, _nfcSession, _nfcDelegate);
                    }
                    else if (message.Command == "unlocked")
                    {
                        var needsAutofillReplacement = await _storageService.GetAsync <bool?>(
                            Core.Constants.AutofillNeedsIdentityReplacementKey);
                        if (needsAutofillReplacement.GetValueOrDefault())
                        {
                            await ASHelpers.ReplaceAllIdentities();
                        }
                    }
                    else if (message.Command == "showAppExtension")
                    {
                        Device.BeginInvokeOnMainThread(() => ShowAppExtension((ExtensionPageViewModel)message.Data));
                    }
                    else if (message.Command == "syncCompleted")
                    {
                        if (message.Data is Dictionary <string, object> data && data.ContainsKey("successfully"))
                        {
                            var success = data["successfully"] as bool?;
                            if (success.GetValueOrDefault() && _deviceActionService.SystemMajorVersion() >= 12)
                            {
                                await ASHelpers.ReplaceAllIdentities();
                            }
                        }
                    }
                    else if (message.Command == "addedCipher" || message.Command == "editedCipher" ||
                             message.Command == "restoredCipher")
                    {
                        if (_deviceActionService.SystemMajorVersion() >= 12)
                        {
                            if (await ASHelpers.IdentitiesCanIncremental())
                            {
                                var cipherId = message.Data as string;
                                if (message.Command == "addedCipher" && !string.IsNullOrWhiteSpace(cipherId))
                                {
                                    var identity = await ASHelpers.GetCipherIdentityAsync(cipherId);
                                    if (identity == null)
                                    {
                                        return;
                                    }
                                    await ASCredentialIdentityStore.SharedStore?.SaveCredentialIdentitiesAsync(
                                        new ASPasswordCredentialIdentity[] { identity });
                                    return;
                                }
                            }
                            await ASHelpers.ReplaceAllIdentities();
                        }
                    }
                    else if (message.Command == "deletedCipher" || message.Command == "softDeletedCipher")
                    {
                        if (_deviceActionService.SystemMajorVersion() >= 12)
                        {
                            if (await ASHelpers.IdentitiesCanIncremental())
                            {
                                var identity = ASHelpers.ToCredentialIdentity(
                                    message.Data as Bit.Core.Models.View.CipherView);
                                if (identity == null)
                                {
                                    return;
                                }
                                await ASCredentialIdentityStore.SharedStore?.RemoveCredentialIdentitiesAsync(
                                    new ASPasswordCredentialIdentity[] { identity });
                                return;
                            }
                            await ASHelpers.ReplaceAllIdentities();
                        }
                    }
                    else if (message.Command == "logout")
                    {
                        if (_deviceActionService.SystemMajorVersion() >= 12)
                        {
                            await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync();
                        }
                    }
                    else if ((message.Command == "softDeletedCipher" || message.Command == "restoredCipher") &&
                             _deviceActionService.SystemMajorVersion() >= 12)
                    {
                        await ASHelpers.ReplaceAllIdentities();
                    }
                    else if (message.Command == "vaultTimeoutActionChanged")
                    {
                        var timeoutAction = await _stateService.GetVaultTimeoutActionAsync();
                        if (timeoutAction == VaultTimeoutAction.Logout)
                        {
                            await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync();
                        }
                        else
                        {
                            await ASHelpers.ReplaceAllIdentities();
                        }
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.LogEvenIfCantBeResolved(ex);
                }
            });

            return(base.FinishedLaunching(app, options));
        }
Пример #6
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Forms.Init();

            if (!Resolver.IsSet)
            {
                SetIoc();
            }

            _lockService       = Resolver.Resolve <ILockService>();
            _deviceInfoService = Resolver.Resolve <IDeviceInfoService>();
            _cipherService     = Resolver.Resolve <ICipherService>();
            _pushHandler       = new iOSPushNotificationHandler(Resolver.Resolve <IPushNotificationListener>());
            _nfcDelegate       = new NFCReaderDelegate((success, message) => ProcessYubikey(success, message));
            var appIdService = Resolver.Resolve <IAppIdService>();

            var crashManagerDelegate = new HockeyAppCrashManagerDelegate(
                appIdService, Resolver.Resolve <IAuthService>());
            var manager = BITHockeyManager.SharedHockeyManager;

            manager.Configure("51f96ae568ba45f699a18ad9f63046c3", crashManagerDelegate);
            manager.CrashManager.CrashManagerStatus = BITCrashManagerStatus.AutoSend;
            manager.UserId = appIdService.AppId;
            manager.StartManager();
            manager.Authenticator.AuthenticateInstallation();
            manager.DisableMetricsManager = manager.DisableFeedbackManager = manager.DisableUpdateManager = true;

            LoadApplication(new App.App(
                                null,
                                Resolver.Resolve <IAuthService>(),
                                Resolver.Resolve <IConnectivity>(),
                                Resolver.Resolve <IDatabaseService>(),
                                Resolver.Resolve <ISyncService>(),
                                Resolver.Resolve <ISettings>(),
                                _lockService,
                                Resolver.Resolve <ILocalizeService>(),
                                Resolver.Resolve <IAppInfoService>(),
                                Resolver.Resolve <IAppSettingsService>(),
                                Resolver.Resolve <IDeviceActionService>()));

            // Appearance stuff

            var primaryColor = new UIColor(red: 0.24f, green: 0.55f, blue: 0.74f, alpha: 1.0f);
            var grayLight    = new UIColor(red: 0.47f, green: 0.47f, blue: 0.47f, alpha: 1.0f);

            UINavigationBar.Appearance.ShadowImage = new UIImage();
            UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
            UIBarButtonItem.AppearanceWhenContainedIn(new Type[] { typeof(UISearchBar) }).TintColor = primaryColor;
            UIButton.AppearanceWhenContainedIn(new Type[] { typeof(UISearchBar) }).SetTitleColor(primaryColor,
                                                                                                 UIControlState.Normal);
            UIButton.AppearanceWhenContainedIn(new Type[] { typeof(UISearchBar) }).TintColor = primaryColor;
            UIStepper.Appearance.TintColor = grayLight;
            UISlider.Appearance.TintColor  = primaryColor;

            MessagingCenter.Subscribe <Xamarin.Forms.Application, ToolsExtensionPage>(
                Xamarin.Forms.Application.Current, "ShowAppExtension", (sender, page) =>
            {
                var itemProvider           = new NSItemProvider(new NSDictionary(), Core.Constants.UTTypeAppExtensionSetup);
                var extensionItem          = new NSExtensionItem();
                extensionItem.Attachments  = new NSItemProvider[] { itemProvider };
                var activityViewController = new UIActivityViewController(new NSExtensionItem[] { extensionItem }, null);
                activityViewController.CompletionHandler = (activityType, completed) =>
                {
                    page.EnabledExtension(completed && activityType == "com.8bit.bitwarden.find-login-action-extension");
                };

                var modal = UIApplication.SharedApplication.KeyWindow.RootViewController.ModalViewController;
                if (activityViewController.PopoverPresentationController != null)
                {
                    activityViewController.PopoverPresentationController.SourceView = modal.View;
                    var frame     = UIScreen.MainScreen.Bounds;
                    frame.Height /= 2;
                    activityViewController.PopoverPresentationController.SourceRect = frame;
                }

                modal.PresentViewController(activityViewController, true, null);
            });

            MessagingCenter.Subscribe <Xamarin.Forms.Application, bool>(
                Xamarin.Forms.Application.Current, "ListenYubiKeyOTP", (sender, listen) =>
            {
                if (_deviceInfoService.NfcEnabled)
                {
                    _nfcSession?.InvalidateSession();
                    _nfcSession?.Dispose();
                    _nfcSession = null;
                    if (listen)
                    {
                        _nfcSession = new NFCNdefReaderSession(_nfcDelegate, null, true);
                        _nfcSession.AlertMessage = AppResources.HoldYubikeyNearTop;
                        _nfcSession.BeginSession();
                    }
                }
            });

            UIApplication.SharedApplication.StatusBarHidden = false;
            UIApplication.SharedApplication.StatusBarStyle  = UIStatusBarStyle.LightContent;

            MessagingCenter.Subscribe <Xamarin.Forms.Application, bool>(
                Xamarin.Forms.Application.Current, "ShowStatusBar", (sender, show) =>
            {
                UIApplication.SharedApplication.SetStatusBarHidden(!show, false);
            });

            MessagingCenter.Subscribe <Xamarin.Forms.Application, bool>(
                Xamarin.Forms.Application.Current, "FullSyncCompleted", async(sender, successfully) =>
            {
                if (_deviceInfoService.Version >= 12 && successfully)
                {
                    await ASHelpers.ReplaceAllIdentities(_cipherService);
                }
            });

            MessagingCenter.Subscribe <Xamarin.Forms.Application, Tuple <string, bool> >(
                Xamarin.Forms.Application.Current, "UpsertedCipher", async(sender, data) =>
            {
                if (_deviceInfoService.Version >= 12)
                {
                    if (await ASHelpers.IdentitiesCanIncremental())
                    {
                        if (data.Item2)
                        {
                            var identity = await ASHelpers.GetCipherIdentityAsync(data.Item1, _cipherService);
                            if (identity == null)
                            {
                                return;
                            }
                            await ASCredentialIdentityStore.SharedStore?.SaveCredentialIdentitiesAsync(
                                new ASPasswordCredentialIdentity[] { identity });
                            return;
                        }
                    }
                    await ASHelpers.ReplaceAllIdentities(_cipherService);
                }
            });

            MessagingCenter.Subscribe <Xamarin.Forms.Application, Cipher>(
                Xamarin.Forms.Application.Current, "DeletedCipher", async(sender, cipher) =>
            {
                if (_deviceInfoService.Version >= 12)
                {
                    if (await ASHelpers.IdentitiesCanIncremental())
                    {
                        var identity = ASHelpers.ToCredentialIdentity(cipher);
                        if (identity == null)
                        {
                            return;
                        }
                        await ASCredentialIdentityStore.SharedStore?.RemoveCredentialIdentitiesAsync(
                            new ASPasswordCredentialIdentity[] { identity });
                        return;
                    }
                    await ASHelpers.ReplaceAllIdentities(_cipherService);
                }
            });

            MessagingCenter.Subscribe <Xamarin.Forms.Application>(
                Xamarin.Forms.Application.Current, "LoggedOut", async(sender) =>
            {
                if (_deviceInfoService.Version >= 12)
                {
                    await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync();
                }
            });

            ZXing.Net.Mobile.Forms.iOS.Platform.Init();
            return(base.FinishedLaunching(app, options));
        }
Пример #7
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Forms.Init();
            InitApp();

            _deviceActionService  = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");
            _messagingService     = ServiceContainer.Resolve <IMessagingService>("messagingService");
            _broadcasterService   = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService");
            _storageService       = ServiceContainer.Resolve <IStorageService>("storageService");
            _lockService          = ServiceContainer.Resolve <ILockService>("lockService");
            _eventService         = ServiceContainer.Resolve <IEventService>("eventService");
            _platformUtilsService = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService");
            _cozyClientService    = ServiceContainer.Resolve <ICozyClientService>("cozyClientService");

            LoadApplication(new App.App(null));
            iOSCoreHelpers.AppearanceAdjustments(_deviceActionService);
            ZXing.Net.Mobile.Forms.iOS.Platform.Init();

            _broadcasterService.Subscribe(nameof(AppDelegate), async(message) =>
            {
                if (message.Command == "scheduleLockTimer")
                {
                    LockTimer((int)message.Data);
                }
                else if (message.Command == "cancelLockTimer")
                {
                    CancelLockTimer();
                }
                else if (message.Command == "startEventTimer")
                {
                    StartEventTimer();
                }
                else if (message.Command == "stopEventTimer")
                {
                    var task = StopEventTimerAsync();
                }
                else if (message.Command == "updatedTheme")
                {
                    // ThemeManager.SetThemeStyle(message.Data as string);
                }
                else if (message.Command == "copiedToClipboard")
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        var task = ClearClipboardTimerAsync(message.Data as Tuple <string, int?, bool>);
                    });
                }
                else if (message.Command == "listenYubiKeyOTP")
                {
                    ListenYubiKey((bool)message.Data);
                }
                else if (message.Command == "unlocked")
                {
                    var needsAutofillReplacement = await _storageService.GetAsync <bool?>(
                        Core.Constants.AutofillNeedsIdentityReplacementKey);
                    if (needsAutofillReplacement.GetValueOrDefault())
                    {
                        await ASHelpers.ReplaceAllIdentities();
                    }
                }
                else if (message.Command == "showAppExtension")
                {
                    Device.BeginInvokeOnMainThread(() => ShowAppExtension((ExtensionPageViewModel)message.Data));
                }
                else if (message.Command == "showStatusBar")
                {
                    Device.BeginInvokeOnMainThread(() =>
                                                   UIApplication.SharedApplication.SetStatusBarHidden(!(bool)message.Data, false));
                }
                else if (message.Command == "syncCompleted")
                {
                    if (message.Data is Dictionary <string, object> data && data.ContainsKey("successfully"))
                    {
                        var success = data["successfully"] as bool?;
                        if (success.GetValueOrDefault() && _deviceActionService.SystemMajorVersion() >= 12)
                        {
                            await ASHelpers.ReplaceAllIdentities();
                        }
                    }
                }
                else if (message.Command == "addedCipher" || message.Command == "editedCipher")
                {
                    if (_deviceActionService.SystemMajorVersion() >= 12)
                    {
                        if (await ASHelpers.IdentitiesCanIncremental())
                        {
                            var cipherId = message.Data as string;
                            if (message.Command == "addedCipher" && !string.IsNullOrWhiteSpace(cipherId))
                            {
                                var identity = await ASHelpers.GetCipherIdentityAsync(cipherId);
                                if (identity == null)
                                {
                                    return;
                                }
                                await ASCredentialIdentityStore.SharedStore?.SaveCredentialIdentitiesAsync(
                                    new ASPasswordCredentialIdentity[] { identity });
                                return;
                            }
                        }
                        await ASHelpers.ReplaceAllIdentities();
                    }
                }
                else if (message.Command == "deletedCipher")
                {
                    if (_deviceActionService.SystemMajorVersion() >= 12)
                    {
                        if (await ASHelpers.IdentitiesCanIncremental())
                        {
                            var identity = ASHelpers.ToCredentialIdentity(
                                message.Data as Bit.Core.Models.View.CipherView);
                            if (identity == null)
                            {
                                return;
                            }
                            await ASCredentialIdentityStore.SharedStore?.RemoveCredentialIdentitiesAsync(
                                new ASPasswordCredentialIdentity[] { identity });
                            return;
                        }
                        await ASHelpers.ReplaceAllIdentities();
                    }
                }
                else if (message.Command == "loggedOut")
                {
                    if (_deviceActionService.SystemMajorVersion() >= 12)
                    {
                        await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync();
                    }
                }
            });

            return(base.FinishedLaunching(app, options));
        }
        protected async Task SaveAsync()
        {
            /*
             * 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 cipher = new CipherView
            {
                Name     = NameCell.TextField.Text,
                Notes    = string.IsNullOrWhiteSpace(NotesCell?.TextView?.Text) ? null : NotesCell.TextView.Text,
                Favorite = FavoriteCell.Switch.On,
                FolderId = FolderCell.SelectedIndex == 0 ?
                           null : _folders.ElementAtOrDefault(FolderCell.SelectedIndex - 1)?.Id,
                Type  = Bit.Core.Enums.CipherType.Login,
                Login = new LoginView
                {
                    Uris     = null,
                    Username = string.IsNullOrWhiteSpace(UsernameCell?.TextField?.Text) ?
                               null : UsernameCell.TextField.Text,
                    Password = string.IsNullOrWhiteSpace(PasswordCell.TextField.Text) ?
                               null : PasswordCell.TextField.Text,
                }
            };

            if (!string.IsNullOrWhiteSpace(UriCell?.TextField?.Text))
            {
                cipher.Login.Uris = new List <LoginUriView>
                {
                    new LoginUriView
                    {
                        Uri = UriCell.TextField.Text
                    }
                };
            }

            var loadingAlert = Dialogs.CreateLoadingAlert(AppResources.Saving);

            PresentViewController(loadingAlert, true, null);
            try
            {
                var cipherDomain = await _cipherService.EncryptAsync(cipher);

                await _cipherService.SaveWithServerAsync(cipherDomain);

                await loadingAlert.DismissViewControllerAsync(true);

                await _storageService.SaveAsync(Bit.Core.Constants.ClearCiphersCacheKey, true);

                if (await ASHelpers.IdentitiesCanIncremental())
                {
                    var identity = await ASHelpers.GetCipherIdentityAsync(cipherDomain.Id);

                    if (identity != null)
                    {
                        await ASCredentialIdentityStore.SharedStore.SaveCredentialIdentitiesAsync(
                            new ASPasswordCredentialIdentity[] { identity });
                    }
                }
                else
                {
                    await ASHelpers.ReplaceAllIdentities();
                }
                Success(cipherDomain.Id);
            }
            catch (ApiException e)
            {
                if (e?.Error != null)
                {
                    DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok);
                }
            }
        }
Пример #9
0
        protected async Task SaveAsync()
        {
            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 cipher = new Cipher
            {
                Name     = string.IsNullOrWhiteSpace(NameCell.TextField.Text) ? null : NameCell.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,
                Type     = App.Enums.CipherType.Login,
                Login    = new Login
                {
                    Uris     = null,
                    Username = string.IsNullOrWhiteSpace(UsernameCell.TextField.Text) ? null : UsernameCell.TextField.Text.Encrypt(),
                    Password = string.IsNullOrWhiteSpace(PasswordCell.TextField.Text) ? null : PasswordCell.TextField.Text.Encrypt()
                }
            };

            if (!string.IsNullOrWhiteSpace(UriCell.TextField.Text))
            {
                cipher.Login.Uris = new List <LoginUri>
                {
                    new LoginUri
                    {
                        Uri = UriCell.TextField.Text.Encrypt()
                    }
                };
            }

            var saveTask     = _cipherService.SaveAsync(cipher);
            var loadingAlert = Dialogs.CreateLoadingAlert(AppResources.Saving);

            PresentViewController(loadingAlert, true, null);
            await saveTask;

            await loadingAlert.DismissViewControllerAsync(true);

            if (saveTask.Result.Succeeded)
            {
                if (await ASHelpers.IdentitiesCanIncremental())
                {
                    var identity = await ASHelpers.GetCipherIdentityAsync(saveTask.Result.Result.Id, _cipherService);

                    if (identity == null)
                    {
                        return;
                    }
                    await ASCredentialIdentityStore.SharedStore.SaveCredentialIdentitiesAsync(
                        new ASPasswordCredentialIdentity[] { identity });
                }
                else
                {
                    await ASHelpers.ReplaceAllIdentities(_cipherService);
                }
                Success();
            }
            else if (saveTask.Result.Errors.Count() > 0)
            {
                DisplayAlert(AppResources.AnErrorHasOccurred, saveTask.Result.Errors.First().Message, AppResources.Ok);
            }
            else
            {
                DisplayAlert(null, AppResources.AnErrorHasOccurred, AppResources.Ok);
            }
        }
Пример #10
0
 public async Task OnAccountSwitchCompleteAsync()
 {
     await ASHelpers.ReplaceAllIdentities();
 }