新用户登录时刷新部分树 [英] Refresh sectionTree on new user login
问题描述
我有一个部分树,它根据当前登录的用户用户类型而变化.
I have a sectiontree which varies based on the current logged in users UserType.
问题是,如果我从后台注销,并使用用户类型较低的新用户登录,则树不会刷新 - 不会重新运行代码来生成树.
The thing is that if i log-out from the backoffice, and logs in with a new user with a lower UserType, the tree is not refreshed - The code is not rerun to generate the tree.
这意味着具有非管理 UserType 的用户可以访问该部分中的管理区域,只要管理员之前已登录同一解决方案即可.
This means that the user with a non administrative UserType can access administrative areas in the section, as long as an administrator have been logged in earlier on the same solution.
如何在新用户登录时刷新 SectionTree?
How would i make the SectionTree refresh on new users login?
更新
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
{
var sectionApi = new SectionApiController();
// Root handler
if (id == Constants.System.Root.ToInvariantString())
{
this.RootHandler();
}
else if(id.Contains("COUNTRY_") || id.Contains("LEVEL_") )
{
var section = new IdConvert(id);
if ( section.Area.Equals("country") )
{
this.FirstLevelHandler(section.Id);
}
else if (section.Area.Equals("level"))
{
this.GetLevels(section.Id);
}
// Render clubs.
this.ClubHandler();
// Render levels
this.LevelHandler();
} else if(id.Contains("CLUB_")) {
}
else if(id.Contains("SPORTS_")) {
var Country = new IdConvert(id);
this.SportsHandler(Country.Id);
}
else if (id.Contains("QUESTIONS_"))
{
var Country = new IdConvert(id);
this.QuestionsHandler(Country.Id);
}
return this._nodes;
}
树工作正常,它渲染它应该渲染的东西.但它不会在新用户登录时刷新.
The Tree works fine, it renders what it should render. But It doesent refresh upon new user login.
我正在使用以下内容来检查一个人是否是管理员"
I'm using the following to check wether or not a person is "admin"
public static bool IsAdministrator()
{
try
{
if (_curNewUser == null)
{
GetCurrentUser();
}
if (_curNewUser.UserType.Alias == "admin")
{
return true;
}
}
catch (Exception e) { }
return false;
}
推荐答案
根据评论,您没有在用户注销时清除 _curNewUser
,这就是您看到此问题的原因.
Based on a comment you are not clearing _curNewUser
when user logs out and that's why you are seeing this issue.
不要保留对 _curNewUser
的引用,您应该直接在您的 UserProvider 中使用 UmbracoContext.Current.Security.CurrentUser
中内置的 umbraco,这将修复它,就像这样:
Instead of keeping the reference to _curNewUser
you should use umbraco built in UmbracoContext.Current.Security.CurrentUser
directly in your UserProvider and that will fix it, something like this:
public static bool IsAdministrator()
{
var user = UmbracoContext.Current.Security.CurrentUser;
return user != null && user.UserType.Alias == "admin";
}
您无需连接注销事件或类似事件.
No need for you to hook up to logout events or anything like that.
这篇关于新用户登录时刷新部分树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!