diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index 535fbe1..5fc1eb4 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -23,6 +23,7 @@ namespace CarCareTracker.Controllers private readonly IReminderRecordDataAccess _reminderRecordDataAccess; private readonly IReminderHelper _reminderHelper; private readonly ITranslationHelper _translationHelper; + private readonly IMailHelper _mailHelper; public HomeController(ILogger logger, IVehicleDataAccess dataAccess, IUserLogic userLogic, @@ -33,7 +34,8 @@ namespace CarCareTracker.Controllers IExtraFieldDataAccess extraFieldDataAccess, IReminderRecordDataAccess reminderRecordDataAccess, IReminderHelper reminderHelper, - ITranslationHelper translationHelper) + ITranslationHelper translationHelper, + IMailHelper mailHelper) { _logger = logger; _dataAccess = dataAccess; @@ -46,6 +48,7 @@ namespace CarCareTracker.Controllers _loginLogic = loginLogic; _vehicleLogic = vehicleLogic; _translationHelper = translationHelper; + _mailHelper = mailHelper; } private int GetUserID() { @@ -555,6 +558,29 @@ namespace CarCareTracker.Controllers } return Json(false); } + [Authorize(Roles = nameof(UserData.IsRootUser))] + public IActionResult GetServerConfiguration() + { + var viewModel = new ServerSettingsViewModel + { + PostgresConnection = _config.GetServerPostgresConnection(), + AllowedFileExtensions = _config.GetAllowedFileUploadExtensions(), + CustomLogoURL = _config.GetLogoUrl(), + MessageOfTheDay = _config.GetMOTD(), + WebHookURL = _config.GetWebHookUrl(), + CustomWidgetsEnabled = _config.GetCustomWidgetsEnabled(), + InvariantAPIEnabled = _config.GetInvariantApi(), + SMTPConfig = _config.GetMailConfig(), + OIDCConfig = _config.GetOpenIDConfig() + }; + return PartialView("_ServerConfig", viewModel); + } + [Authorize(Roles = nameof(UserData.IsRootUser))] + public IActionResult SendTestEmail(string emailAddress) + { + var result = _mailHelper.SendTestEmail(emailAddress); + return Json(result); + } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/Helper/MailHelper.cs b/Helper/MailHelper.cs index 75fb3fd..00e6fa0 100644 --- a/Helper/MailHelper.cs +++ b/Helper/MailHelper.cs @@ -11,6 +11,7 @@ namespace CarCareTracker.Helper OperationResponse NotifyUserForPasswordReset(string emailAddress, string token); OperationResponse NotifyUserForAccountUpdate(string emailAddress, string token); OperationResponse NotifyUserForReminders(Vehicle vehicle, List emailAddresses, List reminders); + OperationResponse SendTestEmail(string emailAddress); } public class MailHelper : IMailHelper { @@ -74,6 +75,28 @@ namespace CarCareTracker.Helper return OperationResponse.Failed(); } } + public OperationResponse SendTestEmail(string emailAddress) + { + if (string.IsNullOrWhiteSpace(mailConfig.EmailServer)) + { + return OperationResponse.Failed("SMTP Server Not Setup"); + } + if (string.IsNullOrWhiteSpace(emailAddress)) + { + return OperationResponse.Failed("Email Address or Token is invalid"); + } + string emailSubject = _translator.Translate(serverLanguage, "Test Email from LubeLogger"); + string emailBody = _translator.Translate(serverLanguage, "If you are seeing this email it means your SMTP configuration is functioning correctly"); + var result = SendEmail(new List { emailAddress }, emailSubject, emailBody); + if (result) + { + return OperationResponse.Succeed("Email Sent!"); + } + else + { + return OperationResponse.Failed(); + } + } public OperationResponse NotifyUserForAccountUpdate(string emailAddress, string token) { if (string.IsNullOrWhiteSpace(mailConfig.EmailServer)) diff --git a/Models/Settings/ServerSettingsViewModel.cs b/Models/Settings/ServerSettingsViewModel.cs new file mode 100644 index 0000000..1b4e286 --- /dev/null +++ b/Models/Settings/ServerSettingsViewModel.cs @@ -0,0 +1,17 @@ +namespace CarCareTracker.Models +{ + public class ServerSettingsViewModel + { + public string LocaleInfo { get; set; } + public string PostgresConnection { get; set; } + public string AllowedFileExtensions { get; set; } + public string CustomLogoURL { get; set; } + public string MessageOfTheDay { get; set; } + public string WebHookURL { get; set; } + public bool CustomWidgetsEnabled { get; set; } + public bool InvariantAPIEnabled { get; set; } + public MailConfig SMTPConfig { get; set; } = new MailConfig(); + public OpenIDConfig OIDCConfig { get; set; } = new OpenIDConfig(); + + } +} diff --git a/Views/Home/_ServerConfig.cshtml b/Views/Home/_ServerConfig.cshtml new file mode 100644 index 0000000..a422cb9 --- /dev/null +++ b/Views/Home/_ServerConfig.cshtml @@ -0,0 +1,219 @@ +@using CarCareTracker.Helper +@inject IConfigHelper config +@inject ITranslationHelper translator +@model ServerSettingsViewModel +@{ + var userConfig = config.GetUserConfig(User); + var userLanguage = userConfig.UserLanguage; +} + + \ No newline at end of file diff --git a/Views/Home/_Settings.cshtml b/Views/Home/_Settings.cshtml index 2240d2c..af6ef30 100644 --- a/Views/Home/_Settings.cshtml +++ b/Views/Home/_Settings.cshtml @@ -253,7 +253,14 @@
- @translator.Translate(userLanguage, "Server-wide Settings") +
+
+ @translator.Translate(userLanguage, "Server-wide Settings") +
+
+ +
+
@@ -355,6 +362,12 @@
+