Пример #1
0
        private void Init()
        {
            // Name
            NameCell = new FormEntryCell(AppResources.Name);
            if (!string.IsNullOrWhiteSpace(_defaultName))
            {
                NameCell.Entry.Text = _defaultName;
            }

            // Notes
            NotesCell = new FormEditorCell(Keyboard.Text, _type == CipherType.SecureNote ? 500 : 180);

            // Folders
            var folderOptions = new List <string> {
                AppResources.FolderNone
            };

            Folders = _folderService.GetAllAsync().GetAwaiter().GetResult()
                      .OrderBy(f => f.Name?.Decrypt()).ToList();
            var selectedIndex = 0;
            var i             = 1;

            foreach (var folder in Folders)
            {
                if (folder.Id == _defaultFolderId)
                {
                    selectedIndex = i;
                }
                folderOptions.Add(folder.Name.Decrypt());
                i++;
            }
            FolderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray());
            FolderCell.Picker.SelectedIndex = selectedIndex;

            // Favorite
            FavoriteCell = new ExtendedSwitchCell {
                Text = AppResources.Favorite
            };

            InitTable();
            InitSave();

            Title   = AppResources.AddItem;
            Content = Table;
            if (Device.RuntimePlatform == Device.iOS)
            {
                ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel));
            }
        }
        public void Init()
        {
            UppercaseCell = new ExtendedSwitchCell
            {
                Text = "A-Z",
                On   = _settings.GetValueOrDefault(Constants.PasswordGeneratorUppercase, true)
            };
            UppercaseCell.OnChanged += UppercaseCell_OnChanged;

            LowercaseCell = new ExtendedSwitchCell
            {
                Text = "a-z",
                On   = _settings.GetValueOrDefault(Constants.PasswordGeneratorLowercase, true)
            };
            LowercaseCell.OnChanged += LowercaseCell_OnChanged;

            SpecialCell = new ExtendedSwitchCell
            {
                Text = "!@#$%^&*",
                On   = _settings.GetValueOrDefault(Constants.PasswordGeneratorSpecial, true)
            };
            SpecialCell.OnChanged += SpecialCell_OnChanged;

            NumbersCell = new ExtendedSwitchCell
            {
                Text = "0-9",
                On   = _settings.GetValueOrDefault(Constants.PasswordGeneratorNumbers, true)
            };
            NumbersCell.OnChanged += NumbersCell_OnChanged;

            AvoidAmbiguousCell = new ExtendedSwitchCell
            {
                Text = AppResources.AvoidAmbiguousCharacters,
                On   = !_settings.GetValueOrDefault(Constants.PasswordGeneratorAmbiguous, false)
            };
            AvoidAmbiguousCell.OnChanged += AvoidAmbiguousCell_OnChanged;;

            NumbersMinCell = new StepperCell(AppResources.MinNumbers,
                                             _settings.GetValueOrDefault(Constants.PasswordGeneratorMinNumbers, 1), 0, 5, 1);
            SpecialMinCell = new StepperCell(AppResources.MinSpecial,
                                             _settings.GetValueOrDefault(Constants.PasswordGeneratorMinSpecial, 1), 0, 5, 1);

            var table = new ExtendedTableView
            {
                EnableScrolling = true,
                Intent          = TableIntent.Settings,
                HasUnevenRows   = true,
                EnableSelection = false,
                Root            = new TableRoot
                {
                    new TableSection
                    {
                        UppercaseCell,
                        LowercaseCell,
                        NumbersCell,
                        SpecialCell
                    },
                    new TableSection
                    {
                        NumbersMinCell,
                        SpecialMinCell
                    },
                    new TableSection
                    {
                        AvoidAmbiguousCell
                    }
                }
            };

            if (Device.OS == TargetPlatform.iOS)
            {
                table.RowHeight          = -1;
                table.EstimatedRowHeight = 44;
            }

            Title   = AppResources.Settings;
            Content = table;
        }
Пример #3
0
        private void Init()
        {
            Cipher = _cipherService.GetByIdAsync(_cipherId).GetAwaiter().GetResult();
            if (Cipher == null)
            {
                // TODO: handle error. navigate back? should never happen...
                return;
            }

            // Name
            NameCell            = new FormEntryCell(AppResources.Name);
            NameCell.Entry.Text = Cipher.Name?.Decrypt(Cipher.OrganizationId);

            // Notes
            NotesCell             = new FormEditorCell(Keyboard.Text, Cipher.Type == CipherType.SecureNote ? 500 : 180);
            NotesCell.Editor.Text = Cipher.Notes?.Decrypt(Cipher.OrganizationId);

            // Folders
            var folderOptions = new List <string> {
                AppResources.FolderNone
            };

            Folders = _folderService.GetAllAsync().GetAwaiter().GetResult()
                      .OrderBy(f => f.Name?.Decrypt()).ToList();
            int selectedIndex = 0;
            int i             = 0;

            foreach (var folder in Folders)
            {
                i++;
                if (folder.Id == Cipher.FolderId)
                {
                    selectedIndex = i;
                }

                folderOptions.Add(folder.Name.Decrypt());
            }
            FolderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray());
            FolderCell.Picker.SelectedIndex = selectedIndex;

            // Favorite
            FavoriteCell = new ExtendedSwitchCell
            {
                Text = AppResources.Favorite,
                On   = Cipher.Favorite
            };

            // Delete
            DeleteCell = new ExtendedTextCell {
                Text = AppResources.Delete, TextColor = Color.Red
            };

            InitTable();
            InitSave();

            Title   = AppResources.EditItem;
            Content = Table;
            if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Windows)
            {
                ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel));
            }
        }
Пример #4
0
        private void Init()
        {
            WebsiteIconsCell = new ExtendedSwitchCell
            {
                Text = AppResources.DisableWebsiteIcons,
                On   = _appSettings.DisableWebsiteIcons
            };

            var websiteIconsTable = new FormTableView(this, true)
            {
                Root = new TableRoot
                {
                    new TableSection(Helpers.GetEmptyTableSectionTitle())
                    {
                        WebsiteIconsCell
                    }
                }
            };

            CopyTotpCell = new ExtendedSwitchCell
            {
                Text = AppResources.DisableAutoTotpCopy,
                On   = _settings.GetValueOrDefault(Constants.SettingDisableTotpCopy, false)
            };

            var totpTable = new FormTableView(this)
            {
                Root = new TableRoot
                {
                    new TableSection(Helpers.GetEmptyTableSectionTitle())
                    {
                        CopyTotpCell
                    }
                }
            };

            CopyTotpLabel = new FormTableLabel(this)
            {
                Text = AppResources.DisableAutoTotpCopyDescription
            };

            WebsiteIconsLabel = new FormTableLabel(this)
            {
                Text = AppResources.DisableWebsiteIconsDescription
            };

            StackLayout = new RedrawableStackLayout
            {
                Children =
                {
                    websiteIconsTable, WebsiteIconsLabel,
                    totpTable,         CopyTotpLabel
                },
                Spacing = 0
            };

            if (Device.RuntimePlatform == Device.Android)
            {
                AutofillAlwaysCell = new ExtendedSwitchCell
                {
                    Text = AppResources.AutofillAlways,
                    On   = !_appSettings.AutofillPersistNotification && !_appSettings.AutofillPasswordField
                };

                var autofillAlwaysTable = new FormTableView(this, true)
                {
                    Root = new TableRoot
                    {
                        new TableSection(AppResources.AutofillAccessibilityService)
                        {
                            AutofillAlwaysCell
                        }
                    }
                };

                AutofillAlwaysLabel = new FormTableLabel(this)
                {
                    Text = AppResources.AutofillAlwaysDescription
                };

                AutofillPersistNotificationCell = new ExtendedSwitchCell
                {
                    Text = AppResources.AutofillPersistNotification,
                    On   = _appSettings.AutofillPersistNotification
                };

                var autofillPersistNotificationTable = new FormTableView(this)
                {
                    Root = new TableRoot
                    {
                        new TableSection(Helpers.GetEmptyTableSectionTitle())
                        {
                            AutofillPersistNotificationCell
                        }
                    }
                };

                AutofillPersistNotificationLabel = new FormTableLabel(this)
                {
                    Text = AppResources.AutofillPersistNotificationDescription
                };

                AutofillPasswordFieldCell = new ExtendedSwitchCell
                {
                    Text = AppResources.AutofillPasswordField,
                    On   = _appSettings.AutofillPasswordField
                };

                var autofillPasswordFieldTable = new FormTableView(this)
                {
                    Root = new TableRoot
                    {
                        new TableSection(Helpers.GetEmptyTableSectionTitle())
                        {
                            AutofillPasswordFieldCell
                        }
                    }
                };

                AutofillPasswordFieldLabel = new FormTableLabel(this)
                {
                    Text = AppResources.AutofillPasswordFieldDescription
                };

                StackLayout.Children.Add(autofillAlwaysTable);
                StackLayout.Children.Add(AutofillAlwaysLabel);
                StackLayout.Children.Add(autofillPasswordFieldTable);
                StackLayout.Children.Add(AutofillPasswordFieldLabel);
                StackLayout.Children.Add(autofillPersistNotificationTable);
                StackLayout.Children.Add(AutofillPersistNotificationLabel);
            }

            var scrollView = new ScrollView
            {
                Content = StackLayout
            };

            if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.UWP)
            {
                ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Close));
            }

            Title   = AppResources.Options;
            Content = scrollView;
        }
