diff --git a/src/App/Pages/Accounts/EnvironmentPage.xaml b/src/App/Pages/Accounts/EnvironmentPage.xaml
index 5a7abb783..cabf07ed7 100644
--- a/src/App/Pages/Accounts/EnvironmentPage.xaml
+++ b/src/App/Pages/Accounts/EnvironmentPage.xaml
@@ -14,7 +14,7 @@
-
+
diff --git a/src/App/Pages/Accounts/EnvironmentPage.xaml.cs b/src/App/Pages/Accounts/EnvironmentPage.xaml.cs
index b57d2f440..baa2dd1c0 100644
--- a/src/App/Pages/Accounts/EnvironmentPage.xaml.cs
+++ b/src/App/Pages/Accounts/EnvironmentPage.xaml.cs
@@ -36,14 +36,6 @@ namespace Bit.App.Pages
};
}
- private async void Submit_Clicked(object sender, EventArgs e)
- {
- if (DoOnce())
- {
- await _vm.SubmitAsync();
- }
- }
-
private async Task SubmitSuccessAsync()
{
_platformUtilsService.ShowToast("success", null, AppResources.EnvironmentSaved);
diff --git a/src/App/Pages/Accounts/EnvironmentPageViewModel.cs b/src/App/Pages/Accounts/EnvironmentPageViewModel.cs
index b25113c41..07ce99a45 100644
--- a/src/App/Pages/Accounts/EnvironmentPageViewModel.cs
+++ b/src/App/Pages/Accounts/EnvironmentPageViewModel.cs
@@ -1,15 +1,17 @@
using System;
using System.Threading.Tasks;
+using System.Windows.Input;
using Bit.App.Resources;
using Bit.Core.Abstractions;
using Bit.Core.Utilities;
-using Xamarin.Forms;
+using Xamarin.CommunityToolkit.ObjectModel;
namespace Bit.App.Pages
{
public class EnvironmentPageViewModel : BaseViewModel
{
private readonly IEnvironmentService _environmentService;
+ readonly LazyResolve _logger = new LazyResolve("logger");
public EnvironmentPageViewModel()
{
@@ -22,10 +24,10 @@ namespace Bit.App.Pages
IdentityUrl = _environmentService.IdentityUrl;
IconsUrl = _environmentService.IconsUrl;
NotificationsUrls = _environmentService.NotificationsUrl;
- SubmitCommand = new Command(async () => await SubmitAsync());
+ SubmitCommand = new AsyncCommand(SubmitAsync, onException: ex => OnSubmitException(ex), allowsMultipleExecutions: false);
}
- public Command SubmitCommand { get; }
+ public ICommand SubmitCommand { get; }
public string BaseUrl { get; set; }
public string ApiUrl { get; set; }
public string IdentityUrl { get; set; }
@@ -37,6 +39,12 @@ namespace Bit.App.Pages
public async Task SubmitAsync()
{
+ if (!ValidateUrls())
+ {
+ await Page.DisplayAlert(AppResources.AnErrorHasOccurred, AppResources.EnvironmentPageUrlsError, AppResources.Ok);
+ return;
+ }
+
var resUrls = await _environmentService.SetUrlsAsync(new Core.Models.Data.EnvironmentUrlData
{
Base = BaseUrl,
@@ -57,5 +65,25 @@ namespace Bit.App.Pages
SubmitSuccessAction?.Invoke();
}
+
+ public bool ValidateUrls()
+ {
+ bool IsUrlValid(string url)
+ {
+ return string.IsNullOrEmpty(url) || Uri.IsWellFormedUriString(url, UriKind.Absolute);
+ }
+
+ return IsUrlValid(BaseUrl)
+ && IsUrlValid(ApiUrl)
+ && IsUrlValid(IdentityUrl)
+ && IsUrlValid(WebVaultUrl)
+ && IsUrlValid(IconsUrl);
+ }
+
+ private void OnSubmitException(Exception ex)
+ {
+ _logger.Value.Exception(ex);
+ Page.DisplayAlert(AppResources.AnErrorHasOccurred, AppResources.GenericErrorMessage, AppResources.Ok);
+ }
}
}
diff --git a/src/App/Resources/AppResources.Designer.cs b/src/App/Resources/AppResources.Designer.cs
index e25fcdcdb..09f2c3f98 100644
--- a/src/App/Resources/AppResources.Designer.cs
+++ b/src/App/Resources/AppResources.Designer.cs
@@ -1,4 +1,4 @@
-//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
@@ -4044,5 +4044,17 @@ namespace Bit.App.Resources {
return ResourceManager.GetString("NeverLockWarning", resourceCulture);
}
}
+
+ public static string EnvironmentPageUrlsError {
+ get {
+ return ResourceManager.GetString("EnvironmentPageUrlsError", resourceCulture);
+ }
+ }
+
+ public static string GenericErrorMessage {
+ get {
+ return ResourceManager.GetString("GenericErrorMessage", resourceCulture);
+ }
+ }
}
}
diff --git a/src/App/Resources/AppResources.resx b/src/App/Resources/AppResources.resx
index a04488167..58cc1f7c9 100644
--- a/src/App/Resources/AppResources.resx
+++ b/src/App/Resources/AppResources.resx
@@ -1,4 +1,4 @@
-
+