Merge pull request #5375 from sbwalker/dev
fix #5374 Visitor Settings not returned due to change in Visitor cookie format
This commit is contained in:
@ -345,6 +345,7 @@
|
|||||||
DateTime expiry = DateTime.MinValue;
|
DateTime expiry = DateTime.MinValue;
|
||||||
if (visitorCookieValue != null && visitorCookieValue.Contains("|"))
|
if (visitorCookieValue != null && visitorCookieValue.Contains("|"))
|
||||||
{
|
{
|
||||||
|
// visitor cookies contain the visitor id and an expiry date separated by a pipe symbol
|
||||||
var values = visitorCookieValue.Split('|');
|
var values = visitorCookieValue.Split('|');
|
||||||
int.TryParse(values[0], out _visitorId);
|
int.TryParse(values[0], out _visitorId);
|
||||||
DateTime.TryParseExact(values[1], "M/d/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture, DateTimeStyles.None, out expiry);
|
DateTime.TryParseExact(values[1], "M/d/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture, DateTimeStyles.None, out expiry);
|
||||||
|
@ -70,7 +70,6 @@ namespace Oqtane.Controllers
|
|||||||
_identityOptionsMonitorCache = identityOptionsMonitorCache;
|
_identityOptionsMonitorCache = identityOptionsMonitorCache;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_alias = tenantManager.GetAlias();
|
_alias = tenantManager.GetAlias();
|
||||||
_visitorCookie = Constants.VisitorCookiePrefix + _alias.SiteId.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: api/<controller>
|
// GET: api/<controller>
|
||||||
@ -299,11 +298,8 @@ namespace Oqtane.Controllers
|
|||||||
authorized = User.IsInRole(RoleNames.Admin);
|
authorized = User.IsInRole(RoleNames.Admin);
|
||||||
if (!authorized)
|
if (!authorized)
|
||||||
{
|
{
|
||||||
// a visitor may have cookies disabled
|
var visitorCookieName = Constants.VisitorCookiePrefix + _alias.SiteId.ToString();
|
||||||
if (int.TryParse(Request.Cookies[_visitorCookie], out int visitorId))
|
authorized = (entityId == GetVisitorCookieId(Request.Cookies[visitorCookieName]));
|
||||||
{
|
|
||||||
authorized = (visitorId == entityId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: // custom entity
|
default: // custom entity
|
||||||
@ -344,11 +340,8 @@ namespace Oqtane.Controllers
|
|||||||
case EntityNames.Visitor:
|
case EntityNames.Visitor:
|
||||||
if (!User.IsInRole(RoleNames.Admin))
|
if (!User.IsInRole(RoleNames.Admin))
|
||||||
{
|
{
|
||||||
filter = true;
|
var visitorCookieName = Constants.VisitorCookiePrefix + _alias.SiteId.ToString();
|
||||||
if (int.TryParse(Request.Cookies[_visitorCookie], out int visitorId))
|
filter = (entityId != GetVisitorCookieId(Request.Cookies[visitorCookieName]));
|
||||||
{
|
|
||||||
filter = (visitorId != entityId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: // custom entity
|
default: // custom entity
|
||||||
@ -358,6 +351,13 @@ namespace Oqtane.Controllers
|
|||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int GetVisitorCookieId(string visitorCookie)
|
||||||
|
{
|
||||||
|
// visitor cookies contain the visitor id and an expiry date separated by a pipe symbol
|
||||||
|
visitorCookie = (visitorCookie.Contains("|")) ? visitorCookie.Split('|')[0] : visitorCookie;
|
||||||
|
return (int.TryParse(visitorCookie, out int visitorId)) ? visitorId : -1;
|
||||||
|
}
|
||||||
|
|
||||||
private void AddSyncEvent(string EntityName, int EntityId, int SettingId, string Action)
|
private void AddSyncEvent(string EntityName, int EntityId, int SettingId, string Action)
|
||||||
{
|
{
|
||||||
_syncManager.AddSyncEvent(_alias, EntityName + "Setting", SettingId, Action);
|
_syncManager.AddSyncEvent(_alias, EntityName + "Setting", SettingId, Action);
|
||||||
|
@ -51,11 +51,8 @@ namespace Oqtane.Controllers
|
|||||||
bool authorized = User.IsInRole(RoleNames.Admin);
|
bool authorized = User.IsInRole(RoleNames.Admin);
|
||||||
if (!authorized)
|
if (!authorized)
|
||||||
{
|
{
|
||||||
var visitorCookie = Constants.VisitorCookiePrefix + _alias.SiteId.ToString();
|
var visitorCookieName = Constants.VisitorCookiePrefix + _alias.SiteId.ToString();
|
||||||
if (int.TryParse(Request.Cookies[visitorCookie], out int visitorId))
|
authorized = (id == GetVisitorCookieId(Request.Cookies[visitorCookieName]));
|
||||||
{
|
|
||||||
authorized = (visitorId == id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var visitor = _visitors.GetVisitor(id);
|
var visitor = _visitors.GetVisitor(id);
|
||||||
@ -77,5 +74,12 @@ namespace Oqtane.Controllers
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int GetVisitorCookieId(string visitorCookie)
|
||||||
|
{
|
||||||
|
// visitor cookies contain the visitor id and an expiry date separated by a pipe symbol
|
||||||
|
visitorCookie = (visitorCookie.Contains("|")) ? visitorCookie.Split('|')[0] : visitorCookie;
|
||||||
|
return (int.TryParse(visitorCookie, out int visitorId)) ? visitorId : -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user