Пример #5
0
        public static Cell MakeFieldCell(FieldType type, string label, string value, TableSection fieldsSection)
        {
            Cell cell;

            switch (type)
            {
            case FieldType.Text:
            case FieldType.Hidden:
                var hidden        = type == FieldType.Hidden;
                var textFieldCell = new FormEntryCell(label, isPassword: hidden,
                                                      button1: hidden ? "eye.png" : null);
                textFieldCell.Entry.Text = value;
                textFieldCell.Entry.DisableAutocapitalize = true;
                textFieldCell.Entry.Autocorrect           = false;

                if (hidden)
                {
                    textFieldCell.Entry.FontFamily = Helpers.OnPlatform(
                        iOS: "Menlo-Regular", Android: "monospace", Windows: "Courier");
                    textFieldCell.Button1.Command = new Command(() =>
                    {
                        textFieldCell.Entry.InvokeToggleIsPassword();
                        textFieldCell.Button1.Image =
                            "eye" + (!textFieldCell.Entry.IsPasswordFromToggled ? "_slash" : string.Empty) + ".png";
                    });
                }
                cell = textFieldCell;
                break;

            case FieldType.Boolean:
                var switchFieldCell = new ExtendedSwitchCell
                {
                    Text = label,
                    On   = value == "true"
                };
                cell = switchFieldCell;
                break;

            default:
                cell = null;
                break;
            }

            if (cell != null)
            {
                var deleteAction = new MenuItem {
                    Text = AppResources.Remove, IsDestructive = true
                };
                deleteAction.Clicked += (sender, e) =>
                {
                    if (fieldsSection.Contains(cell))
                    {
                        fieldsSection.Remove(cell);
                    }

                    if (cell is FormEntryCell feCell)
                    {
                        feCell.Dispose();
                    }
                    cell = null;
                };

                var editNameAction = new MenuItem {
                    Text = AppResources.Edit
                };
                editNameAction.Clicked += async(sender, e) =>
                {
                    string existingLabel = null;
                    var    feCell        = cell as FormEntryCell;
                    var    esCell        = cell as ExtendedSwitchCell;
                    if (feCell != null)
                    {
                        existingLabel = feCell.Label.Text;
                    }
                    else if (esCell != null)
                    {
                        existingLabel = esCell.Text;
                    }

                    var daService = Resolver.Resolve <IDeviceActionService>();
                    var editLabel = await daService.DisplayPromptAync(AppResources.CustomFieldName,
                                                                      null, existingLabel);

                    if (editLabel != null)
                    {
                        if (feCell != null)
                        {
                            feCell.Label.Text = editLabel;
                        }
                        else if (esCell != null)
                        {
                            esCell.Text = editLabel;
                        }
                    }
                };

                cell.ContextActions.Add(editNameAction);
                cell.ContextActions.Add(deleteAction);
            }

            return(cell);
        }
Пример #6
0
        private void Init()
        {
            PinCell = new ExtendedSwitchCell
            {
                Text = "Unlock with PIN Code",
                On   = _settings.GetValueOrDefault(Constants.SettingPinUnlockOn, false)
            };
            PinCell.OnChanged += PinCell_Changed;

            LockOptionsCell = new ExtendedTextCell
            {
                Text            = "Lock Options",
                Detail          = GetLockOptionsDetailsText(),
                ShowDisclousure = true
            };
            LockOptionsCell.Tapped += LockOptionsCell_Tapped;

            var twoStepCell = new ExtendedTextCell
            {
                Text            = "Two-step Login",
                ShowDisclousure = true
            };

            twoStepCell.Tapped += TwoStepCell_Tapped;;

            var securitySecion = new TableSection("Security")
            {
                LockOptionsCell,
                PinCell,
                twoStepCell
            };

            if (_fingerprint.IsAvailable)
            {
                var fingerprintName = Device.OnPlatform(iOS: "Touch ID", Android: "Fingerprint", WinPhone: "Fingerprint");
                FingerprintCell = new ExtendedSwitchCell
                {
                    Text      = "Unlock with " + fingerprintName,
                    On        = _settings.GetValueOrDefault(Constants.SettingFingerprintUnlockOn, false),
                    IsEnabled = _fingerprint.IsAvailable
                };
                FingerprintCell.OnChanged += FingerprintCell_Changed;
                securitySecion.Insert(1, FingerprintCell);
            }

            var changeMasterPasswordCell = new ExtendedTextCell
            {
                Text            = "Change Master Password",
                ShowDisclousure = true
            };

            changeMasterPasswordCell.Tapped += ChangeMasterPasswordCell_Tapped;

            var changeEmailCell = new ExtendedTextCell
            {
                Text            = "Change Email",
                ShowDisclousure = true
            };

            changeEmailCell.Tapped += ChangeEmailCell_Tapped;

            var foldersCell = new ExtendedTextCell
            {
                Text            = "Folders",
                ShowDisclousure = true
            };

            foldersCell.Tapped += FoldersCell_Tapped;

            var syncCell = new ExtendedTextCell
            {
                Text            = "Sync",
                ShowDisclousure = true
            };

            syncCell.Tapped += SyncCell_Tapped;

            var lockCell = new ExtendedTextCell
            {
                Text = "Lock"
            };

            lockCell.Tapped += LockCell_Tapped;

            var logOutCell = new ExtendedTextCell
            {
                Text = "Log Out"
            };

            logOutCell.Tapped += LogOutCell_Tapped;

            var aboutCell = new ExtendedTextCell
            {
                Text            = "About",
                ShowDisclousure = true
            };

            aboutCell.Tapped += AboutCell_Tapped;

            var helpCell = new ExtendedTextCell
            {
                Text            = "Help and Feedback",
                ShowDisclousure = true
            };

            helpCell.Tapped += HelpCell_Tapped;

            var otherSection = new TableSection("Other")
            {
                aboutCell,
                helpCell
            };

            if (Device.OS == TargetPlatform.iOS)
            {
                var rateCell = new LongDetailViewCell("Rate the App",
                                                      "App Store ratings are reset with every new version of bitwarden."
                                                      + " Please consider helping us out with a good review!");
                rateCell.Tapped += RateCell_Tapped;
                otherSection.Add(rateCell);
            }
            else
            {
                var rateCell = new ExtendedTextCell
                {
                    Text                = "Rate the App",
                    Detail              = "Please consider helping us out with a good review!",
                    ShowDisclousure     = true,
                    DetailLineBreakMode = LineBreakMode.WordWrap
                };
                rateCell.Tapped += RateCell_Tapped;
                otherSection.Add(rateCell);
            }

            Table = new CustomTable
            {
                Root = new TableRoot
                {
                    securitySecion,
                    new TableSection("Account")
                    {
                        changeMasterPasswordCell,
                        changeEmailCell
                    },
                    new TableSection("Manage")
                    {
                        foldersCell,
                        syncCell
                    },
                    new TableSection("Current Session")
                    {
                        lockCell,
                        logOutCell
                    },
                    otherSection
                }
            };

            Title   = AppResources.Settings;
            Content = Table;
        }
