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
This commit is contained in:
Andrew Camilleri
2019-04-28 08:27:10 +02:00
committed by Nicolas Dorier
parent 6df83ad148
commit fcb1de8a86
8 changed files with 37 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ using System.Text.Encodings.Web;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Models.AppViewModels; using BTCPayServer.Models.AppViewModels;
using BTCPayServer.Services.Apps; using BTCPayServer.Services.Apps;
using BTCPayServer.Services.Mails;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.Controllers namespace BTCPayServer.Controllers
@@ -33,6 +34,7 @@ namespace BTCPayServer.Controllers
var settings = app.GetSettings<CrowdfundSettings>(); var settings = app.GetSettings<CrowdfundSettings>();
var vm = new UpdateCrowdfundViewModel() var vm = new UpdateCrowdfundViewModel()
{ {
NotificationEmailWarning = await ShowEmailWarningForStore(app.StoreDataId),
Title = settings.Title, Title = settings.Title,
Enabled = settings.Enabled, Enabled = settings.Enabled,
EnforceTargetAmount = settings.EnforceTargetAmount, EnforceTargetAmount = settings.EnforceTargetAmount,

View File

@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Models.AppViewModels; using BTCPayServer.Models.AppViewModels;
using BTCPayServer.Services.Apps; using BTCPayServer.Services.Apps;
using BTCPayServer.Services.Mails;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@@ -90,8 +91,10 @@ namespace BTCPayServer.Controllers
if (app == null) if (app == null)
return NotFound(); return NotFound();
var settings = app.GetSettings<PointOfSaleSettings>(); var settings = app.GetSettings<PointOfSaleSettings>();
var vm = new UpdatePointOfSaleViewModel() var vm = new UpdatePointOfSaleViewModel()
{ {
NotificationEmailWarning = await ShowEmailWarningForStore(app.StoreDataId),
Id = appId, Id = appId,
Title = settings.Title, Title = settings.Title,
EnableShoppingCart = settings.EnableShoppingCart, EnableShoppingCart = settings.EnableShoppingCart,

View File

@@ -7,6 +7,7 @@ using BTCPayServer.Models;
using BTCPayServer.Models.AppViewModels; using BTCPayServer.Models.AppViewModels;
using BTCPayServer.Security; using BTCPayServer.Security;
using BTCPayServer.Services.Apps; using BTCPayServer.Services.Apps;
using BTCPayServer.Services.Mails;
using BTCPayServer.Services.Rates; using BTCPayServer.Services.Rates;
using Ganss.XSS; using Ganss.XSS;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@@ -30,6 +31,7 @@ namespace BTCPayServer.Controllers
BTCPayNetworkProvider networkProvider, BTCPayNetworkProvider networkProvider,
CurrencyNameTable currencies, CurrencyNameTable currencies,
HtmlSanitizer htmlSanitizer, HtmlSanitizer htmlSanitizer,
EmailSenderFactory emailSenderFactory,
AppService AppService) AppService AppService)
{ {
_UserManager = userManager; _UserManager = userManager;
@@ -38,6 +40,7 @@ namespace BTCPayServer.Controllers
_NetworkProvider = networkProvider; _NetworkProvider = networkProvider;
_currencies = currencies; _currencies = currencies;
_htmlSanitizer = htmlSanitizer; _htmlSanitizer = htmlSanitizer;
_emailSenderFactory = emailSenderFactory;
_AppService = AppService; _AppService = AppService;
} }
@@ -47,6 +50,7 @@ namespace BTCPayServer.Controllers
private BTCPayNetworkProvider _NetworkProvider; private BTCPayNetworkProvider _NetworkProvider;
private readonly CurrencyNameTable _currencies; private readonly CurrencyNameTable _currencies;
private readonly HtmlSanitizer _htmlSanitizer; private readonly HtmlSanitizer _htmlSanitizer;
private readonly EmailSenderFactory _emailSenderFactory;
private AppService _AppService; private AppService _AppService;
[TempData] [TempData]
@@ -176,5 +180,10 @@ namespace BTCPayServer.Controllers
{ {
return _UserManager.GetUserId(User); return _UserManager.GetUserId(User);
} }
private async Task<bool> ShowEmailWarningForStore(string storeId)
{
return !((await (_emailSenderFactory.GetEmailSender(storeId) as EmailSender)?.GetEmailSettings())?.IsComplete() is true);
}
} }
} }

