fixes for client-side Blazor
This commit is contained in:
parent
155c4e12d9
commit
2436f74830
|
@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Components;
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
|
using Oqtane.Providers;
|
||||||
|
|
||||||
namespace Oqtane.Services
|
namespace Oqtane.Services
|
||||||
{
|
{
|
||||||
|
@ -15,12 +16,14 @@ namespace Oqtane.Services
|
||||||
private readonly HttpClient _http;
|
private readonly HttpClient _http;
|
||||||
private readonly SiteState _siteState;
|
private readonly SiteState _siteState;
|
||||||
private readonly NavigationManager _navigationManager;
|
private readonly NavigationManager _navigationManager;
|
||||||
|
private readonly IServiceProvider _serviceProvider;
|
||||||
|
|
||||||
public ModuleDefinitionService(HttpClient http, SiteState siteState, NavigationManager navigationManager)
|
public ModuleDefinitionService(HttpClient http, SiteState siteState, NavigationManager navigationManager, IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
_http = http;
|
_http = http;
|
||||||
_siteState = siteState;
|
_siteState = siteState;
|
||||||
_navigationManager = navigationManager;
|
_navigationManager = navigationManager;
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string apiurl
|
private string apiurl
|
||||||
|
@ -55,6 +58,10 @@ namespace Oqtane.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task LoadModuleDefinitionsAsync(int SiteId)
|
public async Task LoadModuleDefinitionsAsync(int SiteId)
|
||||||
|
{
|
||||||
|
// download assemblies to browser when running client-side Blazor
|
||||||
|
var authstateprovider = (IdentityAuthenticationStateProvider)_serviceProvider.GetService(typeof(IdentityAuthenticationStateProvider));
|
||||||
|
if (authstateprovider != null)
|
||||||
{
|
{
|
||||||
// get list of modules from the server
|
// get list of modules from the server
|
||||||
List<ModuleDefinition> moduledefinitions = await GetModuleDefinitionsAsync(SiteId);
|
List<ModuleDefinition> moduledefinitions = await GetModuleDefinitionsAsync(SiteId);
|
||||||
|
@ -88,4 +95,5 @@ namespace Oqtane.Services
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
{
|
{
|
||||||
// client-side Blazor
|
// client-side Blazor
|
||||||
authstateprovider.NotifyAuthenticationChanged();
|
authstateprovider.NotifyAuthenticationChanged();
|
||||||
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "logout"));
|
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,8 +75,9 @@
|
||||||
int moduleid = -1;
|
int moduleid = -1;
|
||||||
string action = "";
|
string action = "";
|
||||||
bool editmode = false;
|
bool editmode = false;
|
||||||
|
int userid = -1;
|
||||||
Reload reload = Reload.None;
|
Reload reload = Reload.None;
|
||||||
DateTime lastsyncdate = DateTime.Now;
|
DateTime lastsyncdate = DateTime.UtcNow;
|
||||||
|
|
||||||
// get Url path and querystring ( and remove anchors )
|
// get Url path and querystring ( and remove anchors )
|
||||||
string path = new Uri(_absoluteUri).PathAndQuery.Substring(1);
|
string path = new Uri(_absoluteUri).PathAndQuery.Substring(1);
|
||||||
|
@ -97,7 +98,10 @@
|
||||||
{
|
{
|
||||||
editmode = PageState.EditMode;
|
editmode = PageState.EditMode;
|
||||||
lastsyncdate = PageState.LastSyncDate;
|
lastsyncdate = PageState.LastSyncDate;
|
||||||
user = PageState.User;
|
if (PageState.User != null)
|
||||||
|
{
|
||||||
|
userid = PageState.User.UserId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
alias = await AliasService.GetAliasAsync(_absoluteUri, lastsyncdate);
|
alias = await AliasService.GetAliasAsync(_absoluteUri, lastsyncdate);
|
||||||
|
@ -114,6 +118,17 @@
|
||||||
}
|
}
|
||||||
if (site != null)
|
if (site != null)
|
||||||
{
|
{
|
||||||
|
// get user
|
||||||
|
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||||
|
if (authState.User.Identity.IsAuthenticated)
|
||||||
|
{
|
||||||
|
user = await UserService.GetUserAsync(authState.User.Identity.Name, site.SiteId);
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
userid = user.UserId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// process sync events
|
// process sync events
|
||||||
if (alias.SyncEvents.Any())
|
if (alias.SyncEvents.Any())
|
||||||
{
|
{
|
||||||
|
@ -125,7 +140,7 @@
|
||||||
{
|
{
|
||||||
reload = Reload.Site;
|
reload = Reload.Site;
|
||||||
}
|
}
|
||||||
if (user != null && alias.SyncEvents.Exists(item => item.EntityName == "User" && item.EntityId == user.UserId))
|
if (alias.SyncEvents.Exists(item => item.EntityName == "User" && item.EntityId == userid))
|
||||||
{
|
{
|
||||||
reload = Reload.Site;
|
reload = Reload.Site;
|
||||||
}
|
}
|
||||||
|
@ -133,15 +148,7 @@
|
||||||
|
|
||||||
if (PageState == null || reload >= Reload.Site)
|
if (PageState == null || reload >= Reload.Site)
|
||||||
{
|
{
|
||||||
#if WASM
|
await ModuleDefinitionService.LoadModuleDefinitionsAsync(site.SiteId);
|
||||||
ModuleDefinitionService.LoadModuleDefinitionsAsync(site.SiteId); // download assemblies to browser when running client-side
|
|
||||||
#endif
|
|
||||||
|
|
||||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
|
||||||
if (authState.User.Identity.IsAuthenticated)
|
|
||||||
{
|
|
||||||
user = await UserService.GetUserAsync(authState.User.Identity.Name, site.SiteId);
|
|
||||||
}
|
|
||||||
pages = await PageService.GetPagesAsync(site.SiteId);
|
pages = await PageService.GetPagesAsync(site.SiteId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -205,20 +212,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
user = null;
|
|
||||||
if (PageState == null || reload >= Reload.Page)
|
|
||||||
{
|
|
||||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
|
||||||
if (authState.User.Identity.IsAuthenticated)
|
|
||||||
{
|
|
||||||
user = await UserService.GetUserAsync(authState.User.Identity.Name, site.SiteId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
user = PageState.User;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (page != null)
|
if (page != null)
|
||||||
{
|
{
|
||||||
if (PageState == null)
|
if (PageState == null)
|
||||||
|
|
|
@ -62,7 +62,7 @@ namespace Oqtane.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
// get sync events
|
// get sync events
|
||||||
alias.SyncDate = DateTime.Now;
|
alias.SyncDate = DateTime.UtcNow;
|
||||||
alias.SyncEvents = _syncManager.GetSyncEvents(DateTime.ParseExact(lastsyncdate, "yyyyMMddHHmmssfff", CultureInfo.InvariantCulture));
|
alias.SyncEvents = _syncManager.GetSyncEvents(DateTime.ParseExact(lastsyncdate, "yyyyMMddHHmmssfff", CultureInfo.InvariantCulture));
|
||||||
|
|
||||||
return alias;
|
return alias;
|
||||||
|
|
|
@ -243,7 +243,7 @@ namespace Oqtane.Controllers
|
||||||
user.LastLoginOn = DateTime.Now;
|
user.LastLoginOn = DateTime.Now;
|
||||||
user.LastIPAddress = HttpContext.Connection.RemoteIpAddress.ToString();
|
user.LastIPAddress = HttpContext.Connection.RemoteIpAddress.ToString();
|
||||||
_users.UpdateUser(user);
|
_users.UpdateUser(user);
|
||||||
_syncManager.AddSyncEvent("User", User.UserId);
|
_syncManager.AddSyncEvent("User", user.UserId);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Login Successful {Username}", User.Username);
|
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Login Successful {Username}", User.Username);
|
||||||
if (SetCookie)
|
if (SetCookie)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,9 +36,9 @@ namespace Oqtane.Infrastructure
|
||||||
|
|
||||||
public void AddSyncEvent(string EntityName, int EntityId)
|
public void AddSyncEvent(string EntityName, int EntityId)
|
||||||
{
|
{
|
||||||
SyncEvents.Add(new SyncEvent { TenantId = TenantId, EntityName = EntityName, EntityId = EntityId, ModifiedOn = DateTime.Now });
|
SyncEvents.Add(new SyncEvent { TenantId = TenantId, EntityName = EntityName, EntityId = EntityId, ModifiedOn = DateTime.UtcNow });
|
||||||
// trim sync events
|
// trim sync events
|
||||||
SyncEvents.RemoveAll(item => item.ModifiedOn < DateTime.Now.AddHours(-1));
|
SyncEvents.RemoveAll(item => item.ModifiedOn < DateTime.UtcNow.AddHours(-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,6 +313,7 @@ namespace Oqtane.Server
|
||||||
// register singleton scoped core services
|
// register singleton scoped core services
|
||||||
services.AddSingleton<IConfigurationRoot>(Configuration);
|
services.AddSingleton<IConfigurationRoot>(Configuration);
|
||||||
services.AddSingleton<IInstallationManager, InstallationManager>();
|
services.AddSingleton<IInstallationManager, InstallationManager>();
|
||||||
|
services.AddSingleton<ISyncManager, SyncManager>();
|
||||||
|
|
||||||
// register transient scoped core services
|
// register transient scoped core services
|
||||||
services.AddTransient<IModuleDefinitionRepository, ModuleDefinitionRepository>();
|
services.AddTransient<IModuleDefinitionRepository, ModuleDefinitionRepository>();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user