Пример #7
0
        private void Init()
        {
            var notesCell = new FormEditorCell(height: 90);

            PasswordCell = new FormEntryCell(AppResources.Password, isPassword: true, nextElement: notesCell.Editor,
                                             useButton: true);
            PasswordCell.Button.Image    = "eye";
            PasswordCell.Button.Clicked += PasswordButton_Clicked;
            PasswordCell.Entry.DisableAutocapitalize = true;
            PasswordCell.Entry.Autocorrect           = false;
            PasswordCell.Entry.FontFamily            = Device.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier");

            var usernameCell = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry);

            usernameCell.Entry.DisableAutocapitalize = true;
            usernameCell.Entry.Autocorrect           = false;

            var uriCell  = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry);
            var nameCell = new FormEntryCell(AppResources.Name, nextElement: uriCell.Entry);

            var folderOptions = new List <string> {
                AppResources.FolderNone
            };
            var folders = _folderService.GetAllAsync().GetAwaiter().GetResult()
                          .OrderBy(f => f.Name?.Decrypt()).ToList();

            foreach (var folder in folders)
            {
                folderOptions.Add(folder.Name.Decrypt());
            }
            var folderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray());

            var generateCell = new ExtendedTextCell
            {
                Text            = AppResources.GeneratePassword,
                ShowDisclousure = true
            };

            generateCell.Tapped += GenerateCell_Tapped;;

            var favoriteCell = new ExtendedSwitchCell {
                Text = AppResources.Favorite
            };

            var table = new ExtendedTableView
            {
                Intent          = TableIntent.Settings,
                EnableScrolling = true,
                HasUnevenRows   = true,
                Root            = new TableRoot
                {
                    new TableSection(AppResources.SiteInformation)
                    {
                        nameCell,
                        uriCell,
                        usernameCell,
                        PasswordCell,
                        generateCell
                    },
                    new TableSection
                    {
                        folderCell,
                        favoriteCell
                    },
                    new TableSection(AppResources.Notes)
                    {
                        notesCell
                    }
                }
            };

            if (Device.OS == TargetPlatform.iOS)
            {
                table.RowHeight          = -1;
                table.EstimatedRowHeight = 70;
            }
            else if (Device.OS == TargetPlatform.Android)
            {
                PasswordCell.Button.WidthRequest = 40;
            }

            var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async() =>
            {
                if (!_connectivity.IsConnected)
                {
                    AlertNoConnection();
                    return;
                }

                if (string.IsNullOrWhiteSpace(nameCell.Entry.Text))
                {
                    await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
                                                                                      AppResources.Name), AppResources.Ok);
                    return;
                }

                var site = new Site
                {
                    Uri      = uriCell.Entry.Text?.Encrypt(),
                    Name     = nameCell.Entry.Text?.Encrypt(),
                    Username = usernameCell.Entry.Text?.Encrypt(),
                    Password = PasswordCell.Entry.Text?.Encrypt(),
                    Notes    = notesCell.Editor.Text?.Encrypt(),
                    Favorite = favoriteCell.On
                };

                if (folderCell.Picker.SelectedIndex > 0)
                {
                    site.FolderId = folders.ElementAt(folderCell.Picker.SelectedIndex - 1).Id;
                }

                _userDialogs.ShowLoading(AppResources.Saving, MaskType.Black);
                var saveTask = await _siteService.SaveAsync(site);

                _userDialogs.HideLoading();
                if (saveTask.Succeeded)
                {
                    await Navigation.PopForDeviceAsync();
                    _userDialogs.Toast(AppResources.NewSiteCreated);
                    _googleAnalyticsService.TrackAppEvent("CreatedSite");
                }
                else if (saveTask.Errors.Count() > 0)
                {
                    await _userDialogs.AlertAsync(saveTask.Errors.First().Message, AppResources.AnErrorHasOccurred);
                }
                else
                {
                    await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred);
                }
            }, ToolbarItemOrder.Default, 0);

            Title   = AppResources.AddSite;
            Content = table;
            ToolbarItems.Add(saveToolBarItem);
            if (Device.OS == TargetPlatform.iOS)
            {
                ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel));
            }
        }
        private void Init()
        {
            var site = _siteService.GetByIdAsync(_siteId).GetAwaiter().GetResult();

            if (site == null)
            {
                // TODO: handle error. navigate back? should never happen...
                return;
            }

            var notesCell = new FormEditorCell(height: 90);

            notesCell.Editor.Text   = site.Notes?.Decrypt();
            PasswordCell            = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor);
            PasswordCell.Entry.Text = site.Password?.Decrypt();
            var usernameCell = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry);

            usernameCell.Entry.Text = site.Username?.Decrypt();
            usernameCell.Entry.DisableAutocapitalize = true;
            usernameCell.Entry.Autocorrect           = false;

            usernameCell.Entry.FontFamily = PasswordCell.Entry.FontFamily = Device.OnPlatform(
                iOS: "Courier", Android: "monospace", WinPhone: "Courier");

            var uriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry);

            uriCell.Entry.Text = site.Uri?.Decrypt();
            var nameCell = new FormEntryCell(AppResources.Name, nextElement: uriCell.Entry);

            nameCell.Entry.Text = site.Name?.Decrypt();

            var generateCell = new ExtendedTextCell
            {
                Text            = "Generate Password",
                ShowDisclousure = true
            };

            generateCell.Tapped += GenerateCell_Tapped;;

            var folderOptions = new List <string> {
                AppResources.FolderNone
            };
            var folders = _folderService.GetAllAsync().GetAwaiter().GetResult()
                          .OrderBy(f => f.Name?.Decrypt()).ToList();
            int selectedIndex = 0;
            int i             = 0;

            foreach (var folder in folders)
            {
                i++;
                if (folder.Id == site.FolderId)
                {
                    selectedIndex = i;
                }

                folderOptions.Add(folder.Name.Decrypt());
            }
            var folderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray());

            folderCell.Picker.SelectedIndex = selectedIndex;

            var favoriteCell = new ExtendedSwitchCell
            {
                Text = "Favorite",
                On   = site.Favorite
            };

            var deleteCell = new ExtendedTextCell {
                Text = AppResources.Delete, TextColor = Color.Red
            };

            deleteCell.Tapped += DeleteCell_Tapped;

            var table = new ExtendedTableView
            {
                Intent          = TableIntent.Settings,
                EnableScrolling = true,
                HasUnevenRows   = true,
                Root            = new TableRoot
                {
                    new TableSection("Site Information")
                    {
                        nameCell,
                        uriCell,
                        usernameCell,
                        PasswordCell,
                        generateCell
                    },
                    new TableSection
                    {
                        folderCell,
                        favoriteCell
                    },
                    new TableSection(AppResources.Notes)
                    {
                        notesCell
                    },
                    new TableSection
                    {
                        deleteCell
                    }
                }
            };

            if (Device.OS == TargetPlatform.iOS)
            {
                table.RowHeight          = -1;
                table.EstimatedRowHeight = 70;
            }

            var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async() =>
            {
                if (!_connectivity.IsConnected)
                {
                    AlertNoConnection();
                    return;
                }

                if (string.IsNullOrWhiteSpace(PasswordCell.Entry.Text))
                {
                    await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
                                                                                      AppResources.Password), AppResources.Ok);
                    return;
                }

                if (string.IsNullOrWhiteSpace(nameCell.Entry.Text))
                {
                    await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
                                                                                      AppResources.Name), AppResources.Ok);
                    return;
                }

                site.Uri      = uriCell.Entry.Text?.Encrypt();
                site.Name     = nameCell.Entry.Text?.Encrypt();
                site.Username = usernameCell.Entry.Text?.Encrypt();
                site.Password = PasswordCell.Entry.Text?.Encrypt();
                site.Notes    = notesCell.Editor.Text?.Encrypt();
                site.Favorite = favoriteCell.On;

                if (folderCell.Picker.SelectedIndex > 0)
                {
                    site.FolderId = folders.ElementAt(folderCell.Picker.SelectedIndex - 1).Id;
                }
                else
                {
                    site.FolderId = null;
                }

                _userDialogs.ShowLoading("Saving...", MaskType.Black);
                var saveTask = await _siteService.SaveAsync(site);

                _userDialogs.HideLoading();

                if (saveTask.Succeeded)
                {
                    await Navigation.PopForDeviceAsync();
                    _userDialogs.Toast("Site updated.");
                    _googleAnalyticsService.TrackAppEvent("EditedSite");
                }
                else if (saveTask.Errors.Count() > 0)
                {
                    await _userDialogs.AlertAsync(saveTask.Errors.First().Message, AppResources.AnErrorHasOccurred);
                }
                else
                {
                    await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred);
                }
            }, ToolbarItemOrder.Default, 0);

            Title   = "Edit Site";
            Content = table;
            ToolbarItems.Add(saveToolBarItem);
            if (Device.OS == TargetPlatform.iOS)
            {
                ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel"));
            }
        }
