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

pop pages if cipher doesnt exist

This commit is contained in:
Kyle Spearrin 2019-05-30 08:40:10 -04:00
parent 46a8ffa5ae
commit e34ca49b9b
4 changed files with 28 additions and 4 deletions

View File

@ -54,7 +54,14 @@ namespace Bit.App.Pages
protected override async void OnAppearing() protected override async void OnAppearing()
{ {
base.OnAppearing(); base.OnAppearing();
await LoadOnAppearedAsync(_scrollView, true, () => _vm.LoadAsync(_appOptions)); await LoadOnAppearedAsync(_scrollView, true, async () =>
{
var success = await _vm.LoadAsync();
if(!success)
{
await Navigation.PopModalAsync();
}
});
if(_vm.EditMode && Device.RuntimePlatform == Device.Android) if(_vm.EditMode && Device.RuntimePlatform == Device.Android)
{ {
if(_vm.Cipher.OrganizationId == null) if(_vm.Cipher.OrganizationId == null)

View File

@ -267,7 +267,7 @@ namespace Bit.App.Pages
PageTitle = EditMode ? AppResources.EditItem : AppResources.AddItem; PageTitle = EditMode ? AppResources.EditItem : AppResources.AddItem;
} }
public async Task LoadAsync(AppOptions appOptions = null) public async Task<bool> LoadAsync(AppOptions appOptions = null)
{ {
var myEmail = await _userService.GetEmailAsync(); var myEmail = await _userService.GetEmailAsync();
OwnershipOptions.Add(new KeyValuePair<string, string>(myEmail, null)); OwnershipOptions.Add(new KeyValuePair<string, string>(myEmail, null));
@ -296,6 +296,10 @@ namespace Bit.App.Pages
if(EditMode) if(EditMode)
{ {
var cipher = await _cipherService.GetAsync(CipherId); var cipher = await _cipherService.GetAsync(CipherId);
if(cipher == null)
{
return false;
}
Cipher = await cipher.DecryptAsync(); Cipher = await cipher.DecryptAsync();
} }
else else
@ -358,6 +362,7 @@ namespace Bit.App.Pages
Fields.ResetWithRange(Cipher.Fields?.Select(f => new AddEditPageFieldViewModel(f))); Fields.ResetWithRange(Cipher.Fields?.Select(f => new AddEditPageFieldViewModel(f)));
} }
} }
return true;
} }
public async Task<bool> SubmitAsync() public async Task<bool> SubmitAsync()

View File

@ -49,7 +49,14 @@ namespace Bit.App.Pages
} }
} }
}); });
await LoadOnAppearedAsync(_scrollView, true, () => _vm.LoadAsync(), _mainContent); await LoadOnAppearedAsync(_scrollView, true, async () =>
{
var success = await _vm.LoadAsync();
if(!success)
{
await Navigation.PopModalAsync();
}
}, _mainContent);
if(Device.RuntimePlatform == Device.Android) if(Device.RuntimePlatform == Device.Android)
{ {
if(_vm.Cipher.OrganizationId == null) if(_vm.Cipher.OrganizationId == null)

View File

@ -206,10 +206,14 @@ namespace Bit.App.Pages
} }
} }
public async Task LoadAsync() public async Task<bool> LoadAsync()
{ {
CleanUp(); CleanUp();
var cipher = await _cipherService.GetAsync(CipherId); var cipher = await _cipherService.GetAsync(CipherId);
if(cipher == null)
{
return false;
}
Cipher = await cipher.DecryptAsync(); Cipher = await cipher.DecryptAsync();
CanAccessPremium = await _userService.CanAccessPremiumAsync(); CanAccessPremium = await _userService.CanAccessPremiumAsync();
Fields = Cipher.Fields?.Select(f => new ViewPageFieldViewModel(f)).ToList(); Fields = Cipher.Fields?.Select(f => new ViewPageFieldViewModel(f)).ToList();
@ -231,6 +235,7 @@ namespace Bit.App.Pages
return true; return true;
}); });
} }
return true;
} }
public void CleanUp() public void CleanUp()