mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 14:04:26 +01:00
Unify StatusMessage handling
This commit is contained in:
@@ -212,7 +212,6 @@ namespace BTCPayServer.Tests
|
|||||||
}));
|
}));
|
||||||
var statusMessageModel = controller.TempData.GetStatusMessageModel();
|
var statusMessageModel = controller.TempData.GetStatusMessageModel();
|
||||||
Assert.NotNull(statusMessageModel);
|
Assert.NotNull(statusMessageModel);
|
||||||
Assert.True(tmpLinkGenerate.RouteValues.ContainsKey("StatusMessage"));
|
|
||||||
Assert.Equal(StatusMessageModel.StatusSeverity.Success, statusMessageModel.Severity);
|
Assert.Equal(StatusMessageModel.StatusSeverity.Success, statusMessageModel.Severity);
|
||||||
var index = statusMessageModel.Html.IndexOf("target='_blank'>");
|
var index = statusMessageModel.Html.IndexOf("target='_blank'>");
|
||||||
var url = statusMessageModel.Html.Substring(index).ReplaceMultiple(new Dictionary<string, string>()
|
var url = statusMessageModel.Html.Substring(index).ReplaceMultiple(new Dictionary<string, string>()
|
||||||
|
|||||||
@@ -2883,42 +2883,6 @@ noninventoryitem:
|
|||||||
Assert.True(settings.AccountDerivation is DirectDerivationStrategy s3 && s3.Segwit);
|
Assert.True(settings.AccountDerivation is DirectDerivationStrategy s3 && s3.Segwit);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact(Timeout = TestTimeout)]
|
|
||||||
[Trait("Fast", "Fast")]
|
|
||||||
public void CheckParseStatusMessageModel()
|
|
||||||
{
|
|
||||||
var legacyStatus = "Error: some bad shit happened";
|
|
||||||
var parsed = new StatusMessageModel(legacyStatus);
|
|
||||||
Assert.Equal(legacyStatus, parsed.Message);
|
|
||||||
Assert.Equal(StatusMessageModel.StatusSeverity.Error, parsed.Severity);
|
|
||||||
|
|
||||||
var legacyStatus2 = "Some normal shit happened";
|
|
||||||
parsed = new StatusMessageModel(legacyStatus2);
|
|
||||||
Assert.Equal(legacyStatus2, parsed.Message);
|
|
||||||
Assert.Equal(StatusMessageModel.StatusSeverity.Success, parsed.Severity);
|
|
||||||
|
|
||||||
var newStatus = new StatusMessageModel()
|
|
||||||
{
|
|
||||||
Html = "<a href='xxx'>something new</a>",
|
|
||||||
Severity = StatusMessageModel.StatusSeverity.Info
|
|
||||||
};
|
|
||||||
parsed = new StatusMessageModel(newStatus.ToString());
|
|
||||||
Assert.Null(parsed.Message);
|
|
||||||
Assert.Equal(newStatus.Html, parsed.Html);
|
|
||||||
Assert.Equal(StatusMessageModel.StatusSeverity.Info, parsed.Severity);
|
|
||||||
|
|
||||||
var newStatus2 = new StatusMessageModel()
|
|
||||||
{
|
|
||||||
Message = "something new",
|
|
||||||
Severity = StatusMessageModel.StatusSeverity.Success
|
|
||||||
};
|
|
||||||
parsed = new StatusMessageModel(newStatus2.ToString());
|
|
||||||
Assert.Null(parsed.Html);
|
|
||||||
Assert.Equal(newStatus2.Message, parsed.Message);
|
|
||||||
Assert.Equal(StatusMessageModel.StatusSeverity.Success, parsed.Severity);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(Timeout = TestTimeout)]
|
[Fact(Timeout = TestTimeout)]
|
||||||
[Trait("Integration", "Integration")]
|
[Trait("Integration", "Integration")]
|
||||||
public async Task CanCreateInvoiceWithSpecificPaymentMethods()
|
public async Task CanCreateInvoiceWithSpecificPaymentMethods()
|
||||||
|
|||||||
@@ -9,9 +9,8 @@ namespace BTCPayServer.Controllers
|
|||||||
public partial class ManageController
|
public partial class ManageController
|
||||||
{
|
{
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> U2FAuthentication(string statusMessage = null)
|
public async Task<IActionResult> U2FAuthentication()
|
||||||
{
|
{
|
||||||
TempData[WellKnownTempData.SuccessMessage] = statusMessage;
|
|
||||||
return View(new U2FAuthenticationViewModel()
|
return View(new U2FAuthenticationViewModel()
|
||||||
{
|
{
|
||||||
Devices = await _u2FService.GetDevices(_userManager.GetUserId(User))
|
Devices = await _u2FService.GetDevices(_userManager.GetUserId(User))
|
||||||
@@ -33,14 +32,12 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
if (!_btcPayServerEnvironment.IsSecure)
|
if (!_btcPayServerEnvironment.IsSecure)
|
||||||
{
|
{
|
||||||
return RedirectToAction("U2FAuthentication", new
|
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||||
{
|
{
|
||||||
StatusMessage = new StatusMessageModel()
|
Severity = StatusMessageModel.StatusSeverity.Error,
|
||||||
{
|
Message = "Cannot register U2F device while not on https or tor"
|
||||||
Severity = StatusMessageModel.StatusSeverity.Error,
|
|
||||||
Message = "Cannot register U2F device while not on https or tor"
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
return RedirectToAction("U2FAuthentication");
|
||||||
}
|
}
|
||||||
|
|
||||||
var serverRegisterResponse = _u2FService.StartDeviceRegistration(_userManager.GetUserId(User),
|
var serverRegisterResponse = _u2FService.StartDeviceRegistration(_userManager.GetUserId(User),
|
||||||
@@ -64,11 +61,8 @@ namespace BTCPayServer.Controllers
|
|||||||
if (await _u2FService.CompleteRegistration(_userManager.GetUserId(User), viewModel.DeviceResponse,
|
if (await _u2FService.CompleteRegistration(_userManager.GetUserId(User), viewModel.DeviceResponse,
|
||||||
string.IsNullOrEmpty(viewModel.Name) ? "Unlabelled U2F Device" : viewModel.Name))
|
string.IsNullOrEmpty(viewModel.Name) ? "Unlabelled U2F Device" : viewModel.Name))
|
||||||
{
|
{
|
||||||
return RedirectToAction("U2FAuthentication", new
|
TempData[WellKnownTempData.SuccessMessage] = "Device added!";
|
||||||
|
return RedirectToAction("U2FAuthentication");
|
||||||
{
|
|
||||||
StatusMessage = "Device added!"
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -76,14 +70,12 @@ namespace BTCPayServer.Controllers
|
|||||||
errorMessage = e.Message;
|
errorMessage = e.Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RedirectToAction("U2FAuthentication", new
|
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||||
{
|
{
|
||||||
StatusMessage = new StatusMessageModel()
|
Severity = StatusMessageModel.StatusSeverity.Error,
|
||||||
{
|
Message = string.IsNullOrEmpty(errorMessage) ? "Could not add device." : errorMessage
|
||||||
Severity = StatusMessageModel.StatusSeverity.Error,
|
|
||||||
Message = string.IsNullOrEmpty(errorMessage) ? "Could not add device." : errorMessage
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
return RedirectToAction("U2FAuthentication");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,8 @@ namespace BTCPayServer.Controllers
|
|||||||
public partial class ServerController
|
public partial class ServerController
|
||||||
{
|
{
|
||||||
[HttpGet("server/files/{fileId?}")]
|
[HttpGet("server/files/{fileId?}")]
|
||||||
public async Task<IActionResult> Files(string fileId = null, string statusMessage = null)
|
public async Task<IActionResult> Files(string fileId = null)
|
||||||
{
|
{
|
||||||
TempData[WellKnownTempData.SuccessMessage] = statusMessage;
|
|
||||||
var fileUrl = string.IsNullOrEmpty(fileId) ? null : await _FileService.GetFileUrl(Request.GetAbsoluteRootUri(), fileId);
|
var fileUrl = string.IsNullOrEmpty(fileId) ? null : await _FileService.GetFileUrl(Request.GetAbsoluteRootUri(), fileId);
|
||||||
|
|
||||||
return View(new ViewFilesViewModel()
|
return View(new ViewFilesViewModel()
|
||||||
@@ -54,14 +53,12 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
return RedirectToAction(nameof(Files), new
|
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||||
{
|
{
|
||||||
statusMessage = new StatusMessageModel()
|
Severity = StatusMessageModel.StatusSeverity.Error,
|
||||||
{
|
Message = e.Message
|
||||||
Severity = StatusMessageModel.StatusSeverity.Error,
|
|
||||||
Message = e.Message
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
return RedirectToAction(nameof(Files));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,16 +116,14 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
var url = await _FileService.GetTemporaryFileUrl(Request.GetAbsoluteRootUri(), fileId, expiry, viewModel.IsDownload);
|
var url = await _FileService.GetTemporaryFileUrl(Request.GetAbsoluteRootUri(), fileId, expiry, viewModel.IsDownload);
|
||||||
|
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||||
|
{
|
||||||
|
Severity = StatusMessageModel.StatusSeverity.Success,
|
||||||
|
Html = $"Generated Temporary Url for file {file.FileName} which expires at {expiry.ToBrowserDate()}. <a href='{url}' target='_blank'>{url}</a>"
|
||||||
|
});
|
||||||
return RedirectToAction(nameof(Files), new
|
return RedirectToAction(nameof(Files), new
|
||||||
{
|
{
|
||||||
StatusMessage = new StatusMessageModel()
|
fileId
|
||||||
{
|
|
||||||
Severity = StatusMessageModel.StatusSeverity.Success,
|
|
||||||
Html =
|
|
||||||
$"Generated Temporary Url for file {file.FileName} which expires at {expiry.ToBrowserDate()}. <a href='{url}' target='_blank'>{url}</a>"
|
|
||||||
}.ToString(),
|
|
||||||
fileId,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -165,9 +160,8 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("server/storage")]
|
[HttpGet("server/storage")]
|
||||||
public async Task<IActionResult> Storage(bool forceChoice = false, string statusMessage = null)
|
public async Task<IActionResult> Storage(bool forceChoice = false)
|
||||||
{
|
{
|
||||||
TempData[WellKnownTempData.SuccessMessage] = statusMessage;
|
|
||||||
var savedSettings = await _SettingsRepository.GetSettingAsync<StorageSettings>();
|
var savedSettings = await _SettingsRepository.GetSettingAsync<StorageSettings>();
|
||||||
if (forceChoice || savedSettings == null)
|
if (forceChoice || savedSettings == null)
|
||||||
{
|
{
|
||||||
@@ -198,14 +192,12 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
if (!Enum.TryParse(typeof(StorageProvider), provider, out var storageProvider))
|
if (!Enum.TryParse(typeof(StorageProvider), provider, out var storageProvider))
|
||||||
{
|
{
|
||||||
return RedirectToAction(nameof(Storage), new
|
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||||
{
|
{
|
||||||
StatusMessage = new StatusMessageModel()
|
Severity = StatusMessageModel.StatusSeverity.Error,
|
||||||
{
|
Message = $"{provider} provider is not supported"
|
||||||
Severity = StatusMessageModel.StatusSeverity.Error,
|
|
||||||
Message = $"{provider} provider is not supported"
|
|
||||||
}.ToString()
|
|
||||||
});
|
});
|
||||||
|
return RedirectToAction(nameof(Storage));
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = (await _SettingsRepository.GetSettingAsync<StorageSettings>()) ?? new StorageSettings();
|
var data = (await _SettingsRepository.GetSettingAsync<StorageSettings>()) ?? new StorageSettings();
|
||||||
@@ -216,14 +208,12 @@ namespace BTCPayServer.Controllers
|
|||||||
switch (storageProviderService)
|
switch (storageProviderService)
|
||||||
{
|
{
|
||||||
case null:
|
case null:
|
||||||
return RedirectToAction(nameof(Storage), new
|
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||||
{
|
{
|
||||||
StatusMessage = new StatusMessageModel()
|
Severity = StatusMessageModel.StatusSeverity.Error,
|
||||||
{
|
Message = $"{storageProvider} is not supported"
|
||||||
Severity = StatusMessageModel.StatusSeverity.Error,
|
|
||||||
Message = $"{storageProvider} is not supported"
|
|
||||||
}.ToString()
|
|
||||||
});
|
});
|
||||||
|
return RedirectToAction(nameof(Storage));
|
||||||
case AzureBlobStorageFileProviderService fileProviderService:
|
case AzureBlobStorageFileProviderService fileProviderService:
|
||||||
return View(nameof(EditAzureBlobStorageStorageProvider),
|
return View(nameof(EditAzureBlobStorageStorageProvider),
|
||||||
fileProviderService.GetProviderConfiguration(data));
|
fileProviderService.GetProviderConfiguration(data));
|
||||||
|
|||||||
@@ -217,6 +217,11 @@ namespace BTCPayServer
|
|||||||
|
|
||||||
public static void SetStatusMessageModel(this ITempDataDictionary tempData, StatusMessageModel statusMessage)
|
public static void SetStatusMessageModel(this ITempDataDictionary tempData, StatusMessageModel statusMessage)
|
||||||
{
|
{
|
||||||
|
if (statusMessage == null)
|
||||||
|
{
|
||||||
|
tempData.Remove("StatusMessageModel");
|
||||||
|
return;
|
||||||
|
}
|
||||||
tempData["StatusMessageModel"] = JObject.FromObject(statusMessage).ToString(Formatting.None);
|
tempData["StatusMessageModel"] = JObject.FromObject(statusMessage).ToString(Formatting.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,32 +10,6 @@ namespace BTCPayServer.Models
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public StatusMessageModel(string s)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(s))
|
|
||||||
return;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (s.StartsWith("{", StringComparison.InvariantCultureIgnoreCase) &&
|
|
||||||
s.EndsWith("}", StringComparison.InvariantCultureIgnoreCase))
|
|
||||||
{
|
|
||||||
var model = JObject.Parse(s).ToObject<StatusMessageModel>();
|
|
||||||
Html = model.Html;
|
|
||||||
Message = model.Message;
|
|
||||||
Severity = model.Severity;
|
|
||||||
AllowDismiss = model.AllowDismiss;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ParseNonJsonStatus(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
ParseNonJsonStatus(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Message { get; set; }
|
public string Message { get; set; }
|
||||||
public string Html { get; set; }
|
public string Html { get; set; }
|
||||||
public StatusSeverity Severity { get; set; }
|
public StatusSeverity Severity { get; set; }
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace BTCPayServer.Services.Altcoins.Monero.UI
|
|||||||
public StoreData StoreData => HttpContext.GetStoreData();
|
public StoreData StoreData => HttpContext.GetStoreData();
|
||||||
|
|
||||||
[HttpGet()]
|
[HttpGet()]
|
||||||
public async Task<IActionResult> GetStoreMoneroLikePaymentMethods(string statusMessage)
|
public async Task<IActionResult> GetStoreMoneroLikePaymentMethods()
|
||||||
{
|
{
|
||||||
var monero = StoreData.GetSupportedPaymentMethods(_BtcPayNetworkProvider)
|
var monero = StoreData.GetSupportedPaymentMethods(_BtcPayNetworkProvider)
|
||||||
.OfType<MoneroSupportedPaymentMethod>();
|
.OfType<MoneroSupportedPaymentMethod>();
|
||||||
@@ -59,7 +59,6 @@ namespace BTCPayServer.Services.Altcoins.Monero.UI
|
|||||||
pair => GetAccounts(pair.Key));
|
pair => GetAccounts(pair.Key));
|
||||||
|
|
||||||
await Task.WhenAll(accountsList.Values);
|
await Task.WhenAll(accountsList.Values);
|
||||||
TempData[WellKnownTempData.SuccessMessage] = statusMessage;
|
|
||||||
return View(new MoneroLikePaymentMethodListViewModel()
|
return View(new MoneroLikePaymentMethodListViewModel()
|
||||||
{
|
{
|
||||||
Items = _MoneroLikeConfiguration.MoneroLikeConfigurationItems.Select(pair =>
|
Items = _MoneroLikeConfiguration.MoneroLikeConfigurationItems.Select(pair =>
|
||||||
@@ -109,7 +108,7 @@ namespace BTCPayServer.Services.Altcoins.Monero.UI
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{cryptoCode}")]
|
[HttpGet("{cryptoCode}")]
|
||||||
public async Task<IActionResult> GetStoreMoneroLikePaymentMethod(string cryptoCode, string statusMessage = null)
|
public async Task<IActionResult> GetStoreMoneroLikePaymentMethod(string cryptoCode)
|
||||||
{
|
{
|
||||||
cryptoCode = cryptoCode.ToUpperInvariant();
|
cryptoCode = cryptoCode.ToUpperInvariant();
|
||||||
if (!_MoneroLikeConfiguration.MoneroLikeConfigurationItems.ContainsKey(cryptoCode))
|
if (!_MoneroLikeConfiguration.MoneroLikeConfigurationItems.ContainsKey(cryptoCode))
|
||||||
@@ -120,7 +119,6 @@ namespace BTCPayServer.Services.Altcoins.Monero.UI
|
|||||||
var vm = GetMoneroLikePaymentMethodViewModel(StoreData.GetSupportedPaymentMethods(_BtcPayNetworkProvider)
|
var vm = GetMoneroLikePaymentMethodViewModel(StoreData.GetSupportedPaymentMethods(_BtcPayNetworkProvider)
|
||||||
.OfType<MoneroSupportedPaymentMethod>(), cryptoCode,
|
.OfType<MoneroSupportedPaymentMethod>(), cryptoCode,
|
||||||
StoreData.GetStoreBlob().GetExcludedPaymentMethods(), await GetAccounts(cryptoCode));
|
StoreData.GetStoreBlob().GetExcludedPaymentMethods(), await GetAccounts(cryptoCode));
|
||||||
TempData[WellKnownTempData.SuccessMessage] = statusMessage;
|
|
||||||
return View(nameof(GetStoreMoneroLikePaymentMethod), vm);
|
return View(nameof(GetStoreMoneroLikePaymentMethod), vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,12 +167,13 @@ namespace BTCPayServer.Services.Altcoins.Monero.UI
|
|||||||
{
|
{
|
||||||
if (summary.WalletAvailable)
|
if (summary.WalletAvailable)
|
||||||
{
|
{
|
||||||
|
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||||
|
{
|
||||||
|
Severity = StatusMessageModel.StatusSeverity.Error,
|
||||||
|
Message = $"There is already an active wallet configured for {cryptoCode}. Replacing it would break any existing invoices"
|
||||||
|
});
|
||||||
return RedirectToAction(nameof(GetStoreMoneroLikePaymentMethod),
|
return RedirectToAction(nameof(GetStoreMoneroLikePaymentMethod),
|
||||||
new {cryptoCode, StatusMessage = new StatusMessageModel()
|
new { cryptoCode });
|
||||||
{
|
|
||||||
Severity = StatusMessageModel.StatusSeverity.Error,
|
|
||||||
Message = $"There is already an active wallet configured for {cryptoCode}. Replacing it would break any existing invoices"
|
|
||||||
}.ToString()});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,13 +77,6 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
@await Html.PartialAsync("_StatusMessage",
|
|
||||||
new StatusMessageModel()
|
|
||||||
{
|
|
||||||
AllowDismiss = false,
|
|
||||||
Severity = StatusMessageModel.StatusSeverity.Warning,
|
|
||||||
Message = "The Trezor wallet import feature is still experimental and may not work as expected. Please double-check that the details were imported correctly before using in production."
|
|
||||||
}.ToString())
|
|
||||||
<p id="trezor-loading" style="display: none;">
|
<p id="trezor-loading" style="display: none;">
|
||||||
<span class="fa fa-question-circle" style="color: orange"></span> <span>Detecting Trezor hardware wallet...</span>
|
<span class="fa fa-question-circle" style="color: orange"></span> <span>Detecting Trezor hardware wallet...</span>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user