Fix set email screen

This commit is contained in:
nicolas.dorier 2018-05-04 15:54:12 +09:00
parent 14360bde78
commit e2533a93e3
5 changed files with 12 additions and 21 deletions

View File

@ -241,10 +241,16 @@ namespace BTCPayServer.Controllers
{
if (command == "Test")
{
if (!ModelState.IsValid)
return View(model);
try
{
if(string.IsNullOrWhiteSpace(model.Settings.From)
|| string.IsNullOrWhiteSpace(model.TestEmail)
|| string.IsNullOrWhiteSpace(model.Settings.Login)
|| string.IsNullOrWhiteSpace(model.Settings.Server))
{
model.StatusMessage = "Error: Required fields missing";
return View(model);
}
var client = model.Settings.CreateSmtpClient();
await client.SendMailAsync(model.Settings.From, model.TestEmail, "BTCPay test", "BTCPay test");
model.StatusMessage = "Email sent to " + model.TestEmail + ", please, verify you received it";
@ -255,21 +261,12 @@ namespace BTCPayServer.Controllers
}
return View(model);
}
else if(command == "Save")
else // if(command == "Save")
{
ModelState.Remove(nameof(model.TestEmail));
if (!ModelState.IsValid)
return View(model);
await _SettingsRepository.UpdateSetting(model.Settings);
model.StatusMessage = "Email settings saved";
return View(model);
}
else
{
await _SettingsRepository.UpdateSetting(new EmailSettings());
model.StatusMessage = "Email settings cleared";
return View(model);
}
}
}
}

View File

@ -19,7 +19,6 @@ namespace BTCPayServer.Models.ServerViewModels
get; set;
}
[Required]
[EmailAddress]
public string TestEmail
{

View File

@ -10,30 +10,25 @@ namespace BTCPayServer.Services.Mails
{
public class EmailSettings
{
[Required]
public string Server
{
get; set;
}
[Required]
public int? Port
{
get; set;
}
[Required]
public String Login
{
get; set;
}
[Required]
public String Password
{
get; set;
}
[EmailAddress]
public string From
{

View File

@ -53,11 +53,11 @@
<div class="form-group">
<label asp-for="TestEmail"></label>
<input asp-for="TestEmail" class="form-control" />
<span asp-validation-for="TestEmail" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary" name="command" value="Save">Save</button>
<button type="submit" class="btn btn-primary" name="command" value="Test">Test</button>
<button type="submit" class="btn btn-danger" name="command" value="Clear">Clear</button>
</form>
</div>
</div>

View File

@ -1,4 +1,4 @@
@model BTCPayServer.Models.StoreViewModels.RatesViewModel.RatesViewModel
@model BTCPayServer.Models.StoreViewModels.RatesViewModel
@{
Layout = "../Shared/_NavLayout.cshtml";
ViewData["Title"] = "Rates";