Пример #9
0
        private void Init()
        {
            PinCell = new ExtendedSwitchCell
            {
                Text = AppResources.UnlockWithPIN,
                On   = _settings.GetValueOrDefault(Constants.SettingPinUnlockOn, false)
            };

            LockOptionsCell = new ExtendedTextCell
            {
                Text            = AppResources.LockOptions,
                Detail          = GetLockOptionsDetailsText(),
                ShowDisclousure = true
            };

            TwoStepCell = new ExtendedTextCell
            {
                Text            = AppResources.TwoStepLogin,
                ShowDisclousure = true
            };

            var securitySecion = new TableSection(AppResources.Security)
            {
                LockOptionsCell,
                PinCell,
                TwoStepCell
            };

            if (_fingerprint.IsAvailable)
            {
                var fingerprintName = Device.OnPlatform(iOS: AppResources.TouchID, Android: AppResources.Fingerprint,
                                                        WinPhone: AppResources.Fingerprint);
                FingerprintCell = new ExtendedSwitchCell
                {
                    Text      = string.Format(AppResources.UnlockWith, fingerprintName),
                    On        = _settings.GetValueOrDefault(Constants.SettingFingerprintUnlockOn, false),
                    IsEnabled = _fingerprint.IsAvailable
                };
                securitySecion.Insert(1, FingerprintCell);
            }

            ChangeMasterPasswordCell = new ExtendedTextCell
            {
                Text            = AppResources.ChangeMasterPassword,
                ShowDisclousure = true
            };

            ChangeEmailCell = new ExtendedTextCell
            {
                Text            = AppResources.ChangeEmail,
                ShowDisclousure = true
            };

            AnalyticsCell = new ExtendedSwitchCell
            {
                Text = AppResources.DisableGA,
                On   = _settings.GetValueOrDefault(Constants.SettingGaOptOut, false)
            };

            FoldersCell = new ExtendedTextCell
            {
                Text            = AppResources.Folders,
                ShowDisclousure = true
            };

            SyncCell = new ExtendedTextCell
            {
                Text            = AppResources.Sync,
                ShowDisclousure = true
            };

            LockCell = new ExtendedTextCell
            {
                Text = AppResources.Lock
            };

            LogOutCell = new ExtendedTextCell
            {
                Text = AppResources.LogOut
            };

            AboutCell = new ExtendedTextCell
            {
                Text            = AppResources.About,
                ShowDisclousure = true
            };

            HelpCell = new ExtendedTextCell
            {
                Text            = AppResources.HelpAndFeedback,
                ShowDisclousure = true
            };

            var otherSection = new TableSection(AppResources.Other)
            {
                AnalyticsCell,
                AboutCell,
                HelpCell
            };

            if (Device.OS == TargetPlatform.iOS)
            {
                RateCellLong = new LongDetailViewCell(AppResources.RateTheApp, AppResources.RateTheAppDescriptionAppStore);
                otherSection.Add(RateCellLong);
            }
            else
            {
                RateCell = new ExtendedTextCell
                {
                    Text                = AppResources.RateTheApp,
                    Detail              = AppResources.RateTheAppDescription,
                    ShowDisclousure     = true,
                    DetailLineBreakMode = LineBreakMode.WordWrap
                };
                otherSection.Add(RateCell);
            }

            Table = new CustomTable
            {
                Root = new TableRoot
                {
                    securitySecion,
                    new TableSection(AppResources.Account)
                    {
                        ChangeMasterPasswordCell,
                        ChangeEmailCell
                    },
                    new TableSection(AppResources.Manage)
                    {
                        FoldersCell,
                        SyncCell
                    },
                    new TableSection(AppResources.CurrentSession)
                    {
                        LockCell,
                        LogOutCell
                    },
                    otherSection
                }
            };

            Title   = AppResources.Settings;
            Content = Table;
        }
Пример #10
0
        private async void Init()
        {
            PinCell = new ExtendedSwitchCell
            {
                Text = AppResources.UnlockWithPIN,
                On   = _settings.GetValueOrDefault(Constants.SettingPinUnlockOn, false)
            };

            LockOptionsCell = new ExtendedTextCell
            {
                Text            = AppResources.LockOptions,
                Detail          = GetLockOptionsDetailsText(),
                ShowDisclousure = true
            };

            TwoStepCell = new ExtendedTextCell
            {
                Text            = AppResources.TwoStepLogin,
                ShowDisclousure = true
            };

            LockCell = new ExtendedTextCell
            {
                Text = AppResources.Lock
            };

            var securitySecion = new TableSection(AppResources.Security)
            {
                LockOptionsCell,
                PinCell,
                LockCell,
                TwoStepCell
            };

            if ((await _fingerprint.GetAvailabilityAsync()) == FingerprintAvailability.Available)
            {
                var fingerprintName = Helpers.OnPlatform(
                    iOS: _deviceInfoService.HasFaceIdSupport ? AppResources.FaceID : AppResources.TouchID,
                    Android: AppResources.Fingerprint,
                    Windows: AppResources.WindowsHello);
                FingerprintCell = new ExtendedSwitchCell
                {
                    Text      = string.Format(AppResources.UnlockWith, fingerprintName),
                    On        = _settings.GetValueOrDefault(Constants.SettingFingerprintUnlockOn, false),
                    IsEnabled = true
                };
                securitySecion.Insert(1, FingerprintCell);
            }

            ChangeMasterPasswordCell = new ExtendedTextCell
            {
                Text            = AppResources.ChangeMasterPassword,
                ShowDisclousure = true
            };

            ChangeEmailCell = new ExtendedTextCell
            {
                Text            = AppResources.ChangeEmail,
                ShowDisclousure = true
            };

            FoldersCell = new ExtendedTextCell
            {
                Text            = AppResources.Folders,
                ShowDisclousure = true
            };

            SyncCell = new ExtendedTextCell
            {
                Text            = AppResources.Sync,
                ShowDisclousure = true
            };

            LogOutCell = new ExtendedTextCell
            {
                Text = AppResources.LogOut
            };

            AboutCell = new ExtendedTextCell
            {
                Text            = AppResources.About,
                ShowDisclousure = true
            };

            HelpCell = new ExtendedTextCell
            {
                Text            = AppResources.HelpAndFeedback,
                ShowDisclousure = true
            };

            OptionsCell = new ExtendedTextCell
            {
                Text            = AppResources.Options,
                ShowDisclousure = true
            };

            var otherSection = new TableSection(AppResources.Other)
            {
                OptionsCell,
                AboutCell,
                HelpCell
            };

            if (Device.RuntimePlatform == Device.iOS)
            {
                RateCellLong = new LongDetailViewCell(AppResources.RateTheApp, AppResources.RateTheAppDescriptionAppStore);
                otherSection.Add(RateCellLong);
            }
            else
            {
                RateCell = new ExtendedTextCell
                {
                    Text                = AppResources.RateTheApp,
                    Detail              = AppResources.RateTheAppDescription,
                    ShowDisclousure     = true,
                    DetailLineBreakMode = LineBreakMode.WordWrap
                };
                otherSection.Add(RateCell);
            }

            Table = new CustomTable
            {
                Root = new TableRoot
                {
                    securitySecion,
                    new TableSection(AppResources.Account)
                    {
                        ChangeMasterPasswordCell,
                        ChangeEmailCell,
                        LogOutCell
                    },
                    new TableSection(AppResources.Manage)
                    {
                        FoldersCell,
                        SyncCell
                    },
                    otherSection
                }
            };

            Title   = AppResources.Settings;
            Content = Table;
        }
