require environment variable to be injected for security reasons.

This commit is contained in:
DESKTOP-T0O5CDB\DESK-555BD
2024-11-04 11:57:27 -07:00
parent 5cdc687f6d
commit c1b361397f
3 changed files with 29 additions and 8 deletions

View File

@@ -526,24 +526,36 @@ namespace CarCareTracker.Controllers
[Authorize(Roles = nameof(UserData.IsRootUser))]
[HttpGet]
public IActionResult GetCustomWidgetEditor()
{
if (_config.GetCustomWidgetsEnabled())
{
var customWidgetData = _fileHelper.GetWidgets();
return PartialView("_WidgetEditor", customWidgetData);
}
return Json(string.Empty);
}
[Authorize(Roles = nameof(UserData.IsRootUser))]
[HttpPost]
public IActionResult SaveCustomWidgets(string widgetsData)
{
if (_config.GetCustomWidgetsEnabled())
{
var saveResult = _fileHelper.SaveWidgets(widgetsData);
return Json(saveResult);
}
return Json(false);
}
[Authorize(Roles = nameof(UserData.IsRootUser))]
[HttpPost]
public IActionResult DeleteCustomWidgets()
{
if (_config.GetCustomWidgetsEnabled())
{
var deleteResult = _fileHelper.DeleteWidgets();
return Json(deleteResult);
}
return Json(false);
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{

View File

@@ -14,6 +14,7 @@ namespace CarCareTracker.Helper
bool AuthenticateRootUser(string username, string password);
bool AuthenticateRootUserOIDC(string email);
string GetWebHookUrl();
bool GetCustomWidgetsEnabled();
string GetMOTD();
string GetLogoUrl();
string GetServerLanguage();
@@ -45,6 +46,10 @@ namespace CarCareTracker.Helper
}
return webhook;
}
public bool GetCustomWidgetsEnabled()
{
return bool.Parse(_config["LUBELOGGER_CUSTOM_WIDGETS"] ?? "false");
}
public string GetMOTD()
{
var motd = _config["LUBELOGGER_MOTD"];

View File

@@ -401,8 +401,12 @@ function showCustomWidgets() {
}).then(function (result) {
if (result.isConfirmed) {
$.get('/Home/GetCustomWidgetEditor', function (data) {
if (data.trim() != '') {
$("#customWidgetModalContent").html(data);
$("#customWidgetModal").modal('show');
} else {
errorToast("Custom Widgets Not Enabled");
}
});
}
});