diff --git a/Package/debug.sh b/Package/debug.sh index 058d474..24935e9 100644 --- a/Package/debug.sh +++ b/Package/debug.sh @@ -9,4 +9,4 @@ cp -f "../Server/bin/Debug/$TargetFramework/$ProjectName.Server.Oqtane.dll" "../ cp -f "../Server/bin/Debug/$TargetFramework/$ProjectName.Server.Oqtane.pdb" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/" cp -f "../Shared/bin/Debug/$TargetFramework/$ProjectName.Shared.Oqtane.dll" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/" cp -f "../Shared/bin/Debug/$TargetFramework/$ProjectName.Shared.Oqtane.pdb" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/" -cp -rf "../Server/wwwroot/"* "../../oqtane.framework/Oqtane.Server/wwwroot/_content/$ProjectName/" +cp -rf "../Server/wwwroot/"* "../../oqtane.framework/Oqtane.Server/wwwroot/" diff --git a/Server/Services/AdminModulesService.cs b/Server/Services/AdminModulesService.cs index 9e4f7d5..82820d8 100644 --- a/Server/Services/AdminModulesService.cs +++ b/Server/Services/AdminModulesService.cs @@ -169,7 +169,7 @@ namespace SZUAbsolventenverein.Module.AdminModules.Services IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username); string body = template.Content; - // Fields befüllen. + // Fields befüllen. string token = await _identityUserManager.GeneratePasswordResetTokenAsync(identityuser); string url = _alias.Protocol + _alias.Name + "/reset?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token); diff --git a/Server/Services/AdminSettingsService.cs b/Server/Services/AdminSettingsService.cs index e7bb81a..427162f 100644 --- a/Server/Services/AdminSettingsService.cs +++ b/Server/Services/AdminSettingsService.cs @@ -13,6 +13,7 @@ using System.Linq; using System.Net; using System.Reflection; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using SZUAbsolventenverein.Module.AdminModules.Models; using SZUAbsolventenverein.Module.AdminModules.Repository; using SZUAbsolventenverein.Module.AdminSettings.Services; diff --git a/Server/Startup/ConfigureDataProtectionTokenProviderOptions.cs b/Server/Startup/ConfigureDataProtectionTokenProviderOptions.cs new file mode 100644 index 0000000..49f4494 --- /dev/null +++ b/Server/Startup/ConfigureDataProtectionTokenProviderOptions.cs @@ -0,0 +1,50 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; +using System; +using System.Linq; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using SZUAbsolventenverein.Module.AdminModules.Models; +using SZUAbsolventenverein.Module.AdminModules.Repository; + +namespace SZUAbsolventenverein.Module.AdminModules.Server.Startup +{ + public class ConfigureDataProtectionTokenProviderOptions : IConfigureOptions + { + private readonly IServiceProvider _serviceProvider; + + public ConfigureDataProtectionTokenProviderOptions(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + Console.WriteLine("Instatiating DPTPO Configurator"); + } + + public void Configure(DataProtectionTokenProviderOptions options) + { + Console.WriteLine("Configuring DPTPO"); + // default fallback + options.TokenLifespan = TimeSpan.FromHours(2); + + try + { + using var scope = _serviceProvider.CreateScope(); + var _dbContextFactory = scope.ServiceProvider.GetRequiredService>(); + var _ctx = _dbContextFactory.CreateDbContext(); + AdminSetting adminSetting = _ctx.AdminSettings.First(); + + Console.WriteLine("Setting DPTPO: " + adminSetting); + if (adminSetting != null) + { + Console.WriteLine("Setting DPTPO: " + adminSetting.TokenLifetime); + options.TokenLifespan = TimeSpan.FromDays(adminSetting.TokenLifetime); + } + } + catch (Exception ex) + { + Console.WriteLine("DB Not ready, using default DPTPO: " + ex); + // DB not ready / read failed — keep default + // Unable to get Create DB Context because Oqtane's Database Setup is incomplete. + } + } + } +} diff --git a/Server/Startup/DataProtectionTokenProviderOptionsConfigurator.cs b/Server/Startup/DataProtectionTokenProviderOptionsConfigurator.cs deleted file mode 100644 index 6fc651e..0000000 --- a/Server/Startup/DataProtectionTokenProviderOptionsConfigurator.cs +++ /dev/null @@ -1,44 +0,0 @@ -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 - { - 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 - } - } - } -} diff --git a/Server/Startup/ServerStartup.cs b/Server/Startup/ServerStartup.cs index 0e69864..280df1c 100644 --- a/Server/Startup/ServerStartup.cs +++ b/Server/Startup/ServerStartup.cs @@ -31,13 +31,9 @@ namespace SZUAbsolventenverein.Module.AdminModules.Startup services.AddTransient(); services.AddTransient(); services.AddDbContextFactory(opt => { }, ServiceLifetime.Transient); - - services.Configure(options => - { - options.TokenLifespan = TimeSpan.FromHours(2); - }); - - services.AddTransient, DataProtectionTokenOptionsConfigurator>(); + + services.AddTransient, + ConfigureDataProtectionTokenProviderOptions>(); } } }