1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-09-28 03:57:43 +02:00

check internet connection before calling server

This commit is contained in:
Kyle Spearrin 2019-06-03 22:43:52 -04:00
parent b38b801963
commit e03cf94441
14 changed files with 120 additions and 3 deletions

View File

@ -11,11 +11,13 @@ namespace Bit.App.Pages
public class HintPageViewModel : BaseViewModel public class HintPageViewModel : BaseViewModel
{ {
private readonly IDeviceActionService _deviceActionService; private readonly IDeviceActionService _deviceActionService;
private readonly IPlatformUtilsService _platformUtilsService;
private readonly IApiService _apiService; private readonly IApiService _apiService;
public HintPageViewModel() public HintPageViewModel()
{ {
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService"); _deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
_apiService = ServiceContainer.Resolve<IApiService>("apiService"); _apiService = ServiceContainer.Resolve<IApiService>("apiService");
PageTitle = AppResources.PasswordHint; PageTitle = AppResources.PasswordHint;
@ -27,6 +29,12 @@ namespace Bit.App.Pages
public async Task SubmitAsync() public async Task SubmitAsync()
{ {
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return;
}
if(string.IsNullOrWhiteSpace(Email)) if(string.IsNullOrWhiteSpace(Email))
{ {
await Page.DisplayAlert(AppResources.AnErrorHasOccurred, await Page.DisplayAlert(AppResources.AnErrorHasOccurred,

View File

@ -17,6 +17,7 @@ namespace Bit.App.Pages
private readonly IAuthService _authService; private readonly IAuthService _authService;
private readonly ISyncService _syncService; private readonly ISyncService _syncService;
private readonly IStorageService _storageService; private readonly IStorageService _storageService;
private readonly IPlatformUtilsService _platformUtilsService;
private bool _showPassword; private bool _showPassword;
private string _email; private string _email;
@ -28,6 +29,7 @@ namespace Bit.App.Pages
_authService = ServiceContainer.Resolve<IAuthService>("authService"); _authService = ServiceContainer.Resolve<IAuthService>("authService");
_syncService = ServiceContainer.Resolve<ISyncService>("syncService"); _syncService = ServiceContainer.Resolve<ISyncService>("syncService");
_storageService = ServiceContainer.Resolve<IStorageService>("storageService"); _storageService = ServiceContainer.Resolve<IStorageService>("storageService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
PageTitle = AppResources.Bitwarden; PageTitle = AppResources.Bitwarden;
TogglePasswordCommand = new Command(TogglePassword); TogglePasswordCommand = new Command(TogglePassword);
@ -73,6 +75,12 @@ namespace Bit.App.Pages
public async Task LogInAsync() public async Task LogInAsync()
{ {
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return;
}
if(string.IsNullOrWhiteSpace(Email)) if(string.IsNullOrWhiteSpace(Email))
{ {
await Page.DisplayAlert(AppResources.AnErrorHasOccurred, await Page.DisplayAlert(AppResources.AnErrorHasOccurred,

View File

@ -15,6 +15,7 @@ namespace Bit.App.Pages
private readonly IDeviceActionService _deviceActionService; private readonly IDeviceActionService _deviceActionService;
private readonly IApiService _apiService; private readonly IApiService _apiService;
private readonly ICryptoService _cryptoService; private readonly ICryptoService _cryptoService;
private readonly IPlatformUtilsService _platformUtilsService;
private bool _showPassword; private bool _showPassword;
@ -23,6 +24,7 @@ namespace Bit.App.Pages
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService"); _deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
_apiService = ServiceContainer.Resolve<IApiService>("apiService"); _apiService = ServiceContainer.Resolve<IApiService>("apiService");
_cryptoService = ServiceContainer.Resolve<ICryptoService>("cryptoService"); _cryptoService = ServiceContainer.Resolve<ICryptoService>("cryptoService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
PageTitle = AppResources.Bitwarden; PageTitle = AppResources.Bitwarden;
TogglePasswordCommand = new Command(TogglePassword); TogglePasswordCommand = new Command(TogglePassword);
@ -52,6 +54,12 @@ namespace Bit.App.Pages
public async Task SubmitAsync() public async Task SubmitAsync()
{ {
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return;
}
if(string.IsNullOrWhiteSpace(Email)) if(string.IsNullOrWhiteSpace(Email))
{ {
await Page.DisplayAlert(AppResources.AnErrorHasOccurred, await Page.DisplayAlert(AppResources.AnErrorHasOccurred,

View File

@ -173,11 +173,18 @@ namespace Bit.App.Pages
{ {
return; return;
} }
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return;
}
if(string.IsNullOrWhiteSpace(Token)) if(string.IsNullOrWhiteSpace(Token))
{ {
await _platformUtilsService.ShowDialogAsync( await _platformUtilsService.ShowDialogAsync(
string.Format(AppResources.ValidationFieldRequired, AppResources.VerificationCode), string.Format(AppResources.ValidationFieldRequired, AppResources.VerificationCode),
AppResources.AnErrorHasOccurred); AppResources.AnErrorHasOccurred);
return;
} }
if(SelectedProviderType == TwoFactorProviderType.Email || if(SelectedProviderType == TwoFactorProviderType.Email ||
SelectedProviderType == TwoFactorProviderType.Authenticator) SelectedProviderType == TwoFactorProviderType.Authenticator)
@ -233,6 +240,12 @@ namespace Bit.App.Pages
{ {
return false; return false;
} }
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return false;
}
try try
{ {
if(showLoading) if(showLoading)

View File

@ -57,6 +57,12 @@ namespace Bit.App.Pages
public async Task<bool> SubmitAsync() public async Task<bool> SubmitAsync()
{ {
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return false;
}
if(string.IsNullOrWhiteSpace(Folder.Name)) if(string.IsNullOrWhiteSpace(Folder.Name))
{ {
await Page.DisplayAlert(AppResources.AnErrorHasOccurred, await Page.DisplayAlert(AppResources.AnErrorHasOccurred,
@ -87,6 +93,12 @@ namespace Bit.App.Pages
public async Task<bool> DeleteAsync() public async Task<bool> DeleteAsync()
{ {
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return false;
}
var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.DoYouReallyWantToDelete, var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.DoYouReallyWantToDelete,
null, AppResources.Yes, AppResources.No); null, AppResources.Yes, AppResources.No);
if(!confirmed) if(!confirmed)

View File

@ -46,6 +46,12 @@ namespace Bit.App.Pages
public async Task SyncAsync() public async Task SyncAsync()
{ {
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return;
}
try try
{ {
await _deviceActionService.ShowLoadingAsync(AppResources.Syncing); await _deviceActionService.ShowLoadingAsync(AppResources.Syncing);

View File

@ -367,6 +367,12 @@ namespace Bit.App.Pages
public async Task<bool> SubmitAsync() public async Task<bool> SubmitAsync()
{ {
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return false;
}
if(string.IsNullOrWhiteSpace(Cipher.Name)) if(string.IsNullOrWhiteSpace(Cipher.Name))
{ {
await Page.DisplayAlert(AppResources.AnErrorHasOccurred, await Page.DisplayAlert(AppResources.AnErrorHasOccurred,
@ -428,6 +434,12 @@ namespace Bit.App.Pages
public async Task<bool> DeleteAsync() public async Task<bool> DeleteAsync()
{ {
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return false;
}
var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.DoYouReallyWantToDelete, var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.DoYouReallyWantToDelete,
null, AppResources.Yes, AppResources.Cancel); null, AppResources.Yes, AppResources.Cancel);
if(!confirmed) if(!confirmed)

View File

@ -83,6 +83,12 @@ namespace Bit.App.Pages
public async Task<bool> SubmitAsync() public async Task<bool> SubmitAsync()
{ {
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return false;
}
if(!_hasUpdatedKey) if(!_hasUpdatedKey)
{ {
await _platformUtilsService.ShowDialogAsync(AppResources.UpdateKey, await _platformUtilsService.ShowDialogAsync(AppResources.UpdateKey,
@ -130,6 +136,12 @@ namespace Bit.App.Pages
private async void DeleteAsync(AttachmentView attachment) private async void DeleteAsync(AttachmentView attachment)
{ {
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return;
}
var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.DoYouReallyWantToDelete, var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.DoYouReallyWantToDelete,
null, AppResources.Yes, AppResources.No); null, AppResources.Yes, AppResources.No);
if(!confirmed) if(!confirmed)

View File

@ -112,7 +112,8 @@ namespace Bit.App.Pages
if(fuzzy) if(fuzzy)
{ {
var options = new List<string> { AppResources.Yes }; var options = new List<string> { AppResources.Yes };
if(cipher.Type == CipherType.Login) if(cipher.Type == CipherType.Login &&
Xamarin.Essentials.Connectivity.NetworkAccess != Xamarin.Essentials.NetworkAccess.None)
{ {
options.Add(AppResources.YesAndSave); options.Add(AppResources.YesAndSave);
} }

View File

@ -119,7 +119,8 @@ namespace Bit.App.Pages
if(!string.IsNullOrWhiteSpace(AutofillUrl)) if(!string.IsNullOrWhiteSpace(AutofillUrl))
{ {
var options = new List<string> { AppResources.Autofill }; var options = new List<string> { AppResources.Autofill };
if(cipher.Type == CipherType.Login) if(cipher.Type == CipherType.Login &&
Xamarin.Essentials.Connectivity.NetworkAccess != Xamarin.Essentials.NetworkAccess.None)
{ {
options.Add(AppResources.AutofillAndSave); options.Add(AppResources.AutofillAndSave);
} }
@ -162,7 +163,7 @@ namespace Bit.App.Pages
} }
if(_deviceActionService.SystemMajorVersion() < 21) if(_deviceActionService.SystemMajorVersion() < 21)
{ {
// TODO await Utilities.AppHelpers.CipherListOptions(Page, cipher);
} }
else else
{ {

View File

@ -64,6 +64,12 @@ namespace Bit.App.Pages
AppResources.Ok); AppResources.Ok);
return false; return false;
} }
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return false;
}
_cipherDomain.CollectionIds = new HashSet<string>( _cipherDomain.CollectionIds = new HashSet<string>(
Collections.Where(c => c.Checked).Select(c => c.Collection.Id)); Collections.Where(c => c.Checked).Select(c => c.Collection.Id));

View File

@ -270,6 +270,12 @@ namespace Bit.App.Pages
public async Task SyncAsync() public async Task SyncAsync()
{ {
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return;
}
await _deviceActionService.ShowLoadingAsync(AppResources.Syncing); await _deviceActionService.ShowLoadingAsync(AppResources.Syncing);
await _syncService.FullSyncAsync(false); await _syncService.FullSyncAsync(false);
await _deviceActionService.HideLoadingAsync(); await _deviceActionService.HideLoadingAsync();

View File

@ -92,6 +92,12 @@ namespace Bit.App.Pages
AppResources.Ok); AppResources.Ok);
return false; return false;
} }
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return false;
}
var cipherDomain = await _cipherService.GetAsync(CipherId); var cipherDomain = await _cipherService.GetAsync(CipherId);
var cipherView = await cipherDomain.DecryptAsync(); var cipherView = await cipherDomain.DecryptAsync();

View File

@ -255,6 +255,12 @@ namespace Bit.App.Pages
public async Task<bool> DeleteAsync() public async Task<bool> DeleteAsync()
{ {
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return false;
}
var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.DoYouReallyWantToDelete, var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.DoYouReallyWantToDelete,
null, AppResources.Yes, AppResources.Cancel); null, AppResources.Yes, AppResources.Cancel);
if(!confirmed) if(!confirmed)
@ -329,6 +335,12 @@ namespace Bit.App.Pages
{ {
return; return;
} }
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return;
}
await _deviceActionService.ShowLoadingAsync(AppResources.CheckingPassword); await _deviceActionService.ShowLoadingAsync(AppResources.CheckingPassword);
var matches = await _auditService.PasswordLeakedAsync(Cipher.Login.Password); var matches = await _auditService.PasswordLeakedAsync(Cipher.Login.Password);
await _deviceActionService.HideLoadingAsync(); await _deviceActionService.HideLoadingAsync();
@ -349,6 +361,12 @@ namespace Bit.App.Pages
{ {
return; return;
} }
if(Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
{
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return;
}
if(Cipher.OrganizationId == null && !CanAccessPremium) if(Cipher.OrganizationId == null && !CanAccessPremium)
{ {
await _platformUtilsService.ShowDialogAsync(AppResources.PremiumRequired); await _platformUtilsService.ShowDialogAsync(AppResources.PremiumRequired);