Merge pull request #4090 from sbwalker/dev

fix #4088 - redirect to login if not authenticated
This commit is contained in:
Shaun Walker 2024-04-01 12:01:04 -04:00 committed by GitHub
commit 273b4f20db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -251,10 +251,8 @@
} }
} }
if (page != null)
{
// check if user is authorized to view page // check if user is authorized to view page
if (UserSecurity.IsAuthorized(user, PermissionNames.View, page.PermissionList) && (Utilities.IsPageModuleVisible(page.EffectiveDate, page.ExpiryDate) || UserSecurity.IsAuthorized(user, PermissionNames.Edit, page.PermissionList))) if (page != null && UserSecurity.IsAuthorized(user, PermissionNames.View, page.PermissionList) && (Utilities.IsPageModuleVisible(page.EffectiveDate, page.ExpiryDate) || UserSecurity.IsAuthorized(user, PermissionNames.Edit, page.PermissionList)))
{ {
// edit mode // edit mode
if (user != null) if (user != null)
@ -313,32 +311,28 @@
} }
else else
{ {
// Need to redirect 404 as page doesnot exist in a Permission or Timeframe if (page == null)
if (route.PagePath != "404")
{ {
// redirect to 404 page // check for url mapping
NavigationManager.NavigateTo(Utilities.NavigateUrl(SiteState.Alias.Path, "404", ""));
}
}
}
else // page not found
{
// look for url mapping
var urlMapping = await UrlMappingService.GetUrlMappingAsync(site.SiteId, route.PagePath); var urlMapping = await UrlMappingService.GetUrlMappingAsync(site.SiteId, route.PagePath);
if (urlMapping != null && !string.IsNullOrEmpty(urlMapping.MappedUrl)) if (urlMapping != null && !string.IsNullOrEmpty(urlMapping.MappedUrl))
{ {
var url = (urlMapping.MappedUrl.StartsWith("http")) ? urlMapping.MappedUrl : route.SiteUrl + "/" + urlMapping.MappedUrl + route.Query; var url = (urlMapping.MappedUrl.StartsWith("http")) ? urlMapping.MappedUrl : route.SiteUrl + "/" + urlMapping.MappedUrl + route.Query;
NavigationManager.NavigateTo(url, false); NavigationManager.NavigateTo(url, false);
return;
} }
else // not mapped }
else
{ {
if (user == null) if (user == null)
{ {
// redirect to login page if user not logged in as they may need to be authenticated // 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=" + WebUtility.UrlEncode(route.PathAndQuery))); NavigationManager.NavigateTo(Utilities.NavigateUrl(SiteState.Alias.Path, "login", "?returnurl=" + WebUtility.UrlEncode(route.PathAndQuery)));
return;
} }
else }
{
// page not found or user does not have sufficient access
if (route.PagePath != "404") if (route.PagePath != "404")
{ {
// redirect to 404 page // redirect to 404 page
@ -351,8 +345,6 @@
} }
} }
} }
}
}
else else
{ {
// site does not exist // site does not exist