2017-09-16 01:15:17 +09:00
|
|
|
|
using BTCPayServer.Models;
|
|
|
|
|
using BTCPayServer.Models.ServerViewModels;
|
2017-09-27 14:18:09 +09:00
|
|
|
|
using BTCPayServer.Services;
|
|
|
|
|
using BTCPayServer.Services.Mails;
|
|
|
|
|
using BTCPayServer.Validations;
|
2017-09-16 01:20:57 +09:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2017-09-16 01:15:17 +09:00
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-09-27 14:18:09 +09:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2017-09-16 01:15:17 +09:00
|
|
|
|
using System.Linq;
|
2017-09-27 14:18:09 +09:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Mail;
|
2017-09-16 01:15:17 +09:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Controllers
|
|
|
|
|
{
|
2017-09-27 14:18:09 +09:00
|
|
|
|
[Authorize(Roles = Roles.ServerAdmin)]
|
2017-09-16 01:15:17 +09:00
|
|
|
|
public class ServerController : Controller
|
|
|
|
|
{
|
|
|
|
|
private UserManager<ApplicationUser> _UserManager;
|
2017-09-27 14:18:09 +09:00
|
|
|
|
SettingsRepository _SettingsRepository;
|
2017-09-16 01:15:17 +09:00
|
|
|
|
|
2017-09-27 14:18:09 +09:00
|
|
|
|
public ServerController(UserManager<ApplicationUser> userManager, SettingsRepository settingsRepository)
|
2017-09-16 01:15:17 +09:00
|
|
|
|
{
|
|
|
|
|
_UserManager = userManager;
|
2017-09-27 14:18:09 +09:00
|
|
|
|
_SettingsRepository = settingsRepository;
|
2017-09-16 01:15:17 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("server/users")]
|
|
|
|
|
public IActionResult ListUsers()
|
|
|
|
|
{
|
|
|
|
|
var users = new UsersViewModel();
|
|
|
|
|
users.Users
|
|
|
|
|
= _UserManager.Users.Select(u => new UsersViewModel.UserViewModel()
|
|
|
|
|
{
|
|
|
|
|
Name = u.UserName,
|
|
|
|
|
Email = u.Email
|
|
|
|
|
}).ToList();
|
|
|
|
|
return View(users);
|
|
|
|
|
}
|
2017-09-27 14:18:09 +09:00
|
|
|
|
|
|
|
|
|
[Route("server/emails")]
|
|
|
|
|
public async Task<IActionResult> Emails()
|
|
|
|
|
{
|
|
|
|
|
var data = (await _SettingsRepository.GetSettingAsync<EmailSettings>()) ?? new EmailSettings();
|
|
|
|
|
return View(new EmailsViewModel() { Settings = data });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("server/policies")]
|
|
|
|
|
public async Task<IActionResult> Policies()
|
|
|
|
|
{
|
|
|
|
|
var data = (await _SettingsRepository.GetSettingAsync<PoliciesSettings>()) ?? new PoliciesSettings();
|
|
|
|
|
return View(data);
|
|
|
|
|
}
|
|
|
|
|
[Route("server/policies")]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> Policies(PoliciesSettings settings)
|
|
|
|
|
{
|
|
|
|
|
await _SettingsRepository.UpdateSetting(settings);
|
|
|
|
|
TempData["StatusMessage"] = "Policies upadated successfully";
|
|
|
|
|
return View(settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("server/emails")]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> Emails(EmailsViewModel model, string command)
|
|
|
|
|
{
|
|
|
|
|
if(command == "Test")
|
|
|
|
|
{
|
|
|
|
|
if(!ModelState.IsValid)
|
|
|
|
|
return View(model);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
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";
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
model.StatusMessage = "Error: " + ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ModelState.Remove(nameof(model.TestEmail));
|
|
|
|
|
if(!ModelState.IsValid)
|
|
|
|
|
return View(model);
|
|
|
|
|
await _SettingsRepository.UpdateSetting(model.Settings);
|
|
|
|
|
model.StatusMessage = "Email settings saved";
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-16 01:15:17 +09:00
|
|
|
|
}
|
|
|
|
|
}
|