1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-23 11:45:38 +01:00

add ciphers: card, identity, and sec note

This commit is contained in:
Kyle Spearrin 2017-10-19 13:44:05 -04:00
parent dd96608bb1
commit df616cfe3e
9 changed files with 1084 additions and 194 deletions

View File

@ -138,6 +138,14 @@ namespace Bit.App.Controls
public Label Label { get; private set; }
public ExtendedEntry Entry { get; private set; }
public ExtendedButton Button { get; private set; }
public VisualElement NextElement
{
get => _nextElement;
set
{
_nextElement = value;
}
}
public void InitEvents()
{
@ -150,7 +158,7 @@ namespace Bit.App.Controls
{
_tgr.Tapped += Tgr_Tapped;
}
Tapped += FormEntryCell_Tapped;
}

View File

@ -6,6 +6,8 @@ namespace Bit.App.Models
{
public class Card
{
public Card() { }
public Card(CipherData data)
{
var deserializedData = JsonConvert.DeserializeObject<CardDataModel>(data.Data);

View File

@ -6,6 +6,8 @@ namespace Bit.App.Models
{
public class Identity
{
public Identity() { }
public Identity(CipherData data)
{
var deserializedData = JsonConvert.DeserializeObject<IdentityDataModel>(data.Data);

View File

@ -5,6 +5,8 @@ namespace Bit.App.Models
{
public class SecureNote
{
public SecureNote() { }
public SecureNote(CipherData data)
{
Type = data.SecureNoteType.Value;

View File

@ -11,6 +11,7 @@ using Xamarin.Forms;
using XLabs.Ioc;
using Plugin.Settings.Abstractions;
using Bit.App.Utilities;
using Bit.App.Enums;
namespace Bit.App.Pages
{
@ -18,6 +19,7 @@ namespace Bit.App.Pages
{
private const string AddedLoginAlertKey = "addedSiteAlert";
private readonly CipherType _type;
private readonly ICipherService _cipherService;
private readonly IFolderService _folderService;
private readonly IUserDialogs _userDialogs;
@ -31,8 +33,10 @@ namespace Bit.App.Pages
private readonly bool _fromAutofill;
private DateTime? _lastAction;
public VaultAddLoginPage(string defaultUri = null, string defaultName = null, bool fromAutofill = false)
public VaultAddLoginPage(CipherType type, string defaultUri = null,
string defaultName = null, bool fromAutofill = false)
{
_type = type;
_defaultUri = defaultUri;
_defaultName = defaultName;
_fromAutofill = fromAutofill;
@ -49,113 +53,450 @@ namespace Bit.App.Pages
Init();
}
public FormEntryCell PasswordCell { get; private set; }
public FormEntryCell UsernameCell { get; private set; }
public FormEntryCell UriCell { get; private set; }
public List<Folder> Folders { get; set; }
public TableRoot TableRoot { get; set; }
public TableSection TopSection { get; set; }
public TableSection MiddleSection { get; set; }
public ExtendedTableView Table { get; set; }
public FormEntryCell NameCell { get; private set; }
public FormEntryCell TotpCell { get; private set; }
public FormEditorCell NotesCell { get; private set; }
public FormPickerCell FolderCell { get; private set; }
public ExtendedTextCell GenerateCell { get; private set; }
public ExtendedSwitchCell FavoriteCell { get; set; }
// Login
public FormEntryCell LoginPasswordCell { get; private set; }
public FormEntryCell LoginUsernameCell { get; private set; }
public FormEntryCell LoginUriCell { get; private set; }
public FormEntryCell LoginTotpCell { get; private set; }
// Card
public FormEntryCell CardNameCell { get; private set; }
public FormEntryCell CardNumberCell { get; private set; }
public FormPickerCell CardBrandCell { get; private set; }
public FormPickerCell CardExpMonthCell { get; private set; }
public FormEntryCell CardExpYearCell { get; private set; }
public FormEntryCell CardCodeCell { get; private set; }
// Identity
public FormPickerCell IdTitleCell { get; private set; }
public FormEntryCell IdFirstNameCell { get; private set; }
public FormEntryCell IdMiddleNameCell { get; private set; }
public FormEntryCell IdLastNameCell { get; private set; }
public FormEntryCell IdUsernameCell { get; private set; }
public FormEntryCell IdCompanyCell { get; private set; }
public FormEntryCell IdSsnCell { get; private set; }
public FormEntryCell IdPassportNumberCell { get; private set; }
public FormEntryCell IdLicenseNumberCell { get; private set; }
public FormEntryCell IdEmailCell { get; private set; }
public FormEntryCell IdPhoneCell { get; private set; }
public FormEntryCell IdAddress1Cell { get; private set; }
public FormEntryCell IdAddress2Cell { get; private set; }
public FormEntryCell IdAddress3Cell { get; private set; }
public FormEntryCell IdCityCell { get; private set; }
public FormEntryCell IdStateCell { get; private set; }
public FormEntryCell IdPostalCodeCell { get; private set; }
public FormEntryCell IdCountryCell { get; private set; }
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);
// Name
NameCell = new FormEntryCell(AppResources.Name);
if(!string.IsNullOrWhiteSpace(_defaultName))
{
NameCell.Entry.Text = _defaultName;
}
// Notes
NotesCell = new FormEditorCell(height: 180);
NotesCell.Editor.Keyboard = Keyboard.Text;
// Folders
var folderOptions = new List<string> { AppResources.FolderNone };
var folders = _folderService.GetAllAsync().GetAwaiter().GetResult()
Folders = _folderService.GetAllAsync().GetAwaiter().GetResult()
.OrderBy(f => f.Name?.Decrypt()).ToList();
foreach(var folder in folders)
foreach(var folder in Folders)
{
folderOptions.Add(folder.Name.Decrypt());
}
FolderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray());
GenerateCell = new ExtendedTextCell
// Favorite
FavoriteCell = new ExtendedSwitchCell { Text = AppResources.Favorite };
InitTable();
InitSave();
Title = AppResources.AddItem;
Content = Table;
if(Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Windows)
{
Text = AppResources.GeneratePassword,
ShowDisclousure = true
ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel));
}
}
protected override void OnAppearing()
{
base.OnAppearing();
if(!_connectivity.IsConnected)
{
AlertNoConnection();
}
NameCell.InitEvents();
NotesCell.InitEvents();
FolderCell.InitEvents();
switch(_type)
{
case CipherType.Login:
LoginPasswordCell.InitEvents();
LoginUsernameCell.InitEvents();
LoginUriCell.InitEvents();
LoginTotpCell.InitEvents();
LoginPasswordCell.Button.Clicked += PasswordButton_Clicked;
GenerateCell.Tapped += GenerateCell_Tapped;
if(LoginTotpCell?.Button != null)
{
LoginTotpCell.Button.Clicked += TotpButton_Clicked;
}
break;
case CipherType.Card:
CardBrandCell.InitEvents();
CardCodeCell.InitEvents();
CardExpMonthCell.InitEvents();
CardExpYearCell.InitEvents();
CardNameCell.InitEvents();
CardNumberCell.InitEvents();
break;
case CipherType.Identity:
IdTitleCell.InitEvents();
IdFirstNameCell.InitEvents();
IdMiddleNameCell.InitEvents();
IdLastNameCell.InitEvents();
IdUsernameCell.InitEvents();
IdCompanyCell.InitEvents();
IdSsnCell.InitEvents();
IdPassportNumberCell.InitEvents();
IdLicenseNumberCell.InitEvents();
IdEmailCell.InitEvents();
IdPhoneCell.InitEvents();
IdAddress1Cell.InitEvents();
IdAddress2Cell.InitEvents();
IdAddress3Cell.InitEvents();
IdCityCell.InitEvents();
IdStateCell.InitEvents();
IdPostalCodeCell.InitEvents();
IdCountryCell.InitEvents();
break;
default:
break;
}
if(_type == CipherType.Login && !_fromAutofill && !_settings.GetValueOrDefault(AddedLoginAlertKey, false))
{
_settings.AddOrUpdateValue(AddedLoginAlertKey, true);
if(Device.RuntimePlatform == Device.iOS)
{
DisplayAlert(AppResources.BitwardenAppExtension, AppResources.BitwardenAppExtensionAlert,
AppResources.Ok);
}
else if(Device.RuntimePlatform == Device.Android && !_appInfoService.AutofillServiceEnabled)
{
DisplayAlert(AppResources.BitwardenAutofillService, AppResources.BitwardenAutofillServiceAlert,
AppResources.Ok);
}
}
NameCell?.Entry.FocusWithDelay();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
NameCell.Dispose();
NotesCell.Dispose();
FolderCell.Dispose();
switch(_type)
{
case CipherType.Login:
LoginTotpCell.Dispose();
LoginPasswordCell.Dispose();
LoginUsernameCell.Dispose();
LoginUriCell.Dispose();
LoginPasswordCell.Button.Clicked -= PasswordButton_Clicked;
GenerateCell.Tapped -= GenerateCell_Tapped;
if(LoginTotpCell?.Button != null)
{
LoginTotpCell.Button.Clicked -= TotpButton_Clicked;
}
break;
case CipherType.Card:
CardBrandCell.Dispose();
CardCodeCell.Dispose();
CardExpMonthCell.Dispose();
CardExpYearCell.Dispose();
CardNameCell.Dispose();
CardNumberCell.Dispose();
break;
case CipherType.Identity:
IdTitleCell.Dispose();
IdFirstNameCell.Dispose();
IdMiddleNameCell.Dispose();
IdLastNameCell.Dispose();
IdUsernameCell.Dispose();
IdCompanyCell.Dispose();
IdSsnCell.Dispose();
IdPassportNumberCell.Dispose();
IdLicenseNumberCell.Dispose();
IdEmailCell.Dispose();
IdPhoneCell.Dispose();
IdAddress1Cell.Dispose();
IdAddress2Cell.Dispose();
IdAddress3Cell.Dispose();
IdCityCell.Dispose();
IdStateCell.Dispose();
IdPostalCodeCell.Dispose();
IdCountryCell.Dispose();
break;
default:
break;
}
}
private void PasswordButton_Clicked(object sender, EventArgs e)
{
LoginPasswordCell.Entry.InvokeToggleIsPassword();
LoginPasswordCell.Button.Image = "eye" + (!LoginPasswordCell.Entry.IsPasswordFromToggled ? "_slash" : string.Empty);
}
private async void TotpButton_Clicked(object sender, EventArgs e)
{
var scanPage = new ScanPage((key) =>
{
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopModalAsync();
if(!string.IsNullOrWhiteSpace(key))
{
LoginTotpCell.Entry.Text = key;
_userDialogs.Toast(AppResources.AuthenticatorKeyAdded);
}
else
{
_userDialogs.Alert(AppResources.AuthenticatorKeyReadError);
}
});
});
await Navigation.PushModalAsync(new ExtendedNavigationPage(scanPage));
}
private async void GenerateCell_Tapped(object sender, EventArgs e)
{
var page = new ToolsPasswordGeneratorPage((password) =>
{
LoginPasswordCell.Entry.Text = password;
_userDialogs.Toast(AppResources.PasswordGenerated);
}, _fromAutofill);
await Navigation.PushForDeviceAsync(page);
}
private void AlertNoConnection()
{
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage,
AppResources.Ok);
}
private void InitTable()
{
// Sections
TopSection = new TableSection(AppResources.ItemInformation)
{
NameCell
};
var favoriteCell = new ExtendedSwitchCell { Text = AppResources.Favorite };
MiddleSection = new TableSection(" ")
{
FolderCell,
FavoriteCell
};
var table = new ExtendedTableView
if(_type == CipherType.Login)
{
LoginTotpCell = new FormEntryCell(AppResources.AuthenticatorKey, nextElement: NotesCell.Editor,
useButton: _deviceInfo.HasCamera);
if(_deviceInfo.HasCamera)
{
LoginTotpCell.Button.Image = "camera";
}
LoginTotpCell.Entry.DisableAutocapitalize = true;
LoginTotpCell.Entry.Autocorrect = false;
LoginTotpCell.Entry.FontFamily = Helpers.OnPlatform(iOS: "Menlo-Regular", Android: "monospace", WinPhone: "Courier");
LoginPasswordCell = new FormEntryCell(AppResources.Password, isPassword: true, nextElement: LoginTotpCell.Entry,
useButton: true);
LoginPasswordCell.Button.Image = "eye";
LoginPasswordCell.Entry.DisableAutocapitalize = true;
LoginPasswordCell.Entry.Autocorrect = false;
LoginPasswordCell.Entry.FontFamily = Helpers.OnPlatform(iOS: "Menlo-Regular", Android: "monospace", WinPhone: "Courier");
GenerateCell = new ExtendedTextCell
{
Text = AppResources.GeneratePassword,
ShowDisclousure = true
};
LoginUsernameCell = new FormEntryCell(AppResources.Username, nextElement: LoginPasswordCell.Entry);
LoginUsernameCell.Entry.DisableAutocapitalize = true;
LoginUsernameCell.Entry.Autocorrect = false;
LoginUriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: LoginUsernameCell.Entry);
if(!string.IsNullOrWhiteSpace(_defaultUri))
{
LoginUriCell.Entry.Text = _defaultUri;
}
NameCell.NextElement = LoginUriCell.Entry;
// Build sections
TopSection.Add(LoginUriCell);
TopSection.Add(LoginUsernameCell);
TopSection.Add(LoginPasswordCell);
TopSection.Add(GenerateCell);
MiddleSection.Insert(0, LoginTotpCell);
}
else if(_type == CipherType.Card)
{
CardCodeCell = new FormEntryCell(AppResources.SecurityCode, Keyboard.Numeric,
nextElement: NotesCell.Editor);
CardExpYearCell = new FormEntryCell(AppResources.ExpirationYear, Keyboard.Numeric,
nextElement: CardCodeCell.Entry);
CardExpMonthCell = new FormPickerCell(AppResources.ExpirationMonth, new string[] {
"--", AppResources.January, AppResources.February, AppResources.March, AppResources.April,
AppResources.May, AppResources.June, AppResources.July, AppResources.August, AppResources.September,
AppResources.October, AppResources.November, AppResources.December
});
CardBrandCell = new FormPickerCell(AppResources.Brand, new string[] {
"--", "Visa", "Mastercard", "American Express", "Discover", "Diners Club",
"JCB", "Maestro", "UnionPay", AppResources.Other
});
CardNumberCell = new FormEntryCell(AppResources.Number, Keyboard.Numeric);
CardNameCell = new FormEntryCell(AppResources.CardholderName, nextElement: CardNumberCell.Entry);
NameCell.NextElement = CardNameCell.Entry;
// Build sections
TopSection.Add(CardNameCell);
TopSection.Add(CardNumberCell);
TopSection.Add(CardBrandCell);
TopSection.Add(CardExpMonthCell);
TopSection.Add(CardExpYearCell);
TopSection.Add(CardCodeCell);
}
else if(_type == CipherType.Identity)
{
IdCountryCell = new FormEntryCell(AppResources.Country, nextElement: NotesCell.Editor);
IdPostalCodeCell = new FormEntryCell(AppResources.ZipPostalCode, nextElement: IdCountryCell.Entry);
IdPostalCodeCell.Entry.DisableAutocapitalize = true;
IdPostalCodeCell.Entry.Autocorrect = false;
IdStateCell = new FormEntryCell(AppResources.StateProvince, nextElement: IdPostalCodeCell.Entry);
IdCityCell = new FormEntryCell(AppResources.CityTown, nextElement: IdStateCell.Entry);
IdAddress3Cell = new FormEntryCell(AppResources.Address3, nextElement: IdCityCell.Entry);
IdAddress2Cell = new FormEntryCell(AppResources.Address2, nextElement: IdAddress3Cell.Entry);
IdAddress1Cell = new FormEntryCell(AppResources.Address1, nextElement: IdAddress2Cell.Entry);
IdPhoneCell = new FormEntryCell(AppResources.Phone, nextElement: IdAddress1Cell.Entry);
IdPhoneCell.Entry.DisableAutocapitalize = true;
IdPhoneCell.Entry.Autocorrect = false;
IdEmailCell = new FormEntryCell(AppResources.Email, Keyboard.Email, nextElement: IdPhoneCell.Entry);
IdEmailCell.Entry.DisableAutocapitalize = true;
IdEmailCell.Entry.Autocorrect = false;
IdLicenseNumberCell = new FormEntryCell(AppResources.LicenseNumber, nextElement: IdEmailCell.Entry);
IdLicenseNumberCell.Entry.DisableAutocapitalize = true;
IdLicenseNumberCell.Entry.Autocorrect = false;
IdPassportNumberCell = new FormEntryCell(AppResources.PassportNumber, nextElement: IdLicenseNumberCell.Entry);
IdPassportNumberCell.Entry.DisableAutocapitalize = true;
IdPassportNumberCell.Entry.Autocorrect = false;
IdSsnCell = new FormEntryCell(AppResources.SSN, nextElement: IdPassportNumberCell.Entry);
IdSsnCell.Entry.DisableAutocapitalize = true;
IdSsnCell.Entry.Autocorrect = false;
IdCompanyCell = new FormEntryCell(AppResources.Company, nextElement: IdSsnCell.Entry);
IdUsernameCell = new FormEntryCell(AppResources.Username, nextElement: IdCompanyCell.Entry);
IdUsernameCell.Entry.DisableAutocapitalize = true;
IdUsernameCell.Entry.Autocorrect = false;
IdLastNameCell = new FormEntryCell(AppResources.LastName, nextElement: IdUsernameCell.Entry);
IdMiddleNameCell = new FormEntryCell(AppResources.MiddleName, nextElement: IdLastNameCell.Entry);
IdFirstNameCell = new FormEntryCell(AppResources.FirstName, nextElement: IdMiddleNameCell.Entry);
IdTitleCell = new FormPickerCell(AppResources.Title, new string[] {
"--", AppResources.Mr, AppResources.Mrs, AppResources.Ms, AppResources.Dr
});
// Name
NameCell.NextElement = IdFirstNameCell.Entry;
// Build sections
TopSection.Add(IdTitleCell);
TopSection.Add(IdFirstNameCell);
TopSection.Add(IdMiddleNameCell);
TopSection.Add(IdLastNameCell);
TopSection.Add(IdUsernameCell);
TopSection.Add(IdCompanyCell);
TopSection.Add(IdSsnCell);
TopSection.Add(IdPassportNumberCell);
TopSection.Add(IdLicenseNumberCell);
TopSection.Add(IdEmailCell);
TopSection.Add(IdPhoneCell);
TopSection.Add(IdAddress1Cell);
TopSection.Add(IdAddress2Cell);
TopSection.Add(IdAddress3Cell);
TopSection.Add(IdCityCell);
TopSection.Add(IdStateCell);
TopSection.Add(IdPostalCodeCell);
TopSection.Add(IdCountryCell);
}
// Make table
TableRoot = new TableRoot
{
TopSection,
MiddleSection,
new TableSection(AppResources.Notes)
{
NotesCell
}
};
Table = new ExtendedTableView
{
Intent = TableIntent.Settings,
EnableScrolling = true,
HasUnevenRows = true,
Root = new TableRoot
{
new TableSection(AppResources.ItemInformation)
{
NameCell,
UriCell,
UsernameCell,
PasswordCell,
GenerateCell
},
new TableSection(" ")
{
TotpCell,
FolderCell,
favoriteCell
},
new TableSection(AppResources.Notes)
{
NotesCell
}
}
Root = TableRoot
};
if(Device.RuntimePlatform == Device.iOS)
{
table.RowHeight = -1;
table.EstimatedRowHeight = 70;
Table.RowHeight = -1;
Table.EstimatedRowHeight = 70;
}
else if(Device.RuntimePlatform == Device.Android)
{
PasswordCell.Button.WidthRequest = 40;
if(TotpCell.Button != null)
if(LoginPasswordCell?.Button != null)
{
TotpCell.Button.WidthRequest = 40;
LoginPasswordCell.Button.WidthRequest = 40;
}
if(LoginTotpCell?.Button != null)
{
LoginTotpCell.Button.WidthRequest = 40;
}
}
}
private void InitSave()
{
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
{
if(_lastAction.LastActionWasRecent())
@ -181,23 +522,151 @@ namespace Bit.App.Pages
{
Name = NameCell.Entry.Text.Encrypt(),
Notes = string.IsNullOrWhiteSpace(NotesCell.Editor.Text) ? null : NotesCell.Editor.Text.Encrypt(),
Favorite = favoriteCell.On,
Login = new Login
{
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(),
Totp = string.IsNullOrWhiteSpace(TotpCell.Entry.Text) ? null :
TotpCell.Entry.Text.Encrypt(),
}
Favorite = FavoriteCell.On,
Type = _type
};
switch(_type)
{
case CipherType.Login:
cipher.Login = new Login
{
Uri = string.IsNullOrWhiteSpace(LoginUriCell.Entry.Text) ? null :
LoginUriCell.Entry.Text.Encrypt(),
Username = string.IsNullOrWhiteSpace(LoginUsernameCell.Entry.Text) ? null :
LoginUsernameCell.Entry.Text.Encrypt(),
Password = string.IsNullOrWhiteSpace(LoginPasswordCell.Entry.Text) ? null :
LoginPasswordCell.Entry.Text.Encrypt(),
Totp = string.IsNullOrWhiteSpace(LoginTotpCell.Entry.Text) ? null :
LoginTotpCell.Entry.Text.Encrypt(),
};
break;
case CipherType.SecureNote:
cipher.SecureNote = new SecureNote
{
Type = SecureNoteType.Generic
};
break;
case CipherType.Card:
string brand;
switch(CardBrandCell.Picker.SelectedIndex)
{
case 1:
brand = "Visa";
break;
case 2:
brand = "Mastercard";
break;
case 3:
brand = "Amex";
break;
case 4:
brand = "Discover";
break;
case 5:
brand = "Diners Club";
break;
case 6:
brand = "JCB";
break;
case 7:
brand = "Maestro";
break;
case 8:
brand = "UnionPay";
break;
case 9:
brand = "Other";
break;
default:
brand = null;
break;
}
var expMonth = CardExpMonthCell.Picker.SelectedIndex > 0 ?
CardExpMonthCell.Picker.SelectedIndex.ToString() : null;
cipher.Card = new Card
{
CardholderName = string.IsNullOrWhiteSpace(CardNameCell.Entry.Text) ? null :
CardNameCell.Entry.Text.Encrypt(),
Number = string.IsNullOrWhiteSpace(CardNumberCell.Entry.Text) ? null :
CardNumberCell.Entry.Text.Encrypt(),
ExpYear = string.IsNullOrWhiteSpace(CardExpYearCell.Entry.Text) ? null :
CardExpYearCell.Entry.Text.Encrypt(),
Code = string.IsNullOrWhiteSpace(CardCodeCell.Entry.Text) ? null :
CardCodeCell.Entry.Text.Encrypt(),
Brand = string.IsNullOrWhiteSpace(brand) ? null : brand.Encrypt(),
ExpMonth = string.IsNullOrWhiteSpace(expMonth) ? null : expMonth.Encrypt(),
};
break;
case CipherType.Identity:
string title;
switch(IdTitleCell.Picker.SelectedIndex)
{
case 1:
title = AppResources.Mr;
break;
case 2:
title = AppResources.Mrs;
break;
case 3:
title = AppResources.Ms;
break;
case 4:
title = AppResources.Dr;
break;
default:
title = null;
break;
}
cipher.Identity = new Identity
{
Title = string.IsNullOrWhiteSpace(title) ? null : title.Encrypt(),
FirstName = string.IsNullOrWhiteSpace(IdFirstNameCell.Entry.Text) ? null :
IdFirstNameCell.Entry.Text.Encrypt(),
MiddleName = string.IsNullOrWhiteSpace(IdMiddleNameCell.Entry.Text) ? null :
IdMiddleNameCell.Entry.Text.Encrypt(),
LastName = string.IsNullOrWhiteSpace(IdLastNameCell.Entry.Text) ? null :
IdLastNameCell.Entry.Text.Encrypt(),
Username = string.IsNullOrWhiteSpace(IdUsernameCell.Entry.Text) ? null :
IdUsernameCell.Entry.Text.Encrypt(),
Company = string.IsNullOrWhiteSpace(IdCompanyCell.Entry.Text) ? null :
IdCompanyCell.Entry.Text.Encrypt(),
SSN = string.IsNullOrWhiteSpace(IdSsnCell.Entry.Text) ? null :
IdSsnCell.Entry.Text.Encrypt(),
PassportNumber = string.IsNullOrWhiteSpace(IdPassportNumberCell.Entry.Text) ? null :
IdPassportNumberCell.Entry.Text.Encrypt(),
LicenseNumber = string.IsNullOrWhiteSpace(IdLicenseNumberCell.Entry.Text) ? null :
IdLicenseNumberCell.Entry.Text.Encrypt(),
Email = string.IsNullOrWhiteSpace(IdEmailCell.Entry.Text) ? null :
IdEmailCell.Entry.Text.Encrypt(),
Phone = string.IsNullOrWhiteSpace(IdPhoneCell.Entry.Text) ? null :
IdPhoneCell.Entry.Text.Encrypt(),
Address1 = string.IsNullOrWhiteSpace(IdAddress1Cell.Entry.Text) ? null :
IdAddress1Cell.Entry.Text.Encrypt(),
Address2 = string.IsNullOrWhiteSpace(IdAddress2Cell.Entry.Text) ? null :
IdAddress2Cell.Entry.Text.Encrypt(),
Address3 = string.IsNullOrWhiteSpace(IdAddress3Cell.Entry.Text) ? null :
IdAddress3Cell.Entry.Text.Encrypt(),
City = string.IsNullOrWhiteSpace(IdCityCell.Entry.Text) ? null :
IdCityCell.Entry.Text.Encrypt(),
State = string.IsNullOrWhiteSpace(IdStateCell.Entry.Text) ? null :
IdStateCell.Entry.Text.Encrypt(),
PostalCode = string.IsNullOrWhiteSpace(IdPostalCodeCell.Entry.Text) ? null :
IdPostalCodeCell.Entry.Text.Encrypt(),
Country = string.IsNullOrWhiteSpace(IdCountryCell.Entry.Text) ? null :
IdCountryCell.Entry.Text.Encrypt()
};
break;
default:
break;
}
if(FolderCell.Picker.SelectedIndex > 0)
{
cipher.FolderId = folders.ElementAt(FolderCell.Picker.SelectedIndex - 1).Id;
cipher.FolderId = Folders.ElementAt(FolderCell.Picker.SelectedIndex - 1).Id;
}
_userDialogs.ShowLoading(AppResources.Saving, MaskType.Black);
@ -227,115 +696,7 @@ namespace Bit.App.Pages
}
}, ToolbarItemOrder.Default, 0);
Title = AppResources.AddItem;
Content = table;
ToolbarItems.Add(saveToolBarItem);
if(Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Windows)
{
ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel));
}
}
protected override void OnAppearing()
{
base.OnAppearing();
if(!_connectivity.IsConnected)
{
AlertNoConnection();
}
PasswordCell.InitEvents();
UsernameCell.InitEvents();
UriCell.InitEvents();
NameCell.InitEvents();
NotesCell.InitEvents();
TotpCell.InitEvents();
FolderCell.InitEvents();
PasswordCell.Button.Clicked += PasswordButton_Clicked;
if(TotpCell?.Button != null)
{
TotpCell.Button.Clicked += TotpButton_Clicked;
}
GenerateCell.Tapped += GenerateCell_Tapped;
if(!_fromAutofill && !_settings.GetValueOrDefault(AddedLoginAlertKey, false))
{
_settings.AddOrUpdateValue(AddedLoginAlertKey, true);
if(Device.RuntimePlatform == Device.iOS)
{
DisplayAlert(AppResources.BitwardenAppExtension, AppResources.BitwardenAppExtensionAlert,
AppResources.Ok);
}
else if(Device.RuntimePlatform == Device.Android && !_appInfoService.AutofillServiceEnabled)
{
DisplayAlert(AppResources.BitwardenAutofillService, AppResources.BitwardenAutofillServiceAlert,
AppResources.Ok);
}
}
NameCell.Entry.FocusWithDelay();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
PasswordCell.Dispose();
UsernameCell.Dispose();
UriCell.Dispose();
NameCell.Dispose();
NotesCell.Dispose();
TotpCell.Dispose();
FolderCell.Dispose();
PasswordCell.Button.Clicked -= PasswordButton_Clicked;
if(TotpCell?.Button != null)
{
TotpCell.Button.Clicked -= TotpButton_Clicked;
}
GenerateCell.Tapped -= GenerateCell_Tapped;
}
private void PasswordButton_Clicked(object sender, EventArgs e)
{
PasswordCell.Entry.InvokeToggleIsPassword();
PasswordCell.Button.Image = "eye" + (!PasswordCell.Entry.IsPasswordFromToggled ? "_slash" : string.Empty);
}
private async void TotpButton_Clicked(object sender, EventArgs e)
{
var scanPage = new ScanPage((key) =>
{
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopModalAsync();
if(!string.IsNullOrWhiteSpace(key))
{
TotpCell.Entry.Text = key;
_userDialogs.Toast(AppResources.AuthenticatorKeyAdded);
}
else
{
_userDialogs.Alert(AppResources.AuthenticatorKeyReadError);
}
});
});
await Navigation.PushModalAsync(new ExtendedNavigationPage(scanPage));
}
private async void GenerateCell_Tapped(object sender, EventArgs e)
{
var page = new ToolsPasswordGeneratorPage((password) =>
{
PasswordCell.Entry.Text = password;
_userDialogs.Toast(AppResources.PasswordGenerated);
}, _fromAutofill);
await Navigation.PushForDeviceAsync(page);
}
private void AlertNoConnection()
{
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage,
AppResources.Ok);
}
}
}