Пример #11
0
        private void Init()
        {
            CopyTotpCell = new ExtendedSwitchCell
            {
                Text = AppResources.DisableAutoTotpCopy,
                On   = _settings.GetValueOrDefault(Constants.SettingDisableTotpCopy, false)
            };

            var totpTable = new FormTableView(true)
            {
                Root = new TableRoot
                {
                    new TableSection(" ")
                    {
                        CopyTotpCell
                    }
                }
            };

            AnalyticsCell = new ExtendedSwitchCell
            {
                Text = AppResources.DisableGA,
                On   = _settings.GetValueOrDefault(Constants.SettingGaOptOut, false)
            };

            var analyticsTable = new FormTableView
            {
                Root = new TableRoot
                {
                    new TableSection(" ")
                    {
                        AnalyticsCell
                    }
                }
            };

            CopyTotpLabel = new FormTableLabel(this)
            {
                Text = AppResources.DisableAutoTotpCopyDescription
            };

            AnalyticsLabel = new FormTableLabel(this)
            {
                Text = AppResources.DisableGADescription
            };

            StackLayout = new StackLayout
            {
                Children = { totpTable, CopyTotpLabel, analyticsTable, AnalyticsLabel },
                Spacing  = 0
            };

            if (Device.RuntimePlatform == Device.Android)
            {
                AutofillAlwaysCell = new ExtendedSwitchCell
                {
                    Text = AppResources.AutofillAlways,
                    On   = !_appSettings.AutofillPersistNotification && !_appSettings.AutofillPasswordField
                };

                var autofillAlwaysTable = new FormTableView(true)
                {
                    Root = new TableRoot
                    {
                        new TableSection(AppResources.AutofillService)
                        {
                            AutofillAlwaysCell
                        }
                    }
                };

                AutofillAlwaysLabel = new FormTableLabel(this)
                {
                    Text = AppResources.AutofillAlwaysDescription
                };

                AutofillPersistNotificationCell = new ExtendedSwitchCell
                {
                    Text = AppResources.AutofillPersistNotification,
                    On   = _appSettings.AutofillPersistNotification
                };

                var autofillPersistNotificationTable = new FormTableView
                {
                    Root = new TableRoot
                    {
                        new TableSection(" ")
                        {
                            AutofillPersistNotificationCell
                        }
                    }
                };

                AutofillPersistNotificationLabel = new FormTableLabel(this)
                {
                    Text = AppResources.AutofillPersistNotificationDescription
                };

                AutofillPasswordFieldCell = new ExtendedSwitchCell
                {
                    Text = AppResources.AutofillPasswordField,
                    On   = _appSettings.AutofillPasswordField
                };

                var autofillPasswordFieldTable = new FormTableView
                {
                    Root = new TableRoot
                    {
                        new TableSection(" ")
                        {
                            AutofillPasswordFieldCell
                        }
                    }
                };

                AutofillPasswordFieldLabel = new FormTableLabel(this)
                {
                    Text = AppResources.AutofillPasswordFieldDescription
                };

                StackLayout.Children.Add(autofillAlwaysTable);
                StackLayout.Children.Add(AutofillAlwaysLabel);
                StackLayout.Children.Add(autofillPasswordFieldTable);
                StackLayout.Children.Add(AutofillPasswordFieldLabel);
                StackLayout.Children.Add(autofillPersistNotificationTable);
                StackLayout.Children.Add(AutofillPersistNotificationLabel);
            }

            var scrollView = new ScrollView
            {
                Content = StackLayout
            };

            if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Windows)
            {
                analyticsTable.RowHeight          = -1;
                analyticsTable.EstimatedRowHeight = 70;
                ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Close));
            }

            Title   = AppResources.Features;
            Content = scrollView;
        }
Пример #12
0
        public void Init()
        {
            Password = new Label
            {
                FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                Margin   = new Thickness(15, 30, 15, 30),
                HorizontalTextAlignment = TextAlignment.Center,
                FontFamily      = Helpers.OnPlatform(iOS: "Menlo-Regular", Android: "monospace", Windows: "Courier"),
                LineBreakMode   = LineBreakMode.TailTruncation,
                VerticalOptions = LayoutOptions.Start,
                TextColor       = Color.Black
            };

            Tgr = new TapGestureRecognizer();
            Password.GestureRecognizers.Add(Tgr);
            Password.SetBinding(Label.TextProperty, nameof(PasswordGeneratorPageModel.Password));

            SliderCell = new SliderViewCell(this, _passwordGenerationService, _settings);

            RegenerateCell = new ExtendedTextCell
            {
                Text      = AppResources.RegeneratePassword,
                TextColor = Colors.Primary
            };
            CopyCell = new ExtendedTextCell {
                Text = AppResources.CopyPassword, TextColor = Colors.Primary
            };

            UppercaseCell = new ExtendedSwitchCell
            {
                Text = "A-Z",
                On   = _settings.GetValueOrDefault(Constants.PasswordGeneratorUppercase, true)
            };

            LowercaseCell = new ExtendedSwitchCell
            {
                Text = "a-z",
                On   = _settings.GetValueOrDefault(Constants.PasswordGeneratorLowercase, true)
            };

            SpecialCell = new ExtendedSwitchCell
            {
                Text = "!@#$%^&*",
                On   = _settings.GetValueOrDefault(Constants.PasswordGeneratorSpecial, true)
            };

            NumbersCell = new ExtendedSwitchCell
            {
                Text = "0-9",
                On   = _settings.GetValueOrDefault(Constants.PasswordGeneratorNumbers, true)
            };

            AvoidAmbiguousCell = new ExtendedSwitchCell
            {
                Text = AppResources.AvoidAmbiguousCharacters,
                On   = !_settings.GetValueOrDefault(Constants.PasswordGeneratorAmbiguous, false)
            };

            NumbersMinCell = new StepperCell(AppResources.MinNumbers,
                                             _settings.GetValueOrDefault(Constants.PasswordGeneratorMinNumbers, 1), 0, 5, 1, () =>
            {
                _settings.AddOrUpdateValue(Constants.PasswordGeneratorMinNumbers,
                                           Convert.ToInt32(NumbersMinCell.Stepper.Value));
                Model.Password = _passwordGenerationService.GeneratePassword();
            });

            SpecialMinCell = new StepperCell(AppResources.MinSpecial,
                                             _settings.GetValueOrDefault(Constants.PasswordGeneratorMinSpecial, 1), 0, 5, 1, () =>
            {
                _settings.AddOrUpdateValue(Constants.PasswordGeneratorMinSpecial,
                                           Convert.ToInt32(SpecialMinCell.Stepper.Value));
                Model.Password = _passwordGenerationService.GeneratePassword();
            });

            var table = new ExtendedTableView
            {
                VerticalOptions = LayoutOptions.Start,
                EnableScrolling = false,
                Intent          = TableIntent.Settings,
                HasUnevenRows   = true,
                NoHeader        = true,
                Root            = new TableRoot
                {
                    new TableSection(Helpers.GetEmptyTableSectionTitle())
                    {
                        RegenerateCell,
                        CopyCell
                    },
                    new TableSection(AppResources.Options)
                    {
                        SliderCell,
                        UppercaseCell,
                        LowercaseCell,
                        NumbersCell,
                        SpecialCell
                    },
                    new TableSection(Helpers.GetEmptyTableSectionTitle())
                    {
                        NumbersMinCell,
                        SpecialMinCell
                    },
                    new TableSection(Helpers.GetEmptyTableSectionTitle())
                    {
                        AvoidAmbiguousCell
                    }
                }
            };

            if (Device.RuntimePlatform == Device.iOS)
            {
                table.RowHeight          = -1;
                table.EstimatedRowHeight = 44;

                if (_passwordValueAction != null)
                {
                    ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel));
                }
            }
            else if (Device.RuntimePlatform == Device.Android)
            {
                table.BottomPadding = 50;
            }

            var stackLayout = new RedrawableStackLayout
            {
                Orientation     = StackOrientation.Vertical,
                Children        = { Password, table },
                VerticalOptions = LayoutOptions.FillAndExpand,
                Spacing         = 0
            };

            table.WrappingStackLayout = () => stackLayout;

            var scrollView = new ScrollView
            {
                Content         = stackLayout,
                Orientation     = ScrollOrientation.Vertical,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            if (_passwordValueAction != null)
            {
                var selectToolBarItem = new ToolbarItem(AppResources.Select, Helpers.ToolbarImage("ion_chevron_right.png"), async() =>
                {
                    if (_fromAutofill)
                    {
                        _googleAnalyticsService.TrackExtensionEvent("SelectedGeneratedPassword");
                    }
                    else
                    {
                        _googleAnalyticsService.TrackAppEvent("SelectedGeneratedPassword");
                    }

                    _passwordValueAction(Password.Text);
                    await Navigation.PopForDeviceAsync();
                }, ToolbarItemOrder.Default, 0);

                ToolbarItems.Add(selectToolBarItem);
            }

            Title          = AppResources.PasswordGenerator;
            Content        = scrollView;
            BindingContext = Model;
        }
