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 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<CrowdfundSettings>();
var vm = new UpdateCrowdfundViewModel()
{
NotificationEmailWarning = await ShowEmailWarningForStore(app.StoreDataId),
Title = settings.Title,
Enabled = settings.Enabled,
EnforceTargetAmount = settings.EnforceTargetAmount,

View File

@ -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<PointOfSaleSettings>();
var vm = new UpdatePointOfSaleViewModel()
{
NotificationEmailWarning = await ShowEmailWarningForStore(app.StoreDataId),
Id = appId,
Title = settings.Title,
EnableShoppingCart = settings.EnableShoppingCart,

View File

@ -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<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; }
[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; }
}
}

View File

@ -79,5 +79,7 @@ namespace BTCPayServer.Models.AppViewModels
Value = ""
}
}, 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>
</div>
<div class="form-group">
<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>
</div>
<div class="form-group">
@ -199,6 +204,8 @@
<input asp-for="DisqusShortname" class="form-control" />
<span asp-validation-for="DisqusShortname" class="text-danger"></span>
</div>
<input type="hidden" asp-for="NotificationEmailWarning"/>
<div class="form-group">
<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>

View File

@ -115,7 +115,11 @@
</div>
<div class="form-group">
<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>
</div>
<div class="form-group">
@ -123,6 +127,7 @@
<select asp-for="RedirectAutomatically" asp-items="Model.RedirectAutomaticallySelectList" class="form-control"></select>
<span asp-validation-for="RedirectAutomatically" class="text-danger"></span>
</div>
<input type="hidden" asp-for="NotificationEmailWarning"/>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Save Settings" />
</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>