public static async Task <string> CipherListOptions(ContentPage page, CipherView cipher, IPasswordRepromptService passwordRepromptService) { var platformUtilsService = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService"); var eventService = ServiceContainer.Resolve <IEventService>("eventService"); var vaultTimeoutService = ServiceContainer.Resolve <IVaultTimeoutService>("vaultTimeoutService"); var options = new List <string> { AppResources.View }; if (!cipher.IsDeleted) { options.Add(AppResources.Edit); } if (cipher.Type == Core.Enums.CipherType.Login) { if (!string.IsNullOrWhiteSpace(cipher.Login.Username)) { options.Add(AppResources.CopyUsername); } if (!string.IsNullOrWhiteSpace(cipher.Login.Password) && cipher.ViewPassword) { options.Add(AppResources.CopyPassword); } if (!string.IsNullOrWhiteSpace(cipher.Login.Totp)) { var userService = ServiceContainer.Resolve <IUserService>("userService"); var canAccessPremium = await userService.CanAccessPremiumAsync(); if (canAccessPremium || cipher.OrganizationUseTotp) { options.Add(AppResources.CopyTotp); } } if (cipher.Login.CanLaunch) { options.Add(AppResources.Launch); } } else if (cipher.Type == Core.Enums.CipherType.Card) { if (!string.IsNullOrWhiteSpace(cipher.Card.Number)) { options.Add(AppResources.CopyNumber); } if (!string.IsNullOrWhiteSpace(cipher.Card.Code)) { options.Add(AppResources.CopySecurityCode); } } else if (cipher.Type == Core.Enums.CipherType.SecureNote) { if (!string.IsNullOrWhiteSpace(cipher.Notes)) { options.Add(AppResources.CopyNotes); } } var selection = await page.DisplayActionSheet(cipher.Name, AppResources.Cancel, null, options.ToArray()); if (await vaultTimeoutService.IsLockedAsync()) { platformUtilsService.ShowToast("info", null, AppResources.VaultIsLocked); } else if (selection == AppResources.View) { await page.Navigation.PushModalAsync(new NavigationPage(new ViewPage(cipher.Id))); } else if (selection == AppResources.Edit) { if (cipher.Reprompt == CipherRepromptType.None || await passwordRepromptService.ShowPasswordPromptAsync()) { await page.Navigation.PushModalAsync(new NavigationPage(new AddEditPage(cipher.Id))); } } else if (selection == AppResources.CopyUsername) { await platformUtilsService.CopyToClipboardAsync(cipher.Login.Username); platformUtilsService.ShowToast("info", null, string.Format(AppResources.ValueHasBeenCopied, AppResources.Username)); } else if (selection == AppResources.CopyPassword) { if (cipher.Reprompt == CipherRepromptType.None || await passwordRepromptService.ShowPasswordPromptAsync()) { await platformUtilsService.CopyToClipboardAsync(cipher.Login.Password); platformUtilsService.ShowToast("info", null, string.Format(AppResources.ValueHasBeenCopied, AppResources.Password)); var task = eventService.CollectAsync(Core.Enums.EventType.Cipher_ClientCopiedPassword, cipher.Id); } } else if (selection == AppResources.CopyTotp) { if (cipher.Reprompt == CipherRepromptType.None || await passwordRepromptService.ShowPasswordPromptAsync()) { var totpService = ServiceContainer.Resolve <ITotpService>("totpService"); var totp = await totpService.GetCodeAsync(cipher.Login.Totp); if (!string.IsNullOrWhiteSpace(totp)) { await platformUtilsService.CopyToClipboardAsync(totp); platformUtilsService.ShowToast("info", null, string.Format(AppResources.ValueHasBeenCopied, AppResources.VerificationCodeTotp)); } } } else if (selection == AppResources.Launch) { platformUtilsService.LaunchUri(cipher.Login.LaunchUri); } else if (selection == AppResources.CopyNumber) { if (cipher.Reprompt == CipherRepromptType.None || await passwordRepromptService.ShowPasswordPromptAsync()) { await platformUtilsService.CopyToClipboardAsync(cipher.Card.Number); platformUtilsService.ShowToast("info", null, string.Format(AppResources.ValueHasBeenCopied, AppResources.Number)); } } else if (selection == AppResources.CopySecurityCode) { if (cipher.Reprompt == CipherRepromptType.None || await passwordRepromptService.ShowPasswordPromptAsync()) { await platformUtilsService.CopyToClipboardAsync(cipher.Card.Code); platformUtilsService.ShowToast("info", null, string.Format(AppResources.ValueHasBeenCopied, AppResources.SecurityCode)); var task = eventService.CollectAsync(Core.Enums.EventType.Cipher_ClientCopiedCardCode, cipher.Id); } } else if (selection == AppResources.CopyNotes) { await platformUtilsService.CopyToClipboardAsync(cipher.Notes); platformUtilsService.ShowToast("info", null, string.Format(AppResources.ValueHasBeenCopied, AppResources.Notes)); } return(selection); }
public async static Task TableRowSelectedAsync(UITableView tableView, NSIndexPath indexPath, ExtensionTableSource tableSource, CredentialProviderViewController cpViewController, UIViewController controller, IPasswordRepromptService passwordRepromptService, string loginAddSegue) { tableView.DeselectRow(indexPath, true); tableView.EndEditing(true); if (tableSource.Items == null || tableSource.Items.Count() == 0) { controller.PerformSegue(loginAddSegue, tableSource); return; } var item = tableSource.Items.ElementAt(indexPath.Row); if (item == null) { cpViewController.CompleteRequest(); return; } if (item.Reprompt != Bit.Core.Enums.CipherRepromptType.None && !await passwordRepromptService.ShowPasswordPromptAsync()) { return; } if (!string.IsNullOrWhiteSpace(item.Username) && !string.IsNullOrWhiteSpace(item.Password)) { string totp = null; var stateService = ServiceContainer.Resolve <IStateService>("stateService"); var disableTotpCopy = await stateService.GetDisableAutoTotpCopyAsync(); if (!disableTotpCopy.GetValueOrDefault(false)) { var canAccessPremiumAsync = await stateService.CanAccessPremiumAsync(); if (!string.IsNullOrWhiteSpace(item.Totp) && (canAccessPremiumAsync || item.CipherView.OrganizationUseTotp)) { var totpService = ServiceContainer.Resolve <ITotpService>("totpService"); totp = await totpService.GetCodeAsync(item.Totp); } } cpViewController.CompleteRequest(item.Id, item.Username, item.Password, totp); } else if (!string.IsNullOrWhiteSpace(item.Username) || !string.IsNullOrWhiteSpace(item.Password) || !string.IsNullOrWhiteSpace(item.Totp)) { var sheet = Dialogs.CreateActionSheet(item.Name, controller); if (!string.IsNullOrWhiteSpace(item.Username)) { sheet.AddAction(UIAlertAction.Create(AppResources.CopyUsername, UIAlertActionStyle.Default, a => { UIPasteboard clipboard = UIPasteboard.General; clipboard.String = item.Username; var alert = Dialogs.CreateMessageAlert(AppResources.CopyUsername); controller.PresentViewController(alert, true, () => { controller.DismissViewController(true, null); }); })); } if (!string.IsNullOrWhiteSpace(item.Password)) { sheet.AddAction(UIAlertAction.Create(AppResources.CopyPassword, UIAlertActionStyle.Default, a => { UIPasteboard clipboard = UIPasteboard.General; clipboard.String = item.Password; var alert = Dialogs.CreateMessageAlert( string.Format(AppResources.ValueHasBeenCopied, AppResources.Password)); controller.PresentViewController(alert, true, () => { controller.DismissViewController(true, null); }); })); } if (!string.IsNullOrWhiteSpace(item.Totp)) { sheet.AddAction(UIAlertAction.Create(AppResources.CopyTotp, UIAlertActionStyle.Default, async a => { var totp = await tableSource.GetTotpAsync(item); if (string.IsNullOrWhiteSpace(totp)) { return; } UIPasteboard clipboard = UIPasteboard.General; clipboard.String = totp; var alert = Dialogs.CreateMessageAlert( string.Format(AppResources.ValueHasBeenCopied, AppResources.VerificationCodeTotp)); controller.PresentViewController(alert, true, () => { controller.DismissViewController(true, null); }); })); } sheet.AddAction(UIAlertAction.Create(AppResources.Cancel, UIAlertActionStyle.Cancel, null)); controller.PresentViewController(sheet, true, null); } else { var alert = Dialogs.CreateAlert(null, AppResources.NoUsernamePasswordConfigured, AppResources.Ok); controller.PresentViewController(alert, true, null); } }