- Updated Docker configuration for production deployment - Added SilverPay integration settings - Configured for admin.thebankofdebbie.giize.com deployment - Includes all recent security fixes and improvements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
175 lines
7.5 KiB
C#
175 lines
7.5 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using LittleShop.Services;
|
|
using LittleShop.Enums;
|
|
|
|
namespace LittleShop.Areas.Admin.Controllers;
|
|
|
|
[Area("Admin")]
|
|
[Authorize(Policy = "AdminOnly")]
|
|
public class SystemSettingsController : Controller
|
|
{
|
|
private readonly ISystemSettingsService _systemSettingsService;
|
|
private readonly ISilverPayService _silverPayService;
|
|
private readonly ILogger<SystemSettingsController> _logger;
|
|
|
|
public SystemSettingsController(
|
|
ISystemSettingsService systemSettingsService,
|
|
ISilverPayService silverPayService,
|
|
ILogger<SystemSettingsController> logger)
|
|
{
|
|
_systemSettingsService = systemSettingsService;
|
|
_silverPayService = silverPayService;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task<IActionResult> Index()
|
|
{
|
|
try
|
|
{
|
|
var viewModel = new SystemSettingsViewModel
|
|
{
|
|
TestCurrencies = new Dictionary<string, bool>
|
|
{
|
|
{ "TBTC", await _systemSettingsService.IsTestCurrencyEnabledAsync("TBTC") },
|
|
{ "TLTC", await _systemSettingsService.IsTestCurrencyEnabledAsync("TLTC") }
|
|
},
|
|
SilverPaySettings = new SilverPaySettingsViewModel
|
|
{
|
|
BaseUrl = await _systemSettingsService.GetSettingAsync("SilverPay.BaseUrl") ?? "",
|
|
ApiKey = await _systemSettingsService.GetSettingAsync("SilverPay.ApiKey") ?? "",
|
|
WebhookSecret = await _systemSettingsService.GetSettingAsync("SilverPay.WebhookSecret") ?? "",
|
|
DefaultWebhookUrl = await _systemSettingsService.GetSettingAsync("SilverPay.DefaultWebhookUrl") ?? "",
|
|
LastTestDate = await _systemSettingsService.GetSettingAsync<DateTime?>("SilverPay.LastTestDate"),
|
|
LastTestSuccess = await _systemSettingsService.GetSettingAsync<bool>("SilverPay.LastTestSuccess", false),
|
|
LastTestMessage = await _systemSettingsService.GetSettingAsync("SilverPay.LastTestMessage") ?? ""
|
|
}
|
|
};
|
|
|
|
viewModel.SilverPaySettings.IsConfigured = !string.IsNullOrEmpty(viewModel.SilverPaySettings.BaseUrl);
|
|
|
|
return View(viewModel);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error loading system settings");
|
|
ViewBag.Error = "Failed to load system settings";
|
|
return View(new SystemSettingsViewModel());
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> UpdateTestCurrencies(SystemSettingsViewModel model)
|
|
{
|
|
try
|
|
{
|
|
if (model.TestCurrencies != null)
|
|
{
|
|
foreach (var currency in model.TestCurrencies)
|
|
{
|
|
await _systemSettingsService.SetTestCurrencyEnabledAsync(currency.Key, currency.Value);
|
|
_logger.LogInformation("Updated test currency {Currency} to {Enabled}", currency.Key, currency.Value);
|
|
}
|
|
}
|
|
|
|
ViewBag.Success = "Test currency settings updated successfully";
|
|
return View("Index", model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error updating test currency settings");
|
|
ViewBag.Error = "Failed to update test currency settings";
|
|
return View("Index", model);
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> UpdateSilverPaySettings(SilverPaySettingsViewModel model)
|
|
{
|
|
try
|
|
{
|
|
await _systemSettingsService.SetSettingAsync("SilverPay.BaseUrl", model.BaseUrl ?? "", "SilverPay API base URL");
|
|
await _systemSettingsService.SetSettingAsync("SilverPay.ApiKey", model.ApiKey ?? "", "SilverPay API authentication key");
|
|
await _systemSettingsService.SetSettingAsync("SilverPay.WebhookSecret", model.WebhookSecret ?? "", "SilverPay webhook validation secret");
|
|
await _systemSettingsService.SetSettingAsync("SilverPay.DefaultWebhookUrl", model.DefaultWebhookUrl ?? "", "Default webhook URL for SilverPay notifications");
|
|
|
|
_logger.LogInformation("Updated SilverPay settings");
|
|
TempData["Success"] = "SilverPay settings updated successfully";
|
|
|
|
return RedirectToAction("Index");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error updating SilverPay settings");
|
|
TempData["Error"] = "Failed to update SilverPay settings";
|
|
return RedirectToAction("Index");
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> TestSilverPayConnection()
|
|
{
|
|
try
|
|
{
|
|
var baseUrl = await _systemSettingsService.GetSettingAsync("SilverPay.BaseUrl");
|
|
|
|
if (string.IsNullOrEmpty(baseUrl))
|
|
{
|
|
TempData["Error"] = "SilverPay base URL not configured";
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
// Test the connection by getting supported currencies
|
|
var currencies = await _silverPayService.GetSupportedCurrenciesAsync();
|
|
|
|
if (currencies != null && currencies.Count > 0)
|
|
{
|
|
await _systemSettingsService.SetSettingAsync("SilverPay.LastTestDate", DateTime.UtcNow);
|
|
await _systemSettingsService.SetSettingAsync("SilverPay.LastTestSuccess", true);
|
|
await _systemSettingsService.SetSettingAsync("SilverPay.LastTestMessage",
|
|
$"Successfully connected. Supported currencies: {string.Join(", ", currencies)}");
|
|
|
|
TempData["Success"] = $"SilverPay connection successful! Supported currencies: {string.Join(", ", currencies)}";
|
|
_logger.LogInformation("SilverPay connection test successful. Currencies: {Currencies}", string.Join(", ", currencies));
|
|
}
|
|
else
|
|
{
|
|
await _systemSettingsService.SetSettingAsync("SilverPay.LastTestDate", DateTime.UtcNow);
|
|
await _systemSettingsService.SetSettingAsync("SilverPay.LastTestSuccess", false);
|
|
await _systemSettingsService.SetSettingAsync("SilverPay.LastTestMessage", "Connection established but no currencies returned");
|
|
|
|
TempData["Warning"] = "SilverPay connection established but no supported currencies returned";
|
|
_logger.LogWarning("SilverPay connection test returned no currencies");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await _systemSettingsService.SetSettingAsync("SilverPay.LastTestDate", DateTime.UtcNow);
|
|
await _systemSettingsService.SetSettingAsync("SilverPay.LastTestSuccess", false);
|
|
await _systemSettingsService.SetSettingAsync("SilverPay.LastTestMessage", ex.Message);
|
|
|
|
TempData["Error"] = $"SilverPay connection test failed: {ex.Message}";
|
|
_logger.LogError(ex, "SilverPay connection test failed");
|
|
}
|
|
|
|
return RedirectToAction("Index");
|
|
}
|
|
}
|
|
|
|
public class SystemSettingsViewModel
|
|
{
|
|
public Dictionary<string, bool> TestCurrencies { get; set; } = new();
|
|
public SilverPaySettingsViewModel SilverPaySettings { get; set; } = new();
|
|
}
|
|
|
|
public class SilverPaySettingsViewModel
|
|
{
|
|
public string BaseUrl { get; set; } = "";
|
|
public string ApiKey { get; set; } = "";
|
|
public string WebhookSecret { get; set; } = "";
|
|
public string DefaultWebhookUrl { get; set; } = "";
|
|
public bool IsConfigured { get; set; }
|
|
public DateTime? LastTestDate { get; set; }
|
|
public bool LastTestSuccess { get; set; }
|
|
public string LastTestMessage { get; set; } = "";
|
|
} |