Пример #13
0
        private void Init()
        {
            PinCell = new ExtendedSwitchCell
            {
                Text = AppResources.UnlockWithPIN,
                On   = _settings.GetValueOrDefault(Constants.SettingPinUnlockOn, false)
            };
            PinCell.OnChanged += PinCell_Changed;

            LockOptionsCell = new ExtendedTextCell
            {
                Text            = AppResources.LockOptions,
                Detail          = GetLockOptionsDetailsText(),
                ShowDisclousure = true
            };
            LockOptionsCell.Tapped += LockOptionsCell_Tapped;

            var twoStepCell = new ExtendedTextCell
            {
                Text            = AppResources.TwoStepLogin,
                ShowDisclousure = true
            };

            twoStepCell.Tapped += TwoStepCell_Tapped;;

            var securitySecion = new TableSection(AppResources.Security)
            {
                LockOptionsCell,
                PinCell,
                twoStepCell
            };

            if (_fingerprint.IsAvailable)
            {
                var fingerprintName = Device.OnPlatform(iOS: AppResources.TouchID, Android: AppResources.Fingerprint,
                                                        WinPhone: AppResources.Fingerprint);
                FingerprintCell = new ExtendedSwitchCell
                {
                    Text      = string.Format(AppResources.UnlockWith, fingerprintName),
                    On        = _settings.GetValueOrDefault(Constants.SettingFingerprintUnlockOn, false),
                    IsEnabled = _fingerprint.IsAvailable
                };
                FingerprintCell.OnChanged += FingerprintCell_Changed;
                securitySecion.Insert(1, FingerprintCell);
            }

            var changeMasterPasswordCell = new ExtendedTextCell
            {
                Text            = AppResources.ChangeMasterPassword,
                ShowDisclousure = true
            };

            changeMasterPasswordCell.Tapped += ChangeMasterPasswordCell_Tapped;

            var changeEmailCell = new ExtendedTextCell
            {
                Text            = AppResources.ChangeEmail,
                ShowDisclousure = true
            };

            changeEmailCell.Tapped += ChangeEmailCell_Tapped;

            var foldersCell = new ExtendedTextCell
            {
                Text            = AppResources.Folders,
                ShowDisclousure = true
            };

            foldersCell.Tapped += FoldersCell_Tapped;

            var syncCell = new ExtendedTextCell
            {
                Text            = AppResources.Sync,
                ShowDisclousure = true
            };

            syncCell.Tapped += SyncCell_Tapped;

            var lockCell = new ExtendedTextCell
            {
                Text = AppResources.Lock
            };

            lockCell.Tapped += LockCell_Tapped;

            var logOutCell = new ExtendedTextCell
            {
                Text = AppResources.LogOut
            };

            logOutCell.Tapped += LogOutCell_Tapped;

            var aboutCell = new ExtendedTextCell
            {
                Text            = AppResources.About,
                ShowDisclousure = true
            };

            aboutCell.Tapped += AboutCell_Tapped;

            var helpCell = new ExtendedTextCell
            {
                Text            = AppResources.HelpAndFeedback,
                ShowDisclousure = true
            };

            helpCell.Tapped += HelpCell_Tapped;

            var otherSection = new TableSection(AppResources.Other)
            {
                aboutCell,
                helpCell
            };

            if (Device.OS == TargetPlatform.iOS)
            {
                var rateCell = new LongDetailViewCell(AppResources.RateTheApp, AppResources.RateTheAppDescriptionAppStore);
                rateCell.Tapped += RateCell_Tapped;
                otherSection.Add(rateCell);
            }
            else
            {
                var rateCell = new ExtendedTextCell
                {
                    Text                = AppResources.RateTheApp,
                    Detail              = AppResources.RateTheAppDescription,
                    ShowDisclousure     = true,
                    DetailLineBreakMode = LineBreakMode.WordWrap
                };
                rateCell.Tapped += RateCell_Tapped;
                otherSection.Add(rateCell);
            }

            Table = new CustomTable
            {
                Root = new TableRoot
                {
                    securitySecion,
                    new TableSection(AppResources.Account)
                    {
                        changeMasterPasswordCell,
                        changeEmailCell
                    },
                    new TableSection(AppResources.Manage)
                    {
                        foldersCell,
                        syncCell
                    },
                    new TableSection(AppResources.CurrentSession)
                    {
                        lockCell,
                        logOutCell
                    },
                    otherSection
                }
            };

            Title   = AppResources.Settings;
            Content = Table;
        }
Пример #14
0
        private void Init()
        {
            NotesCell = new FormEditorCell(height: 180);
            NotesCell.Editor.Keyboard = Keyboard.Text;

            TotpCell = new FormEntryCell(AppResources.AuthenticatorKey, nextElement: NotesCell.Editor,
                                         useButton: _deviceInfo.HasCamera);
            if (_deviceInfo.HasCamera)
            {
                TotpCell.Button.Image = "camera";
            }
            TotpCell.Entry.DisableAutocapitalize = true;
            TotpCell.Entry.Autocorrect           = false;
            TotpCell.Entry.FontFamily            = Helpers.OnPlatform(iOS: "Menlo-Regular", Android: "monospace", WinPhone: "Courier");

            PasswordCell = new FormEntryCell(AppResources.Password, isPassword: true, nextElement: TotpCell.Entry,
                                             useButton: true);
            PasswordCell.Button.Image = "eye";
            PasswordCell.Entry.DisableAutocapitalize = true;
            PasswordCell.Entry.Autocorrect           = false;
            PasswordCell.Entry.FontFamily            = Helpers.OnPlatform(iOS: "Menlo-Regular", Android: "monospace", WinPhone: "Courier");

            UsernameCell = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry);
            UsernameCell.Entry.DisableAutocapitalize = true;
            UsernameCell.Entry.Autocorrect           = false;

            UriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: UsernameCell.Entry);
            if (!string.IsNullOrWhiteSpace(_defaultUri))
            {
                UriCell.Entry.Text = _defaultUri;
            }

            NameCell = new FormEntryCell(AppResources.Name, nextElement: UriCell.Entry);
            if (!string.IsNullOrWhiteSpace(_defaultName))
            {
                NameCell.Entry.Text = _defaultName;
            }

            var folderOptions = new List <string> {
                AppResources.FolderNone
            };
            var folders = _folderService.GetAllAsync().GetAwaiter().GetResult()
                          .OrderBy(f => f.Name?.Decrypt()).ToList();

            foreach (var folder in folders)
            {
                folderOptions.Add(folder.Name.Decrypt());
            }
            FolderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray());

            GenerateCell = new ExtendedTextCell
            {
                Text            = AppResources.GeneratePassword,
                ShowDisclousure = true
            };

            var favoriteCell = new ExtendedSwitchCell {
                Text = AppResources.Favorite
            };

            var table = new ExtendedTableView
            {
                Intent          = TableIntent.Settings,
                EnableScrolling = true,
                HasUnevenRows   = true,
                Root            = new TableRoot
                {
                    new TableSection(AppResources.LoginInformation)
                    {
                        NameCell,
                        UriCell,
                        UsernameCell,
                        PasswordCell,
                        GenerateCell
                    },
                    new TableSection(" ")
                    {
                        TotpCell,
                        FolderCell,
                        favoriteCell
                    },
                    new TableSection(AppResources.Notes)
                    {
                        NotesCell
                    }
                }
            };

            if (Device.RuntimePlatform == Device.iOS)
            {
                table.RowHeight          = -1;
                table.EstimatedRowHeight = 70;
            }
            else if (Device.RuntimePlatform == Device.Android)
            {
                PasswordCell.Button.WidthRequest = 40;

                if (TotpCell.Button != null)
                {
                    TotpCell.Button.WidthRequest = 40;
                }
            }

            var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async() =>
            {
                if (_lastAction.LastActionWasRecent())
                {
                    return;
                }
                _lastAction = DateTime.UtcNow;

                if (!_connectivity.IsConnected)
                {
                    AlertNoConnection();
                    return;
                }

                if (string.IsNullOrWhiteSpace(NameCell.Entry.Text))
                {
                    await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
                                                                                      AppResources.Name), AppResources.Ok);
                    return;
                }

                var login = new Login
                {
                    Name     = NameCell.Entry.Text.Encrypt(),
                    Uri      = string.IsNullOrWhiteSpace(UriCell.Entry.Text) ? null : UriCell.Entry.Text.Encrypt(),
                    Username = string.IsNullOrWhiteSpace(UsernameCell.Entry.Text) ? null : UsernameCell.Entry.Text.Encrypt(),
                    Password = string.IsNullOrWhiteSpace(PasswordCell.Entry.Text) ? null : PasswordCell.Entry.Text.Encrypt(),
                    Notes    = string.IsNullOrWhiteSpace(NotesCell.Editor.Text) ? null : NotesCell.Editor.Text.Encrypt(),
                    Totp     = string.IsNullOrWhiteSpace(TotpCell.Entry.Text) ? null : TotpCell.Entry.Text.Encrypt(),
                    Favorite = favoriteCell.On
                };

                if (FolderCell.Picker.SelectedIndex > 0)
                {
                    login.FolderId = folders.ElementAt(FolderCell.Picker.SelectedIndex - 1).Id;
                }

                _userDialogs.ShowLoading(AppResources.Saving, MaskType.Black);
                var saveTask = await _loginService.SaveAsync(login);
                _userDialogs.HideLoading();

                if (saveTask.Succeeded)
                {
                    _userDialogs.Toast(AppResources.NewLoginCreated);
                    if (_fromAutofill)
                    {
                        _googleAnalyticsService.TrackExtensionEvent("CreatedLogin");
                    }
                    else
                    {
                        _googleAnalyticsService.TrackAppEvent("CreatedLogin");
                    }
                    await Navigation.PopForDeviceAsync();
                }
                else if (saveTask.Errors.Count() > 0)
                {
                    await _userDialogs.AlertAsync(saveTask.Errors.First().Message, AppResources.AnErrorHasOccurred);
                }
                else
                {
                    await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred);
                }
            }, ToolbarItemOrder.Default, 0);

            Title   = AppResources.AddLogin;
            Content = table;
            ToolbarItems.Add(saveToolBarItem);
            if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Windows)
            {
                ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel));
            }
        }
