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 (command == "Test")
{ {
if (!ModelState.IsValid)
return View(model);
try 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(); var client = model.Settings.CreateSmtpClient();
await client.SendMailAsync(model.Settings.From, model.TestEmail, "BTCPay test", "BTCPay test"); await client.SendMailAsync(model.Settings.From, model.TestEmail, "BTCPay test", "BTCPay test");
model.StatusMessage = "Email sent to " + model.TestEmail + ", please, verify you received it"; model.StatusMessage = "Email sent to " + model.TestEmail + ", please, verify you received it";
@@ -255,21 +261,12 @@ namespace BTCPayServer.Controllers
} }
return View(model); 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); await _SettingsRepository.UpdateSetting(model.Settings);
model.StatusMessage = "Email settings saved"; model.StatusMessage = "Email settings saved";
return View(model); return View(model);
} }
else
{
await _SettingsRepository.UpdateSetting(new EmailSettings());
model.StatusMessage = "Email settings cleared";
return View(model);
}
} }
} }
} }

View File

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

View File

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

View File

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

View File

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