From fcb1de8a868b38e64aa33ee3e04d3a8d038adc51 Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Sun, 28 Apr 2019 08:27:10 +0200 Subject: [PATCH] Show email warning on apps when settings are not complete (#794) * Show email warning on apps when settings are not complete closes #693 * refactor email warning logic --- BTCPayServer/Controllers/AppsController.Crowdfund.cs | 2 ++ BTCPayServer/Controllers/AppsController.PointOfSale.cs | 3 +++ BTCPayServer/Controllers/AppsController.cs | 9 +++++++++ .../Models/AppViewModels/UpdateCrowdfundViewModel.cs | 2 ++ .../Models/AppViewModels/UpdatePointOfSaleViewModel.cs | 2 ++ BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml | 9 ++++++++- BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml | 7 ++++++- .../Views/Shared/NotificationEmailWarning.cshtml | 5 +++++ 8 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 BTCPayServer/Views/Shared/NotificationEmailWarning.cshtml diff --git a/BTCPayServer/Controllers/AppsController.Crowdfund.cs b/BTCPayServer/Controllers/AppsController.Crowdfund.cs index c9c9de22e..b364653f4 100644 --- a/BTCPayServer/Controllers/AppsController.Crowdfund.cs +++ b/BTCPayServer/Controllers/AppsController.Crowdfund.cs @@ -5,6 +5,7 @@ using System.Text.Encodings.Web; using System.Threading.Tasks; using BTCPayServer.Models.AppViewModels; using BTCPayServer.Services.Apps; +using BTCPayServer.Services.Mails; using Microsoft.AspNetCore.Mvc; namespace BTCPayServer.Controllers @@ -33,6 +34,7 @@ namespace BTCPayServer.Controllers var settings = app.GetSettings(); var vm = new UpdateCrowdfundViewModel() { + NotificationEmailWarning = await ShowEmailWarningForStore(app.StoreDataId), Title = settings.Title, Enabled = settings.Enabled, EnforceTargetAmount = settings.EnforceTargetAmount, diff --git a/BTCPayServer/Controllers/AppsController.PointOfSale.cs b/BTCPayServer/Controllers/AppsController.PointOfSale.cs index 2b5510142..10277f661 100644 --- a/BTCPayServer/Controllers/AppsController.PointOfSale.cs +++ b/BTCPayServer/Controllers/AppsController.PointOfSale.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using BTCPayServer.Data; using BTCPayServer.Models.AppViewModels; using BTCPayServer.Services.Apps; +using BTCPayServer.Services.Mails; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -90,8 +91,10 @@ namespace BTCPayServer.Controllers if (app == null) return NotFound(); var settings = app.GetSettings(); + var vm = new UpdatePointOfSaleViewModel() { + NotificationEmailWarning = await ShowEmailWarningForStore(app.StoreDataId), Id = appId, Title = settings.Title, EnableShoppingCart = settings.EnableShoppingCart, diff --git a/BTCPayServer/Controllers/AppsController.cs b/BTCPayServer/Controllers/AppsController.cs index a7104bb95..7c6125057 100644 --- a/BTCPayServer/Controllers/AppsController.cs +++ b/BTCPayServer/Controllers/AppsController.cs @@ -7,6 +7,7 @@ using BTCPayServer.Models; using BTCPayServer.Models.AppViewModels; using BTCPayServer.Security; using BTCPayServer.Services.Apps; +using BTCPayServer.Services.Mails; using BTCPayServer.Services.Rates; using Ganss.XSS; using Microsoft.AspNetCore.Authorization; @@ -30,6 +31,7 @@ namespace BTCPayServer.Controllers BTCPayNetworkProvider networkProvider, CurrencyNameTable currencies, HtmlSanitizer htmlSanitizer, + EmailSenderFactory emailSenderFactory, AppService AppService) { _UserManager = userManager; @@ -38,6 +40,7 @@ namespace BTCPayServer.Controllers _NetworkProvider = networkProvider; _currencies = currencies; _htmlSanitizer = htmlSanitizer; + _emailSenderFactory = emailSenderFactory; _AppService = AppService; } @@ -47,6 +50,7 @@ namespace BTCPayServer.Controllers private BTCPayNetworkProvider _NetworkProvider; private readonly CurrencyNameTable _currencies; private readonly HtmlSanitizer _htmlSanitizer; + private readonly EmailSenderFactory _emailSenderFactory; private AppService _AppService; [TempData] @@ -176,5 +180,10 @@ namespace BTCPayServer.Controllers { return _UserManager.GetUserId(User); } + + private async Task ShowEmailWarningForStore(string storeId) + { + return !((await (_emailSenderFactory.GetEmailSender(storeId) as EmailSender)?.GetEmailSettings())?.IsComplete() is true); + } } } diff --git a/BTCPayServer/Models/AppViewModels/UpdateCrowdfundViewModel.cs b/BTCPayServer/Models/AppViewModels/UpdateCrowdfundViewModel.cs index 126bd2e8b..346673ba5 100644 --- a/BTCPayServer/Models/AppViewModels/UpdateCrowdfundViewModel.cs +++ b/BTCPayServer/Models/AppViewModels/UpdateCrowdfundViewModel.cs @@ -92,5 +92,7 @@ namespace BTCPayServer.Models.AppViewModels public string Sounds{ get; set; } [Display(Name = "Colors to rotate between with animation when a payment is made. First color is the default background. One color per line. Can be any valid css color value.")] public string AnimationColors{ get; set; } + + public bool NotificationEmailWarning { get; set; } } } diff --git a/BTCPayServer/Models/AppViewModels/UpdatePointOfSaleViewModel.cs b/BTCPayServer/Models/AppViewModels/UpdatePointOfSaleViewModel.cs index 6db315ca5..378a2eefd 100644 --- a/BTCPayServer/Models/AppViewModels/UpdatePointOfSaleViewModel.cs +++ b/BTCPayServer/Models/AppViewModels/UpdatePointOfSaleViewModel.cs @@ -79,5 +79,7 @@ namespace BTCPayServer.Models.AppViewModels Value = "" } }, nameof(SelectListItem.Value), nameof(SelectListItem.Text), RedirectAutomatically); + + public bool NotificationEmailWarning { get; set; } } } diff --git a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml index c4b1ceb20..9986b3bf8 100644 --- a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml +++ b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml @@ -138,8 +138,13 @@
+ - + @if (Model.NotificationEmailWarning) + { + + } +
@@ -199,6 +204,8 @@
+ +
Invoices diff --git a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml index 82ec16d15..f69a1a20c 100644 --- a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml +++ b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml @@ -115,7 +115,11 @@
- + @if (Model.NotificationEmailWarning) + { + + } +
@@ -123,6 +127,7 @@
+
diff --git a/BTCPayServer/Views/Shared/NotificationEmailWarning.cshtml b/BTCPayServer/Views/Shared/NotificationEmailWarning.cshtml new file mode 100644 index 000000000..fa5e0cc71 --- /dev/null +++ b/BTCPayServer/Views/Shared/NotificationEmailWarning.cshtml @@ -0,0 +1,5 @@ +
+ The Email settings have not been configured on this server or store yet. Setting this field will not send emails until then. Configure store email settings +