Unable to get it working. introduced ConfigureDataProtectionTokenProviderOptions, no DB Configured at time of execution...
This commit is contained in:
@@ -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 "../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.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 -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/"
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ namespace SZUAbsolventenverein.Module.AdminModules.Services
|
|||||||
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username);
|
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username);
|
||||||
string body = template.Content;
|
string body = template.Content;
|
||||||
|
|
||||||
// Fields bef<EFBFBD>llen.
|
// Fields befüllen.
|
||||||
string token = await _identityUserManager.GeneratePasswordResetTokenAsync(identityuser);
|
string token = await _identityUserManager.GeneratePasswordResetTokenAsync(identityuser);
|
||||||
string url = _alias.Protocol + _alias.Name + "/reset?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
|
string url = _alias.Protocol + _alias.Name + "/reset?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using System.Linq;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using SZUAbsolventenverein.Module.AdminModules.Models;
|
using SZUAbsolventenverein.Module.AdminModules.Models;
|
||||||
using SZUAbsolventenverein.Module.AdminModules.Repository;
|
using SZUAbsolventenverein.Module.AdminModules.Repository;
|
||||||
using SZUAbsolventenverein.Module.AdminSettings.Services;
|
using SZUAbsolventenverein.Module.AdminSettings.Services;
|
||||||
|
|||||||
@@ -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<DataProtectionTokenProviderOptions>
|
||||||
|
{
|
||||||
|
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<IDbContextFactory<AdminModulesContext>>();
|
||||||
|
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.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -32,12 +32,8 @@ namespace SZUAbsolventenverein.Module.AdminModules.Startup
|
|||||||
services.AddTransient<IAdminSettingsService, ServerAdminSettingsService>();
|
services.AddTransient<IAdminSettingsService, ServerAdminSettingsService>();
|
||||||
services.AddDbContextFactory<AdminModulesContext>(opt => { }, ServiceLifetime.Transient);
|
services.AddDbContextFactory<AdminModulesContext>(opt => { }, ServiceLifetime.Transient);
|
||||||
|
|
||||||
services.Configure<DataProtectionTokenProviderOptions>(options =>
|
services.AddTransient<IConfigureOptions<DataProtectionTokenProviderOptions>,
|
||||||
{
|
ConfigureDataProtectionTokenProviderOptions>();
|
||||||
options.TokenLifespan = TimeSpan.FromHours(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
services.AddTransient<IConfigureOptions<DataProtectionTokenProviderOptions>, DataProtectionTokenOptionsConfigurator>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user