mirror of
https://github.com/bitwarden/mobile.git
synced 2024-12-18 15:37:42 +01:00
populate add page from autofill
This commit is contained in:
parent
65f3a146fa
commit
9ab41c5de6
@ -9,15 +9,21 @@ namespace Bit.App.Pages
|
|||||||
{
|
{
|
||||||
private AddEditPageViewModel _vm;
|
private AddEditPageViewModel _vm;
|
||||||
private readonly AppOptions _appOptions;
|
private readonly AppOptions _appOptions;
|
||||||
|
private bool _fromAutofill;
|
||||||
|
|
||||||
public AddEditPage(
|
public AddEditPage(
|
||||||
string cipherId = null,
|
string cipherId = null,
|
||||||
CipherType? type = null,
|
CipherType? type = null,
|
||||||
string folderId = null,
|
string folderId = null,
|
||||||
string collectionId = null,
|
string collectionId = null,
|
||||||
|
string name = null,
|
||||||
|
string uri = null,
|
||||||
|
bool fromAutofill = false,
|
||||||
AppOptions appOptions = null)
|
AppOptions appOptions = null)
|
||||||
{
|
{
|
||||||
_appOptions = appOptions;
|
_appOptions = appOptions;
|
||||||
|
_fromAutofill = fromAutofill;
|
||||||
|
FromAutofillFramework = _appOptions?.FromAutofillFramework ?? false;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_vm = BindingContext as AddEditPageViewModel;
|
_vm = BindingContext as AddEditPageViewModel;
|
||||||
_vm.Page = this;
|
_vm.Page = this;
|
||||||
@ -25,6 +31,8 @@ namespace Bit.App.Pages
|
|||||||
_vm.FolderId = folderId;
|
_vm.FolderId = folderId;
|
||||||
_vm.CollectionIds = collectionId != null ? new HashSet<string>(new List<string> { collectionId }) : null;
|
_vm.CollectionIds = collectionId != null ? new HashSet<string>(new List<string> { collectionId }) : null;
|
||||||
_vm.Type = type;
|
_vm.Type = type;
|
||||||
|
_vm.DefaultName = name ?? appOptions?.SaveName;
|
||||||
|
_vm.DefaultUri = uri ?? appOptions?.Uri;
|
||||||
_vm.Init();
|
_vm.Init();
|
||||||
SetActivityIndicator();
|
SetActivityIndicator();
|
||||||
if(!_vm.EditMode)
|
if(!_vm.EditMode)
|
||||||
@ -41,6 +49,8 @@ namespace Bit.App.Pages
|
|||||||
_ownershipPicker.ItemDisplayBinding = new Binding("Key");
|
_ownershipPicker.ItemDisplayBinding = new Binding("Key");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool FromAutofillFramework { get; set; }
|
||||||
|
|
||||||
protected override async void OnAppearing()
|
protected override async void OnAppearing()
|
||||||
{
|
{
|
||||||
base.OnAppearing();
|
base.OnAppearing();
|
||||||
@ -77,6 +87,16 @@ namespace Bit.App.Pages
|
|||||||
base.OnDisappearing();
|
base.OnDisappearing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool OnBackButtonPressed()
|
||||||
|
{
|
||||||
|
if(FromAutofillFramework)
|
||||||
|
{
|
||||||
|
Application.Current.MainPage = new TabsPage();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return base.OnBackButtonPressed();
|
||||||
|
}
|
||||||
|
|
||||||
private async void PasswordHistory_Tapped(object sender, System.EventArgs e)
|
private async void PasswordHistory_Tapped(object sender, System.EventArgs e)
|
||||||
{
|
{
|
||||||
if(DoOnce())
|
if(DoOnce())
|
||||||
|
@ -142,6 +142,8 @@ namespace Bit.App.Pages
|
|||||||
public string FolderId { get; set; }
|
public string FolderId { get; set; }
|
||||||
public CipherType? Type { get; set; }
|
public CipherType? Type { get; set; }
|
||||||
public HashSet<string> CollectionIds { get; set; }
|
public HashSet<string> CollectionIds { get; set; }
|
||||||
|
public string DefaultName { get; set; }
|
||||||
|
public string DefaultUri { get; set; }
|
||||||
public List<KeyValuePair<string, CipherType>> TypeOptions { get; set; }
|
public List<KeyValuePair<string, CipherType>> TypeOptions { get; set; }
|
||||||
public List<KeyValuePair<string, string>> CardBrandOptions { get; set; }
|
public List<KeyValuePair<string, string>> CardBrandOptions { get; set; }
|
||||||
public List<KeyValuePair<string, string>> CardExpMonthOptions { get; set; }
|
public List<KeyValuePair<string, string>> CardExpMonthOptions { get; set; }
|
||||||
@ -300,6 +302,7 @@ namespace Bit.App.Pages
|
|||||||
{
|
{
|
||||||
Cipher = new CipherView
|
Cipher = new CipherView
|
||||||
{
|
{
|
||||||
|
Name = DefaultName,
|
||||||
OrganizationId = OrganizationId,
|
OrganizationId = OrganizationId,
|
||||||
FolderId = FolderId,
|
FolderId = FolderId,
|
||||||
Type = Type.GetValueOrDefault(CipherType.Login),
|
Type = Type.GetValueOrDefault(CipherType.Login),
|
||||||
@ -308,7 +311,7 @@ namespace Bit.App.Pages
|
|||||||
Identity = new IdentityView(),
|
Identity = new IdentityView(),
|
||||||
SecureNote = new SecureNoteView()
|
SecureNote = new SecureNoteView()
|
||||||
};
|
};
|
||||||
Cipher.Login.Uris = new List<LoginUriView> { new LoginUriView() };
|
Cipher.Login.Uris = new List<LoginUriView> { new LoginUriView { Uri = DefaultUri } };
|
||||||
Cipher.SecureNote.Type = SecureNoteType.Generic;
|
Cipher.SecureNote.Type = SecureNoteType.Generic;
|
||||||
TypeSelectedIndex = TypeOptions.FindIndex(k => k.Value == Cipher.Type);
|
TypeSelectedIndex = TypeOptions.FindIndex(k => k.Value == Cipher.Type);
|
||||||
|
|
||||||
@ -398,7 +401,16 @@ namespace Bit.App.Pages
|
|||||||
_platformUtilsService.ShowToast("success", null,
|
_platformUtilsService.ShowToast("success", null,
|
||||||
EditMode ? AppResources.ItemUpdated : AppResources.NewItemCreated);
|
EditMode ? AppResources.ItemUpdated : AppResources.NewItemCreated);
|
||||||
_messagingService.Send(EditMode ? "editedCipher" : "addedCipher");
|
_messagingService.Send(EditMode ? "editedCipher" : "addedCipher");
|
||||||
await Page.Navigation.PopModalAsync();
|
|
||||||
|
if((Page as AddEditPage).FromAutofillFramework)
|
||||||
|
{
|
||||||
|
// Close and go back to app
|
||||||
|
_deviceActionService.CloseAutofill();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await Page.Navigation.PopModalAsync();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch(ApiException e)
|
catch(ApiException e)
|
||||||
|
@ -49,11 +49,12 @@ namespace Bit.App.Pages
|
|||||||
}
|
}
|
||||||
if(_appOptions.FillType.HasValue && _appOptions.FillType != CipherType.Login)
|
if(_appOptions.FillType.HasValue && _appOptions.FillType != CipherType.Login)
|
||||||
{
|
{
|
||||||
var pageForOther = new AddEditPage(type: _appOptions.FillType);
|
var pageForOther = new AddEditPage(type: _appOptions.FillType, fromAutofill: true);
|
||||||
await Navigation.PushModalAsync(new NavigationPage(pageForOther));
|
await Navigation.PushModalAsync(new NavigationPage(pageForOther));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var pageForLogin = new AddEditPage(null, CipherType.Login);
|
var pageForLogin = new AddEditPage(null, CipherType.Login, uri: _vm.Uri, name: _vm.Name,
|
||||||
|
fromAutofill: true);
|
||||||
await Navigation.PushModalAsync(new NavigationPage(pageForLogin));
|
await Navigation.PushModalAsync(new NavigationPage(pageForLogin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,8 +23,6 @@ namespace Bit.App.Pages
|
|||||||
private readonly ICipherService _cipherService;
|
private readonly ICipherService _cipherService;
|
||||||
|
|
||||||
private AppOptions _appOptions;
|
private AppOptions _appOptions;
|
||||||
private string _name;
|
|
||||||
private string _uri;
|
|
||||||
private bool _showList;
|
private bool _showList;
|
||||||
private string _noDataText;
|
private string _noDataText;
|
||||||
|
|
||||||
@ -38,6 +36,8 @@ namespace Bit.App.Pages
|
|||||||
CipherOptionsCommand = new Command<CipherView>(CipherOptionsAsync);
|
CipherOptionsCommand = new Command<CipherView>(CipherOptionsAsync);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Uri { get; set; }
|
||||||
public Command CipherOptionsCommand { get; set; }
|
public Command CipherOptionsCommand { get; set; }
|
||||||
public ExtendedObservableCollection<GroupingsPageListGroup> GroupedItems { get; set; }
|
public ExtendedObservableCollection<GroupingsPageListGroup> GroupedItems { get; set; }
|
||||||
|
|
||||||
@ -56,25 +56,27 @@ namespace Bit.App.Pages
|
|||||||
public void Init(AppOptions appOptions)
|
public void Init(AppOptions appOptions)
|
||||||
{
|
{
|
||||||
_appOptions = appOptions;
|
_appOptions = appOptions;
|
||||||
_uri = appOptions.Uri;
|
Uri = appOptions.Uri;
|
||||||
if(_uri.StartsWith(Constants.AndroidAppProtocol))
|
string name = null;
|
||||||
|
if(Uri.StartsWith(Constants.AndroidAppProtocol))
|
||||||
{
|
{
|
||||||
_name = _uri.Substring(Constants.AndroidAppProtocol.Length);
|
name = Uri.Substring(Constants.AndroidAppProtocol.Length);
|
||||||
}
|
}
|
||||||
else if(!Uri.TryCreate(_uri, UriKind.Absolute, out Uri uri) ||
|
else if(!System.Uri.TryCreate(Uri, UriKind.Absolute, out Uri uri) ||
|
||||||
!DomainName.TryParseBaseDomain(uri.Host, out _name))
|
!DomainName.TryParseBaseDomain(uri.Host, out name))
|
||||||
{
|
{
|
||||||
_name = "--";
|
name = "--";
|
||||||
}
|
}
|
||||||
PageTitle = string.Format(AppResources.ItemsForUri, _name ?? "--");
|
Name = name;
|
||||||
NoDataText = string.Format(AppResources.NoItemsForUri, _name ?? "--");
|
PageTitle = string.Format(AppResources.ItemsForUri, Name ?? "--");
|
||||||
|
NoDataText = string.Format(AppResources.NoItemsForUri, Name ?? "--");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task LoadAsync()
|
public async Task LoadAsync()
|
||||||
{
|
{
|
||||||
ShowList = false;
|
ShowList = false;
|
||||||
var groupedItems = new List<GroupingsPageListGroup>();
|
var groupedItems = new List<GroupingsPageListGroup>();
|
||||||
var ciphers = await _cipherService.GetAllDecryptedByUrlAsync(_uri, null);
|
var ciphers = await _cipherService.GetAllDecryptedByUrlAsync(Uri, null);
|
||||||
var matching = ciphers.Item1?.Select(c => new GroupingsPageListItem { Cipher = c }).ToList();
|
var matching = ciphers.Item1?.Select(c => new GroupingsPageListItem { Cipher = c }).ToList();
|
||||||
if(matching?.Any() ?? false)
|
if(matching?.Any() ?? false)
|
||||||
{
|
{
|
||||||
@ -109,7 +111,7 @@ namespace Bit.App.Pages
|
|||||||
options.Add(AppResources.YesAndSave);
|
options.Add(AppResources.YesAndSave);
|
||||||
}
|
}
|
||||||
autofillResponse = await _deviceActionService.DisplayAlertAsync(null,
|
autofillResponse = await _deviceActionService.DisplayAlertAsync(null,
|
||||||
string.Format(AppResources.BitwardenAutofillServiceMatchConfirm, _name), AppResources.No,
|
string.Format(AppResources.BitwardenAutofillServiceMatchConfirm, Name), AppResources.No,
|
||||||
options.ToArray());
|
options.ToArray());
|
||||||
}
|
}
|
||||||
if(autofillResponse == AppResources.YesAndSave && cipher.Type == CipherType.Login)
|
if(autofillResponse == AppResources.YesAndSave && cipher.Type == CipherType.Login)
|
||||||
@ -121,7 +123,7 @@ namespace Bit.App.Pages
|
|||||||
}
|
}
|
||||||
uris.Add(new LoginUriView
|
uris.Add(new LoginUriView
|
||||||
{
|
{
|
||||||
Uri = _uri,
|
Uri = Uri,
|
||||||
Match = null
|
Match = null
|
||||||
});
|
});
|
||||||
cipher.Login.Uris = uris;
|
cipher.Login.Uris = uris;
|
||||||
|
Loading…
Reference in New Issue
Block a user