Пример #15
0
        private void Init()
        {
            var login = _loginService.GetByIdAsync(_loginId).GetAwaiter().GetResult();

            if (login == null)
            {
                // TODO: handle error. navigate back? should never happen...
                return;
            }

            NotesCell             = new FormEditorCell(height: 90);
            NotesCell.Editor.Text = login.Notes?.Decrypt();

            PasswordCell = new FormEntryCell(AppResources.Password, isPassword: true, nextElement: NotesCell.Editor,
                                             useButton: true);
            PasswordCell.Entry.Text   = login.Password?.Decrypt();
            PasswordCell.Button.Image = "eye";
            PasswordCell.Entry.DisableAutocapitalize = true;
            PasswordCell.Entry.Autocorrect           = false;
            PasswordCell.Entry.FontFamily            = Device.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier");

            UsernameCell            = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry);
            UsernameCell.Entry.Text = login.Username?.Decrypt();
            UsernameCell.Entry.DisableAutocapitalize = true;
            UsernameCell.Entry.Autocorrect           = false;

            UriCell             = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: UsernameCell.Entry);
            UriCell.Entry.Text  = login.Uri?.Decrypt();
            NameCell            = new FormEntryCell(AppResources.Name, nextElement: UriCell.Entry);
            NameCell.Entry.Text = login.Name?.Decrypt();

            GenerateCell = new ExtendedTextCell
            {
                Text            = AppResources.GeneratePassword,
                ShowDisclousure = true
            };

            var folderOptions = new List <string> {
                AppResources.FolderNone
            };
            var folders = _folderService.GetAllAsync().GetAwaiter().GetResult()
                          .OrderBy(f => f.Name?.Decrypt()).ToList();
            int selectedIndex = 0;
            int i             = 0;

            foreach (var folder in folders)
            {
                i++;
                if (folder.Id == login.FolderId)
                {
                    selectedIndex = i;
                }

                folderOptions.Add(folder.Name.Decrypt());
            }
            FolderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray());
            FolderCell.Picker.SelectedIndex = selectedIndex;

            var favoriteCell = new ExtendedSwitchCell
            {
                Text = AppResources.Favorite,
                On   = login.Favorite
            };

            DeleteCell = new ExtendedTextCell {
                Text = AppResources.Delete, TextColor = Color.Red
            };

            var table = new ExtendedTableView
            {
                Intent          = TableIntent.Settings,
                EnableScrolling = true,
                HasUnevenRows   = true,
                Root            = new TableRoot
                {
                    new TableSection(AppResources.LoginInformation)
                    {
                        NameCell,
                        UriCell,
                        UsernameCell,
                        PasswordCell,
                        GenerateCell
                    },
                    new TableSection
                    {
                        FolderCell,
                        favoriteCell
                    },
                    new TableSection(AppResources.Notes)
                    {
                        NotesCell
                    },
                    new TableSection
                    {
                        DeleteCell
                    }
                }
            };

            if (Device.OS == TargetPlatform.iOS)
            {
                table.RowHeight          = -1;
                table.EstimatedRowHeight = 70;
            }
            else if (Device.OS == TargetPlatform.Android)
            {
                PasswordCell.Button.WidthRequest = 40;
            }

            var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async() =>
            {
                if (!_connectivity.IsConnected)
                {
                    AlertNoConnection();
                    return;
                }

                if (string.IsNullOrWhiteSpace(NameCell.Entry.Text))
                {
                    await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
                                                                                      AppResources.Name), AppResources.Ok);
                    return;
                }

                login.Uri      = UriCell.Entry.Text?.Encrypt();
                login.Name     = NameCell.Entry.Text?.Encrypt();
                login.Username = UsernameCell.Entry.Text?.Encrypt();
                login.Password = PasswordCell.Entry.Text?.Encrypt();
                login.Notes    = NotesCell.Editor.Text?.Encrypt();
                login.Favorite = favoriteCell.On;

                if (FolderCell.Picker.SelectedIndex > 0)
                {
                    login.FolderId = folders.ElementAt(FolderCell.Picker.SelectedIndex - 1).Id;
                }
                else
                {
                    login.FolderId = null;
                }

                _userDialogs.ShowLoading(AppResources.Saving, MaskType.Black);
                var saveTask = await _loginService.SaveAsync(login);

                _userDialogs.HideLoading();

                if (saveTask.Succeeded)
                {
                    await Navigation.PopForDeviceAsync();
                    _userDialogs.Toast(AppResources.LoginUpdated);
                    _googleAnalyticsService.TrackAppEvent("EditeLogin");
                }
                else if (saveTask.Errors.Count() > 0)
                {
                    await _userDialogs.AlertAsync(saveTask.Errors.First().Message, AppResources.AnErrorHasOccurred);
                }
                else
                {
                    await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred);
                }
            }, ToolbarItemOrder.Default, 0);

            Title   = AppResources.EditLogin;
            Content = table;
            ToolbarItems.Add(saveToolBarItem);
            if (Device.OS == TargetPlatform.iOS)
            {
                ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel));
            }
        }
