+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Set default role to new user

Set default role to new user

2 posts, 0 answered
  1. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    17 Jul 2014
    Link to this post

    Hi all,

    Is it possible to set a default role when creating a new user through the backend interface?
    I need to have a particular role being checked, by default.

    Best,
    Daniel

  2. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    22 Jul 2014
    Link to this post
    Hello Daniel,

    You should map the UserCreate view and manipulate the RolesRepeater which holds the Roles and the Checkbox for each role selection. Using the codebehind of the mapped view, we can iterate the roles collection and find the one we need, then find the underlying checkbox and check it:
    public partial class UserNew : System.Web.UI.UserControl
        {
     
            protected void Page_Load(object sender, EventArgs e)
            {
                var rolesList = this.FindControl("rptRolesList") as Repeater;
                if (rolesList != null)
                {
                    var items = rolesList.DataSource as List<RoleProviderPair>;
                    if (items != null && items.Count > 0)
                    {
                        for (int i = 0; i < items.Count; i++)
                        {
                            if (items[i].RoleItem.Name == "Authors")
                            {
                                var checkBox = rolesList.Items[i].FindControl("role") as CheckBox;
                                if (checkBox != null)
                                {
                                    checkBox.Checked = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }

    The view is mapped from Administration -> Settings -> Advanced -> Controls -> ViewMap. Create New and add to HostType: Telerik.Sitefinity.Security.Web.UI.Principals.UserNewDialog, Telerik.Sitefinity, in LayoutTemplatePath set the path to the new template. Example.

    I have attached the mapped view. Hope you find it helpful.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
2 posts, 0 answered