View File

@ -12,6 +12,7 @@ using Bit.App.Utilities;
using System.Threading;
using Bit.App.Models;
using System.Collections.Generic;
using Bit.App.Enums;
namespace Bit.App.Pages
{
@ -231,7 +232,7 @@ namespace Bit.App.Pages
private async void AddCipherAsync()
{
var page = new VaultAddLoginPage(Uri, _name, true);
var page = new VaultAddLoginPage(CipherType.Login, Uri, _name, true);
await Navigation.PushForDeviceAsync(page);
}

View File

@ -14,6 +14,7 @@ using Plugin.Connectivity.Abstractions;
using System.Collections.Generic;
using System.Threading;
using FFImageLoading.Forms;
using Bit.App.Enums;
namespace Bit.App.Pages
{
@ -490,7 +491,28 @@ namespace Bit.App.Pages
private async void AddCipher()
{
var page = new VaultAddLoginPage(Uri);
var type = await _userDialogs.ActionSheetAsync(AppResources.SelectTypeAdd, AppResources.Cancel, null, null,
AppResources.TypeLogin, AppResources.TypeCard, AppResources.TypeIdentity, AppResources.TypeSecureNote);
var selectedType = CipherType.SecureNote;
if(type == AppResources.Cancel)
{
return;
}
else if(type == AppResources.TypeLogin)
{
selectedType = CipherType.Login;
}
else if(type == AppResources.TypeCard)
{
selectedType = CipherType.Card;
}
else if(type == AppResources.TypeIdentity)
{
selectedType = CipherType.Identity;
}
var page = new VaultAddLoginPage(selectedType, Uri);
await Navigation.PushForDeviceAsync(page);
}

View File

@ -133,6 +133,33 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Address 1.
/// </summary>
public static string Address1 {
get {
return ResourceManager.GetString("Address1", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Address 2.
/// </summary>
public static string Address2 {
get {
return ResourceManager.GetString("Address2", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Address 3.
/// </summary>
public static string Address3 {
get {
return ResourceManager.GetString("Address3", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An error has occurred..
/// </summary>
@ -160,6 +187,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to April.
/// </summary>
public static string April {
get {
return ResourceManager.GetString("April", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Attachment added.
/// </summary>
@ -196,6 +232,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to August.
/// </summary>
public static string August {
get {
return ResourceManager.GetString("August", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Authenticator App.
/// </summary>
@ -484,6 +529,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Brand.
/// </summary>
public static string Brand {
get {
return ResourceManager.GetString("Brand", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Camera.
/// </summary>
@ -529,6 +583,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Cardholder Name.
/// </summary>
public static string CardholderName {
get {
return ResourceManager.GetString("CardholderName", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Change Email.
/// </summary>
@ -574,6 +637,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to City / Town.
/// </summary>
public static string CityTown {
get {
return ResourceManager.GetString("CityTown", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Close.
/// </summary>
@ -592,6 +664,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Company.
/// </summary>
public static string Company {
get {
return ResourceManager.GetString("Company", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Continue.
/// </summary>
@ -691,6 +772,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Country.
/// </summary>
public static string Country {
get {
return ResourceManager.GetString("Country", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Create Account.
/// </summary>
@ -754,6 +844,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to December.
/// </summary>
public static string December {
get {
return ResourceManager.GetString("December", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Delete.
/// </summary>
@ -835,6 +934,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Dr.
/// </summary>
public static string Dr {
get {
return ResourceManager.GetString("Dr", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Edit.
/// </summary>
@ -970,6 +1078,24 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Expiration Month.
/// </summary>
public static string ExpirationMonth {
get {
return ResourceManager.GetString("ExpirationMonth", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Expiration Year.
/// </summary>
public static string ExpirationYear {
get {
return ResourceManager.GetString("ExpirationYear", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Extension Activated!.
/// </summary>
@ -1105,6 +1231,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to February.
/// </summary>
public static string February {
get {
return ResourceManager.GetString("February", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to File.
/// </summary>
@ -1159,6 +1294,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to First Name.
/// </summary>
public static string FirstName {
get {
return ResourceManager.GetString("FirstName", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Folder.
/// </summary>
@ -1393,6 +1537,42 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to January.
/// </summary>
public static string January {
get {
return ResourceManager.GetString("January", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to July.
/// </summary>
public static string July {
get {
return ResourceManager.GetString("July", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to June.
/// </summary>
public static string June {
get {
return ResourceManager.GetString("June", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Last Name.
/// </summary>
public static string LastName {
get {
return ResourceManager.GetString("LastName", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Last Sync:.
/// </summary>
@ -1429,6 +1609,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to License Number.
/// </summary>
public static string LicenseNumber {
get {
return ResourceManager.GetString("LicenseNumber", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Lock.
/// </summary>
@ -1573,6 +1762,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to March.
/// </summary>
public static string March {
get {
return ResourceManager.GetString("March", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Master Password.
/// </summary>
@ -1645,6 +1843,24 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to May.
/// </summary>
public static string May {
get {
return ResourceManager.GetString("May", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Middle Name.
/// </summary>
public static string MiddleName {
get {
return ResourceManager.GetString("MiddleName", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Minimum Numbers.
/// </summary>
@ -1681,6 +1897,33 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Mr.
/// </summary>
public static string Mr {
get {
return ResourceManager.GetString("Mr", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Mrs.
/// </summary>
public static string Mrs {
get {
return ResourceManager.GetString("Mrs", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Ms.
/// </summary>
public static string Ms {
get {
return ResourceManager.GetString("Ms", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You must log into the main bitwarden app before you can use the extension..
/// </summary>
@ -1825,6 +2068,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to November.
/// </summary>
public static string November {
get {
return ResourceManager.GetString("November", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Number.
/// </summary>
@ -1834,6 +2086,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to October.
/// </summary>
public static string October {
get {
return ResourceManager.GetString("October", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Ok.
/// </summary>
@ -1879,6 +2140,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Passport Number.
/// </summary>
public static string PassportNumber {
get {
return ResourceManager.GetString("PassportNumber", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Password.
/// </summary>
@ -1942,6 +2212,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Phone.
/// </summary>
public static string Phone {
get {
return ResourceManager.GetString("Phone", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Photos.
/// </summary>
@ -2122,6 +2401,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to What type of item do you want to add?.
/// </summary>
public static string SelectTypeAdd {
get {
return ResourceManager.GetString("SelectTypeAdd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Self-hosted Environment.
/// </summary>
@ -2149,6 +2437,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to September.
/// </summary>
public static string September {
get {
return ResourceManager.GetString("September", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Server URL.
/// </summary>
@ -2212,6 +2509,24 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Social Security Number.
/// </summary>
public static string SSN {
get {
return ResourceManager.GetString("SSN", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to State / Province.
/// </summary>
public static string StateProvince {
get {
return ResourceManager.GetString("StateProvince", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Status.
/// </summary>
@ -2293,6 +2608,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Title.
/// </summary>
public static string Title {
get {
return ResourceManager.GetString("Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Tools.
/// </summary>
@ -2347,6 +2671,42 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Card.
/// </summary>
public static string TypeCard {
get {
return ResourceManager.GetString("TypeCard", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Identity.
/// </summary>
public static string TypeIdentity {
get {
return ResourceManager.GetString("TypeIdentity", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Login.
/// </summary>
public static string TypeLogin {
get {
return ResourceManager.GetString("TypeLogin", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Secure Note.
/// </summary>
public static string TypeSecureNote {
get {
return ResourceManager.GetString("TypeSecureNote", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Unable to download file..
/// </summary>
@ -2625,5 +2985,14 @@ namespace Bit.App.Resources {
return ResourceManager.GetString("YubiKeyTitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Zip / Postal Code.
/// </summary>
public static string ZipPostalCode {
get {
return ResourceManager.GetString("ZipPostalCode", resourceCulture);
}
}
}
}

View File

@ -1047,4 +1047,127 @@
<data name="SecurityCode" xml:space="preserve">
<value>Security Code</value>
</data>
<data name="SelectTypeAdd" xml:space="preserve">
<value>What type of item do you want to add?</value>
</data>
<data name="TypeCard" xml:space="preserve">
<value>Card</value>
</data>
<data name="TypeIdentity" xml:space="preserve">
<value>Identity</value>
</data>
<data name="TypeLogin" xml:space="preserve">
<value>Login</value>
</data>
<data name="TypeSecureNote" xml:space="preserve">
<value>Secure Note</value>
</data>
<data name="Address1" xml:space="preserve">
<value>Address 1</value>
</data>
<data name="Address2" xml:space="preserve">
<value>Address 2</value>
</data>
<data name="Address3" xml:space="preserve">
<value>Address 3</value>
</data>
<data name="April" xml:space="preserve">
<value>April</value>
</data>
<data name="August" xml:space="preserve">
<value>August</value>
</data>
<data name="Brand" xml:space="preserve">
<value>Brand</value>
</data>
<data name="CardholderName" xml:space="preserve">
<value>Cardholder Name</value>
</data>
<data name="CityTown" xml:space="preserve">
<value>City / Town</value>
</data>
<data name="Company" xml:space="preserve">
<value>Company</value>
</data>
<data name="Country" xml:space="preserve">
<value>Country</value>
</data>
<data name="December" xml:space="preserve">
<value>December</value>
</data>
<data name="Dr" xml:space="preserve">
<value>Dr</value>
</data>
<data name="ExpirationMonth" xml:space="preserve">
<value>Expiration Month</value>
</data>
<data name="ExpirationYear" xml:space="preserve">
<value>Expiration Year</value>
</data>
<data name="February" xml:space="preserve">
<value>February</value>
</data>
<data name="FirstName" xml:space="preserve">
<value>First Name</value>
</data>
<data name="January" xml:space="preserve">
<value>January</value>
</data>
<data name="July" xml:space="preserve">
<value>July</value>
</data>
<data name="June" xml:space="preserve">
<value>June</value>
</data>
<data name="LastName" xml:space="preserve">
<value>Last Name</value>
</data>
<data name="LicenseNumber" xml:space="preserve">
<value>License Number</value>
</data>
<data name="March" xml:space="preserve">
<value>March</value>
</data>
<data name="May" xml:space="preserve">
<value>May</value>
</data>
<data name="MiddleName" xml:space="preserve">
<value>Middle Name</value>
</data>
<data name="Mr" xml:space="preserve">
<value>Mr</value>
</data>
<data name="Mrs" xml:space="preserve">
<value>Mrs</value>
</data>
<data name="Ms" xml:space="preserve">
<value>Ms</value>
</data>
<data name="November" xml:space="preserve">
<value>November</value>
</data>
<data name="October" xml:space="preserve">
<value>October</value>
</data>
<data name="PassportNumber" xml:space="preserve">
<value>Passport Number</value>
</data>
<data name="Phone" xml:space="preserve">
<value>Phone</value>
</data>
<data name="September" xml:space="preserve">
<value>September</value>
</data>
<data name="SSN" xml:space="preserve">
<value>Social Security Number</value>
</data>
<data name="StateProvince" xml:space="preserve">
<value>State / Province</value>
</data>
<data name="Title" xml:space="preserve">
<value>Title</value>
</data>
<data name="ZipPostalCode" xml:space="preserve">
<value>Zip / Postal Code</value>
</data>
</root>