Refresh sectionTree on new user login

别说谁变了你拦得住时间么 提交于 2019-12-11 10:42:27

问题


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.

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.

How would i make the SectionTree refresh on new users login?

Update

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;

}

回答1:


Based on a comment you are not clearing _curNewUser when user logs out and that's why you are seeing this issue.

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.



来源:https://stackoverflow.com/questions/29509288/refresh-sectiontree-on-new-user-login

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!