Bulk: Commit: AdminSettings Module
Saving to DB is done, Reading from DB to UI is done. Loading at startup is still missing...
This commit is contained in:
@@ -13,13 +13,11 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<Microsoft.AspNetCore.Components.Forms.InputNumber @bind-Value="_AdminSetting.TokenLifeTimeInDays" />
|
||||
<button class="btn btn-primary" onclick="Save">Save</button>
|
||||
<Microsoft.AspNetCore.Components.Forms.InputNumber @bind-Value="_AdminSetting.TokenLifetime" />
|
||||
<button class="btn btn-primary" type="button" @onclick="Save">Save</button>
|
||||
}
|
||||
|
||||
@code {
|
||||
public override string RenderMode => RenderModes.Static;
|
||||
|
||||
public override List<Resource> Resources => new List<Resource>()
|
||||
{
|
||||
new Stylesheet("_content/SZUAbsolventenverein.Module.AdminModules/Module.css"),
|
||||
@@ -41,11 +39,14 @@ else
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task Save()
|
||||
private async Task Save()
|
||||
{
|
||||
Console.WriteLine("Saving!!!!");
|
||||
try
|
||||
{
|
||||
AddModuleMessage("Saved", MessageType.Success);
|
||||
await AdminSettingsService.SetAdminSettingsAsync(_AdminSetting);
|
||||
AddModuleMessage("Saved", MessageType.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,9 @@ namespace SZUAbsolventenverein.Module.AdminModules.Migrations
|
||||
massMailingTemplateEntityBuilder.Create();
|
||||
var adminSettingsEntityBuilder = new AdminSettingsEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
adminSettingsEntityBuilder.Create();
|
||||
|
||||
// Eine AdminSettings Zeile erstellen, damit die Werte nachher bearbeitet werden k<>nnen.
|
||||
migrationBuilder.Sql("INSERT INTO SZUAbsolventenvereinAdminSettings VALUES (1, 1, 'host', time('now'), 'host', time('now'))");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
|
||||
@@ -6,22 +6,39 @@ using Oqtane.Modules;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.AdminModules.Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// Repository to manage admin settings in the database.
|
||||
/// </summary>
|
||||
public interface IAdminSettingsRepository
|
||||
{
|
||||
Models.AdminSetting GetAdminSetting(int AdminModuleId);
|
||||
/// <summary>
|
||||
/// Retrieves the administrative settings entry from the Database.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="Models.AdminSetting"/> object containing the settings for the specified module. Returns <see
|
||||
/// langword="null"/> if the module is not found.</returns>
|
||||
Models.AdminSetting GetAdminSetting();
|
||||
|
||||
/// <summary>
|
||||
/// Updates the administrative settings with the specified values.
|
||||
/// </summary>
|
||||
/// <param name="adminSetting">The new administrative settings to apply. Cannot be null.</param>
|
||||
/// <returns>The updated <see cref="Models.AdminSetting"/> object reflecting the applied changes.</returns>
|
||||
Models.AdminSetting SetAdminSettings(Models.AdminSetting adminSetting);
|
||||
}
|
||||
|
||||
public class AdminSettingRepository : IAdminSettingsRepository, ITransientService
|
||||
/// <summary>
|
||||
/// Implementation of the <see cref="IAdminSettingsRepository"/> interface for managing admin settings in the database.
|
||||
/// </summary>
|
||||
public class AdminSettingsRepository : IAdminSettingsRepository, ITransientService
|
||||
{
|
||||
private readonly IDbContextFactory<AdminModulesContext> _factory;
|
||||
|
||||
public AdminSettingRepository(IDbContextFactory<AdminModulesContext> factory)
|
||||
public AdminSettingsRepository(IDbContextFactory<AdminModulesContext> factory)
|
||||
{
|
||||
_factory = factory;
|
||||
}
|
||||
|
||||
public AdminSetting GetAdminSetting(int AdminModuleId)
|
||||
public AdminSetting GetAdminSetting()
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
return db.AdminSettings.First();
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace SZUAbsolventenverein.Module.AdminModules.Services
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
|
||||
{
|
||||
return Task.FromResult(_AdminSettingsRepository.GetAdminSetting(ModuleId));
|
||||
return Task.FromResult(_AdminSettingsRepository.GetAdminSetting());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -63,6 +63,7 @@ namespace SZUAbsolventenverein.Module.AdminModules.Services
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, 1, PermissionNames.View))
|
||||
{
|
||||
_logger.Log(LogLevel.Critical, this, LogFunction.Update, "Set AdminSettings");
|
||||
return Task.FromResult(_AdminSettingsRepository.SetAdminSettings(AdminSettings));
|
||||
}
|
||||
else
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Models;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Repository;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.AdminModules.Server.Startup
|
||||
{
|
||||
public class DataProtectionTokenOptionsConfigurator : IConfigureOptions<DataProtectionTokenProviderOptions>
|
||||
{
|
||||
private readonly IAdminSettingsRepository _repo;
|
||||
|
||||
public DataProtectionTokenOptionsConfigurator(IAdminSettingsRepository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
public void Configure(DataProtectionTokenProviderOptions options)
|
||||
{
|
||||
// default fallback
|
||||
options.TokenLifespan = TimeSpan.FromHours(2);
|
||||
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Setting DPTPO: ");
|
||||
AdminSetting settings = _repo.GetAdminSetting();
|
||||
Console.WriteLine("Setting DPTPO: " + settings);
|
||||
if (settings != null && settings.TokenLifetime > 0)
|
||||
{
|
||||
Console.WriteLine("Setting DPTPO: " + settings.TokenLifetime);
|
||||
options.TokenLifespan = TimeSpan.FromDays(settings.TokenLifetime);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// DB not ready / read failed — keep default
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Oqtane.Infrastructure;
|
||||
using System;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Models;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Repository;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Server.Startup;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Services;
|
||||
using SZUAbsolventenverein.Module.AdminSettings.Services;
|
||||
|
||||
@@ -24,14 +28,16 @@ namespace SZUAbsolventenverein.Module.AdminModules.Startup
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.Configure<DataProtectionTokenProviderOptions>(options =>
|
||||
{
|
||||
options.TokenLifespan = TimeSpan.FromDays(14);
|
||||
});
|
||||
|
||||
services.AddTransient<IAdminModulesService, ServerAdminModulesService>();
|
||||
services.AddTransient<IAdminSettingsService, ServerAdminSettingsService>();
|
||||
services.AddDbContextFactory<AdminModulesContext>(opt => { }, ServiceLifetime.Transient);
|
||||
|
||||
services.Configure<DataProtectionTokenProviderOptions>(options =>
|
||||
{
|
||||
options.TokenLifespan = TimeSpan.FromHours(2);
|
||||
});
|
||||
|
||||
services.AddTransient<IConfigureOptions<DataProtectionTokenProviderOptions>, DataProtectionTokenOptionsConfigurator>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace SZUAbsolventenverein.Module.AdminModules.Models
|
||||
{
|
||||
[Key]
|
||||
public int AdminSettingsId { get; set; }
|
||||
[NotMapped]
|
||||
public int ModuleId { get; set; }
|
||||
public int TokenLifeTimeInDays { get; set; }
|
||||
public int TokenLifetime { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user