Set default role to new user

Posted by Community Admin on 03-Aug-2018 13:50

Set default role to new user

All Replies

Posted by Community Admin on 17-Jul-2014 00:00

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

Posted by Community Admin on 22-Jul-2014 00:00

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
 

This thread is closed