-
+
@code {
- private string _scope = "page";
- private string _login = "-";
- private string _register = "-";
- private string _footer = "-";
+ private string resourceType = "Oqtane.Themes.OqtaneTheme.ThemeSettings, Oqtane.Client"; // for localization
+ private string _scope = "page";
+ private string _login = "-";
+ private string _register = "-";
+ private string _footer = "-";
- protected override async Task OnInitializedAsync()
- {
- try
- {
- await LoadSettings();
+ protected override async Task OnInitializedAsync()
+ {
+ try
+ {
+ await LoadSettings();
}
catch (Exception ex)
{
@@ -110,7 +111,7 @@
{
if (_scope == "site")
{
- var settings = PageState.Site.Settings;
+ var settings = await SettingService.GetSiteSettingsAsync(PageState.Site.SiteId);
if (_login != "-")
{
settings = SettingService.SetSetting(settings, GetType().Namespace + ":Login", _login, true);
@@ -127,7 +128,7 @@
}
else
{
- var settings = PageState.Page.Settings;
+ var settings = await SettingService.GetPageSettingsAsync(PageState.Page.PageId);
if (_login != "-")
{
settings = SettingService.SetSetting(settings, GetType().Namespace + ":Login", _login);
diff --git a/Oqtane.Client/Themes/ThemeBase.cs b/Oqtane.Client/Themes/ThemeBase.cs
index 2771105c..ccf80e04 100644
--- a/Oqtane.Client/Themes/ThemeBase.cs
+++ b/Oqtane.Client/Themes/ThemeBase.cs
@@ -104,14 +104,19 @@ namespace Oqtane.Themes
return Utilities.ContentUrl(PageState.Alias, fileid, asAttachment);
}
- public string ImageUrl(int fileid, int width, int height, string mode)
+ public string ImageUrl(int fileid, int width, int height)
{
- return ImageUrl(fileid, width, height, mode, 0);
+ return ImageUrl(fileid, width, height, "");
}
- public string ImageUrl(int fileid, int width, int height, string mode, int rotate)
+ public string ImageUrl(int fileid, int width, int height, string mode)
{
- return Utilities.ImageUrl(PageState.Alias, fileid, width, height, mode, rotate);
+ return ImageUrl(fileid, width, height, mode, "", "", 0, false);
+ }
+
+ public string ImageUrl(int fileid, int width, int height, string mode, string position, string background, int rotate, bool recreate)
+ {
+ return Utilities.ImageUrl(PageState.Alias, fileid, width, height, mode, position, background, rotate, recreate);
}
}
}
diff --git a/Oqtane.Client/UI/Interop.cs b/Oqtane.Client/UI/Interop.cs
index 2aa9fb9f..28b72307 100644
--- a/Oqtane.Client/UI/Interop.cs
+++ b/Oqtane.Client/UI/Interop.cs
@@ -262,5 +262,22 @@ namespace Oqtane.UI
return Task.CompletedTask;
}
}
+
+ public Task ScrollTo(int top, int left, string behavior)
+ {
+ try
+ {
+ if (string.IsNullOrEmpty(behavior)) behavior = "smooth";
+ _jsRuntime.InvokeVoidAsync(
+ "Oqtane.Interop.scrollTo",
+ top, left, behavior);
+ return Task.CompletedTask;
+ }
+ catch
+ {
+ return Task.CompletedTask;
+ }
+ }
+
}
}
diff --git a/Oqtane.Client/UI/PageState.cs b/Oqtane.Client/UI/PageState.cs
index bc0fdacf..5b14ad00 100644
--- a/Oqtane.Client/UI/PageState.cs
+++ b/Oqtane.Client/UI/PageState.cs
@@ -21,5 +21,6 @@ namespace Oqtane.UI
public DateTime LastSyncDate { get; set; }
public Oqtane.Shared.Runtime Runtime { get; set; }
public int VisitorId { get; set; }
+ public string RemoteIPAddress { get; set; }
}
}
diff --git a/Oqtane.Client/UI/SiteRouter.razor b/Oqtane.Client/UI/SiteRouter.razor
index a6a222db..360ff6a1 100644
--- a/Oqtane.Client/UI/SiteRouter.razor
+++ b/Oqtane.Client/UI/SiteRouter.razor
@@ -9,6 +9,7 @@
@inject IPageService PageService
@inject IUserService UserService
@inject IModuleService ModuleService
+@inject IUrlMappingService UrlMappingService
@inject ILogService LogService
@implements IHandleAfterRender
@@ -82,134 +83,137 @@
var action = (!string.IsNullOrEmpty(route.Action)) ? route.Action : Constants.DefaultAction;
var querystring = ParseQueryString(route.Query);
- // reload the client application if there is a forced reload or the user navigated to a site with a different alias
- if (querystring.ContainsKey("reload") || (!route.AbsolutePath.Substring(1).ToLower().StartsWith(SiteState.Alias.Path.ToLower()) && !string.IsNullOrEmpty(SiteState.Alias.Path)))
- {
- NavigationManager.NavigateTo(_absoluteUri.Replace("?reload", ""), true);
- return;
- }
- else
- {
- // the refresh parameter is used to refresh the PageState
- if (querystring.ContainsKey("refresh"))
- {
- refresh = UI.Refresh.Site;
- }
- }
+ // reload the client application if there is a forced reload or the user navigated to a site with a different alias
+ if (querystring.ContainsKey("reload") || (!route.AbsolutePath.Substring(1).ToLower().StartsWith(SiteState.Alias.Path.ToLower()) && !string.IsNullOrEmpty(SiteState.Alias.Path)))
+ {
+ NavigationManager.NavigateTo(_absoluteUri.Replace("?reload", ""), true);
+ return;
+ }
+ else
+ {
+ // the refresh parameter is used to refresh the PageState
+ if (querystring.ContainsKey("refresh"))
+ {
+ refresh = UI.Refresh.Site;
+ }
+ }
- if (PageState != null)
- {
- editmode = PageState.EditMode;
- lastsyncdate = PageState.LastSyncDate;
- }
+ if (PageState != null)
+ {
+ editmode = PageState.EditMode;
+ lastsyncdate = PageState.LastSyncDate;
+ }
- // process any sync events
- var sync = await SyncService.GetSyncAsync(lastsyncdate);
- lastsyncdate = sync.SyncDate;
- if (sync.SyncEvents.Any())
- {
- // reload client application if server was restarted or site runtime/rendermode was modified
- if (PageState != null && sync.SyncEvents.Exists(item => (item.TenantId == -1 || item.EntityName == EntityNames.Site && item.EntityId == SiteState.Alias.SiteId) && item.Reload))
- {
- NavigationManager.NavigateTo(_absoluteUri, true);
- return;
- }
- if (sync.SyncEvents.Exists(item => item.EntityName == EntityNames.Site && item.EntityId == SiteState.Alias.SiteId))
- {
- refresh = UI.Refresh.Site;
- }
- }
+ // process any sync events
+ var sync = await SyncService.GetSyncAsync(lastsyncdate);
+ lastsyncdate = sync.SyncDate;
+ if (sync.SyncEvents.Any())
+ {
+ // reload client application if server was restarted or site runtime/rendermode was modified
+ if (PageState != null && sync.SyncEvents.Exists(item => (item.TenantId == -1 || item.EntityName == EntityNames.Site && item.EntityId == SiteState.Alias.SiteId) && item.Reload))
+ {
+ NavigationManager.NavigateTo(_absoluteUri, true);
+ return;
+ }
+ if (sync.SyncEvents.Exists(item => item.EntityName == EntityNames.Site && item.EntityId == SiteState.Alias.SiteId))
+ {
+ refresh = UI.Refresh.Site;
+ }
+ }
- if (refresh == UI.Refresh.Site || PageState == null || PageState.Alias.SiteId != SiteState.Alias.SiteId)
- {
- site = await SiteService.GetSiteAsync(SiteState.Alias.SiteId);
- refresh = UI.Refresh.Site;
- }
- else
- {
- site = PageState.Site;
- }
+ if (refresh == UI.Refresh.Site || PageState == null || PageState.Alias.SiteId != SiteState.Alias.SiteId)
+ {
+ site = await SiteService.GetSiteAsync(SiteState.Alias.SiteId);
+ refresh = UI.Refresh.Site;
+ }
+ else
+ {
+ site = PageState.Site;
+ }
- if (site != null)
- {
- if (PageState == null || refresh == UI.Refresh.Site)
- {
- // get user
- var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
- if (authState.User.Identity.IsAuthenticated)
- {
- user = await UserService.GetUserAsync(authState.User.Identity.Name, site.SiteId);
- user.IsAuthenticated = authState.User.Identity.IsAuthenticated;
- }
- }
- else
- {
- user = PageState.User;
- }
+ if (site != null)
+ {
+ if (PageState == null || refresh == UI.Refresh.Site)
+ {
+ // 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)
+ {
+ user.IsAuthenticated = authState.User.Identity.IsAuthenticated;
+ }
+ }
+ }
+ else
+ {
+ user = PageState.User;
+ }
- // process any sync events for user
- if (refresh != UI.Refresh.Site && user != null && sync.SyncEvents.Any())
- {
- if (sync.SyncEvents.Exists(item => item.EntityName == EntityNames.User && item.EntityId == user.UserId))
- {
- refresh = UI.Refresh.Site;
- }
- }
+ // process any sync events for user
+ if (refresh != UI.Refresh.Site && user != null && sync.SyncEvents.Any())
+ {
+ if (sync.SyncEvents.Exists(item => item.EntityName == EntityNames.User && item.EntityId == user.UserId))
+ {
+ refresh = UI.Refresh.Site;
+ }
+ }
- if (PageState == null || refresh == UI.Refresh.Site)
- {
- pages = await PageService.GetPagesAsync(site.SiteId);
- }
- else
- {
- pages = PageState.Pages;
- }
+ if (PageState == null || refresh == UI.Refresh.Site)
+ {
+ pages = await PageService.GetPagesAsync(site.SiteId);
+ }
+ else
+ {
+ pages = PageState.Pages;
+ }
- if (PageState == null || refresh == UI.Refresh.Site)
- {
- page = pages.FirstOrDefault(item => item.Path.Equals(route.PagePath, StringComparison.OrdinalIgnoreCase));
- }
- else
- {
- page = PageState.Page;
- }
+ if (PageState == null || refresh == UI.Refresh.Site)
+ {
+ page = pages.FirstOrDefault(item => item.Path.Equals(route.PagePath, StringComparison.OrdinalIgnoreCase));
+ }
+ else
+ {
+ page = PageState.Page;
+ }
- // get the page if the path has changed
- if (page == null || page.Path != route.PagePath)
- {
- page = pages.FirstOrDefault(item => item.Path.Equals(route.PagePath, StringComparison.OrdinalIgnoreCase));
+ // get the page if the path has changed
+ if (page == null || page.Path != route.PagePath)
+ {
+ page = pages.FirstOrDefault(item => item.Path.Equals(route.PagePath, StringComparison.OrdinalIgnoreCase));
// if the home page path does not exist then use the first page in the collection (a future enhancement would allow the admin to specify the home page)
if (page == null && route.PagePath == "")
{
page = pages.FirstOrDefault();
}
- editmode = false;
- }
+ editmode = false;
+ }
- if (page != null)
- {
- if (PageState == null)
- {
- editmode = false;
- }
+ if (page != null)
+ {
+ if (PageState == null)
+ {
+ editmode = false;
+ }
- // check if user is authorized to view page
- if (UserSecurity.IsAuthorized(user, PermissionNames.View, page.Permissions))
- {
- page = await ProcessPage(page, site, user);
+ // check if user is authorized to view page
+ if (UserSecurity.IsAuthorized(user, PermissionNames.View, page.Permissions))
+ {
+ page = await ProcessPage(page, site, user);
- if (PageState == null || refresh == UI.Refresh.Site)
- {
- modules = await ModuleService.GetModulesAsync(site.SiteId);
- }
- else
- {
- modules = PageState.Modules;
- }
+ if (PageState == null || refresh == UI.Refresh.Site)
+ {
+ modules = await ModuleService.GetModulesAsync(site.SiteId);
+ }
+ else
+ {
+ modules = PageState.Modules;
+ }
- (page, modules) = ProcessModules(page, modules, moduleid, action, (!string.IsNullOrEmpty(page.DefaultContainerType)) ? page.DefaultContainerType : site.DefaultContainerType);
+ (page, modules) = ProcessModules(page, modules, moduleid, action, (!string.IsNullOrEmpty(page.DefaultContainerType)) ? page.DefaultContainerType : site.DefaultContainerType);
- _pagestate = new PageState
+ _pagestate = new PageState
{
Alias = SiteState.Alias,
Site = site,
@@ -225,28 +229,39 @@
EditMode = editmode,
LastSyncDate = lastsyncdate,
Runtime = runtime,
- VisitorId = VisitorId
+ VisitorId = VisitorId,
+ RemoteIPAddress = SiteState.RemoteIPAddress
};
- OnStateChange?.Invoke(_pagestate);
- }
- }
- else
- {
- if (user == null)
- {
- // redirect to login page
- NavigationManager.NavigateTo(Utilities.NavigateUrl(SiteState.Alias.Path, "login", "?returnurl=" + route.AbsolutePath));
- }
- else
- {
- await LogService.Log(null, null, user.UserId, GetType().AssemblyQualifiedName, Utilities.GetTypeNameLastSegment(GetType().AssemblyQualifiedName, 1), LogFunction.Security, LogLevel.Error, null, "Page Does Not Exist Or User Is Not Authorized To View Page {Path}", route.PagePath);
- if (route.PagePath != "")
- {
- // redirect to home page
- NavigationManager.NavigateTo(Utilities.NavigateUrl(SiteState.Alias.Path, "", ""));
- }
- }
+ OnStateChange?.Invoke(_pagestate);
+ }
+ }
+ else // page not found
+ {
+ // look for url mapping
+ var urlMapping = await UrlMappingService.GetUrlMappingAsync(site.SiteId, route.PagePath);
+ if (urlMapping != null && !string.IsNullOrEmpty(urlMapping.MappedUrl))
+ {
+ var url = (urlMapping.MappedUrl.StartsWith("http")) ? urlMapping.MappedUrl : route.SiteUrl + "/" + urlMapping.MappedUrl;
+ NavigationManager.NavigateTo(url, false);
+ }
+ else // not mapped
+ {
+ if (user == null)
+ {
+ // redirect to login page if user not logged in as they may need to be authenticated
+ NavigationManager.NavigateTo(Utilities.NavigateUrl(SiteState.Alias.Path, "login", "?returnurl=" + route.AbsolutePath));
+ }
+ else
+ {
+ await LogService.Log(null, null, user.UserId, GetType().AssemblyQualifiedName, Utilities.GetTypeNameLastSegment(GetType().AssemblyQualifiedName, 1), LogFunction.Security, LogLevel.Error, null, "Page Does Not Exist Or User Is Not Authorized To View Page {Path}", route.PagePath);
+ if (route.PagePath != "")
+ {
+ // redirect to home page
+ NavigationManager.NavigateTo(Utilities.NavigateUrl(SiteState.Alias.Path, "", ""));
+ }
+ }
+ }
}
}
else
diff --git a/Oqtane.Client/UI/ThemeBuilder.razor b/Oqtane.Client/UI/ThemeBuilder.razor
index 0f96323e..77f95a6c 100644
--- a/Oqtane.Client/UI/ThemeBuilder.razor
+++ b/Oqtane.Client/UI/ThemeBuilder.razor
@@ -28,32 +28,29 @@
protected override async Task OnAfterRenderAsync(bool firstRender)
{
- if (!firstRender)
+ var interop = new Interop(JsRuntime);
+
+ // manage stylesheets for this page
+ string batch = DateTime.UtcNow.ToString("yyyyMMddHHmmssfff");
+ var links = new List