View File

@@ -92,5 +92,7 @@ namespace BTCPayServer.Models.AppViewModels
public string Sounds{ get; set; } 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.")] [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 string AnimationColors{ get; set; }
public bool NotificationEmailWarning { get; set; }
} }
} }

View File

@@ -79,5 +79,7 @@ namespace BTCPayServer.Models.AppViewModels
Value = "" Value = ""
} }
}, nameof(SelectListItem.Value), nameof(SelectListItem.Text), RedirectAutomatically); }, nameof(SelectListItem.Value), nameof(SelectListItem.Text), RedirectAutomatically);
public bool NotificationEmailWarning { get; set; }
} }
} }

View File

@@ -138,8 +138,13 @@
<span asp-validation-for="NotificationUrl" class="text-danger"></span> <span asp-validation-for="NotificationUrl" class="text-danger"></span>
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="NotificationEmail" class="control-label"></label> <label asp-for="NotificationEmail" class="control-label"></label>
<input type="email" asp-for="NotificationEmail" class="form-control" /> @if (Model.NotificationEmailWarning)
{
<partial name="NotificationEmailWarning"></partial>
}
<input type="email" asp-for="NotificationEmail" class="form-control"/>
<span asp-validation-for="NotificationEmail" class="text-danger"></span> <span asp-validation-for="NotificationEmail" class="text-danger"></span>
</div> </div>
<div class="form-group"> <div class="form-group">
@@ -199,6 +204,8 @@
<input asp-for="DisqusShortname" class="form-control" /> <input asp-for="DisqusShortname" class="form-control" />
<span asp-validation-for="DisqusShortname" class="text-danger"></span> <span asp-validation-for="DisqusShortname" class="text-danger"></span>
</div> </div>
<input type="hidden" asp-for="NotificationEmailWarning"/>
<div class="form-group"> <div class="form-group">
<input type="submit" class="btn btn-primary" value="Save Settings" /> <input type="submit" class="btn btn-primary" value="Save Settings" />
<a class="btn btn-secondary" target="_blank" asp-action="ListInvoices" asp-controller="Invoice" asp-route-searchterm="@Model.SearchTerm">Invoices</a> <a class="btn btn-secondary" target="_blank" asp-action="ListInvoices" asp-controller="Invoice" asp-route-searchterm="@Model.SearchTerm">Invoices</a>

View File

@@ -115,7 +115,11 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="NotificationEmail" class="control-label"></label> <label asp-for="NotificationEmail" class="control-label"></label>
<input type="email" asp-for="NotificationEmail" class="form-control" /> @if (Model.NotificationEmailWarning)
{
<partial name="NotificationEmailWarning"></partial>
}
<input type="email" asp-for="NotificationEmail" class="form-control"/>
<span asp-validation-for="NotificationEmail" class="text-danger"></span> <span asp-validation-for="NotificationEmail" class="text-danger"></span>
</div> </div>
<div class="form-group"> <div class="form-group">
@@ -123,6 +127,7 @@
<select asp-for="RedirectAutomatically" asp-items="Model.RedirectAutomaticallySelectList" class="form-control"></select> <select asp-for="RedirectAutomatically" asp-items="Model.RedirectAutomaticallySelectList" class="form-control"></select>
<span asp-validation-for="RedirectAutomatically" class="text-danger"></span> <span asp-validation-for="RedirectAutomatically" class="text-danger"></span>
</div> </div>
<input type="hidden" asp-for="NotificationEmailWarning"/>
<div class="form-group"> <div class="form-group">
<input type="submit" class="btn btn-primary" value="Save Settings" /> <input type="submit" class="btn btn-primary" value="Save Settings" />
</div> </div>

View File

@@ -0,0 +1,5 @@
<div class="alert alert-warning alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>The Email settings have not been configured on this server or store yet. Setting this field will not send emails until then. <a asp-action="Emails" asp-controller="Stores">Configure store email settings</a>
</div>