Пример #16
0
        private void Init()
        {
            SubscribeYubiKey(true);
            if (_providers.Count > 1)
            {
                var sendEmailTask = SendEmailAsync(false);
            }

            ToolbarItems.Clear();
            var scrollView = new ScrollView();

            var anotherMethodButton = new ExtendedButton
            {
                Text            = AppResources.UseAnotherTwoStepMethod,
                Style           = (Style)Application.Current.Resources["btn-primaryAccent"],
                Margin          = new Thickness(15, 0, 15, 25),
                Command         = new Command(() => AnotherMethodAsync()),
                Uppercase       = false,
                BackgroundColor = Color.Transparent,
                VerticalOptions = LayoutOptions.Start
            };

            var instruction = new Label
            {
                LineBreakMode           = LineBreakMode.WordWrap,
                Margin                  = new Thickness(15),
                HorizontalTextAlignment = TextAlignment.Center
            };

            RememberCell = new ExtendedSwitchCell
            {
                Text = AppResources.RememberMe,
                On   = false
            };

            if (!_providerType.HasValue)
            {
                instruction.Text = AppResources.NoTwoStepAvailable;

                var layout = new StackLayout
                {
                    Children = { instruction, anotherMethodButton },
                    Spacing  = 0
                };

                scrollView.Content = layout;

                Title   = AppResources.LoginUnavailable;
                Content = scrollView;
            }
            else if (_providerType.Value == TwoFactorProviderType.Authenticator ||
                     _providerType.Value == TwoFactorProviderType.Email)
            {
                var continueToolbarItem = new ToolbarItem(AppResources.Continue, Helpers.ToolbarImage("login.png"), async() =>
                {
                    var token = TokenCell?.Entry.Text.Trim().Replace(" ", "");
                    await LogInAsync(token);
                }, ToolbarItemOrder.Default, 0);

                var padding = Helpers.OnPlatform(
                    iOS: new Thickness(15, 20),
                    Android: new Thickness(15, 8),
                    Windows: new Thickness(10, 8));

                TokenCell = new FormEntryCell(AppResources.VerificationCode, useLabelAsPlaceholder: true,
                                              imageSource: "lock", containerPadding: padding);

                TokenCell.Entry.Keyboard   = Keyboard.Numeric;
                TokenCell.Entry.ReturnType = ReturnType.Go;

                var table = new TwoFactorTable(
                    new TableSection(Helpers.GetEmptyTableSectionTitle())
                {
                    TokenCell,
                    RememberCell
                });

                var layout = new RedrawableStackLayout
                {
                    Children = { instruction, table },
                    Spacing  = 0
                };

                table.WrappingStackLayout = () => layout;
                scrollView.Content        = layout;

                switch (_providerType.Value)
                {
                case TwoFactorProviderType.Authenticator:
                    instruction.Text = AppResources.EnterVerificationCodeApp;
                    layout.Children.Add(anotherMethodButton);
                    break;

                case TwoFactorProviderType.Email:
                    var emailParams   = _providers[TwoFactorProviderType.Email];
                    var redactedEmail = emailParams["Email"].ToString();

                    instruction.Text = string.Format(AppResources.EnterVerificationCodeEmail, redactedEmail);
                    var resendEmailButton = new ExtendedButton
                    {
                        Text            = AppResources.SendVerificationCodeAgain,
                        Style           = (Style)Application.Current.Resources["btn-primaryAccent"],
                        Margin          = new Thickness(15, 0, 15, 0),
                        Command         = new Command(async() => await SendEmailAsync(true)),
                        Uppercase       = false,
                        BackgroundColor = Color.Transparent,
                        VerticalOptions = LayoutOptions.Start
                    };

                    layout.Children.Add(resendEmailButton);
                    layout.Children.Add(anotherMethodButton);
                    break;

                default:
                    break;
                }

                ToolbarItems.Add(continueToolbarItem);
                Title = AppResources.VerificationCode;

                Content = scrollView;
                TokenCell.Entry.FocusWithDelay();
            }
            else if (_providerType == TwoFactorProviderType.Duo)
            {
                var duoParams = _providers[TwoFactorProviderType.Duo];

                var host = WebUtility.UrlEncode(duoParams["Host"].ToString());
                var req  = WebUtility.UrlEncode(duoParams["Signature"].ToString());

                var webVaultUrl = "https://vault.bitwarden.com";
                if (!string.IsNullOrWhiteSpace(_appSettingsService.BaseUrl))
                {
                    webVaultUrl = _appSettingsService.BaseUrl;
                }
                else if (!string.IsNullOrWhiteSpace(_appSettingsService.WebVaultUrl))
                {
                    webVaultUrl = _appSettingsService.WebVaultUrl;
                }

                var webView = new HybridWebView
                {
                    Uri = $"{webVaultUrl}/duo-connector.html?host={host}&request={req}",
                    HorizontalOptions    = LayoutOptions.FillAndExpand,
                    VerticalOptions      = LayoutOptions.FillAndExpand,
                    MinimumHeightRequest = 400
                };
                webView.RegisterAction(async(sig) =>
                {
                    await LogInAsync(sig);
                });

                var table = new TwoFactorTable(
                    new TableSection(Helpers.GetEmptyTableSectionTitle())
                {
                    RememberCell
                });

                var layout = new RedrawableStackLayout
                {
                    Children = { webView, table, anotherMethodButton },
                    Spacing  = 0
                };

                table.WrappingStackLayout = () => layout;
                scrollView.Content        = layout;

                Title   = "Duo";
                Content = scrollView;
            }
            else if (_providerType == TwoFactorProviderType.YubiKey)
            {
                instruction.Text = AppResources.YubiKeyInstruction;

                var image = new CachedImage
                {
                    Source            = "yubikey",
                    VerticalOptions   = LayoutOptions.Start,
                    HorizontalOptions = LayoutOptions.Center,
                    WidthRequest      = 266,
                    HeightRequest     = 160,
                    Margin            = new Thickness(0, 0, 0, 25)
                };

                var table = new TwoFactorTable(
                    new TableSection(Helpers.GetEmptyTableSectionTitle())
                {
                    RememberCell
                });

                var layout = new RedrawableStackLayout
                {
                    Children = { instruction, image, table, anotherMethodButton },
                    Spacing  = 0
                };

                table.WrappingStackLayout = () => layout;
                scrollView.Content        = layout;

                Title   = AppResources.YubiKeyTitle;
                Content = scrollView;
            }
        }
Пример #17
0
        private void Init()
        {
            AnalyticsCell = new ExtendedSwitchCell
            {
                Text = AppResources.DisableGA,
                On   = _settings.GetValueOrDefault(Constants.SettingGaOptOut, false)
            };

            var analyticsTable = new FormTableView
            {
                Root = new TableRoot
                {
                    new TableSection(" ")
                    {
                        AnalyticsCell
                    }
                }
            };

            AnalyticsLabel = new Label
            {
                Text          = AppResources.DisbaleGADescription,
                LineBreakMode = LineBreakMode.WordWrap,
                FontSize      = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                Style         = (Style)Application.Current.Resources["text-muted"],
                Margin        = new Thickness(15, (this.IsLandscape() ? 5 : 0), 15, 25)
            };

            StackLayout = new StackLayout
            {
                Children = { analyticsTable, AnalyticsLabel },
                Spacing  = 0
            };

            if (Device.RuntimePlatform == Device.Android)
            {
                AutofillAlwaysCell = new ExtendedSwitchCell
                {
                    Text = AppResources.AutofillAlways,
                    On   = !_appSettings.AutofillPersistNotification && !_appSettings.AutofillPasswordField
                };

                var autofillAlwaysTable = new FormTableView
                {
                    Root = new TableRoot
                    {
                        new TableSection(AppResources.AutofillService)
                        {
                            AutofillAlwaysCell
                        }
                    }
                };

                AutofillAlwaysLabel = new FormTableLabel(this)
                {
                    Text = AppResources.AutofillAlwaysDescription
                };

                AutofillPersistNotificationCell = new ExtendedSwitchCell
                {
                    Text = AppResources.AutofillPersistNotification,
                    On   = _appSettings.AutofillPersistNotification
                };

                var autofillPersistNotificationTable = new FormTableView
                {
                    NoHeader = true,
                    Root     = new TableRoot
                    {
                        new TableSection(" ")
                        {
                            AutofillPersistNotificationCell
                        }
                    }
                };

                AutofillPersistNotificationLabel = new FormTableLabel(this)
                {
                    Text = AppResources.AutofillPersistNotificationDescription
                };

                AutofillPasswordFieldCell = new ExtendedSwitchCell
                {
                    Text = AppResources.AutofillPasswordField,
                    On   = _appSettings.AutofillPasswordField
                };

                var autofillPasswordFieldTable = new FormTableView
                {
                    NoHeader = true,
                    Root     = new TableRoot
                    {
                        new TableSection(" ")
                        {
                            AutofillPasswordFieldCell
                        }
                    }
                };

                AutofillPasswordFieldLabel = new FormTableLabel(this)
                {
                    Text = AppResources.AutofillPasswordFieldDescription
                };

                StackLayout.Children.Add(autofillAlwaysTable);
                StackLayout.Children.Add(AutofillAlwaysLabel);
                StackLayout.Children.Add(autofillPasswordFieldTable);
                StackLayout.Children.Add(AutofillPasswordFieldLabel);
                StackLayout.Children.Add(autofillPersistNotificationTable);
                StackLayout.Children.Add(AutofillPersistNotificationLabel);
            }

            var scrollView = new ScrollView
            {
                Content = StackLayout
            };

            if (Device.RuntimePlatform == Device.iOS)
            {
                analyticsTable.RowHeight          = -1;
                analyticsTable.EstimatedRowHeight = 70;
                ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel));
            }

            Title   = AppResources.Features;
            Content = scrollView;
        }