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

Forums / Deployment / Mass Enroll?

Mass Enroll?

6 posts, 1 answered
  1. Haddicus
    Haddicus avatar
    17 posts
    Registered:
    19 Dec 2009
    26 Jan 2010
    Link to this post
    I am the President of Iota Sigma Tau, Kaplan University's IT honor society and am trying to put my head around how we can do a mass enroll of members into sitefinitity and provide them with a starting password easily. Has anyone implemented any sort of mass enrollment that would allow us to create membership for individuals and temporary passwords and upon initial login ask for a new password. The only reference I could find in relation was a post about single sign on, but that's not really what we want to implement. I appriciate any feedback.

    Thanks!

    -SH
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    26 Jan 2010
    Link to this post
    Hello Sean Haddy,

    Thank  you for using our services.

    You can create a CSV (Comma Separated Values) file which will contain your user information such as user names, profile information, e-mail, etc .Attached is a sample tool that reads values from this file and creates new users. What the tool does is that it reads lines from a file where users and profile information are entered as coma separated values (CSV file). Each line represents the following information:

    Username, Password, Email, Role

    This tool can be easily extended to read additional data and add it to user's profile for example. If for example you wish to add user's profile you just have to add some code to the ~/Tools/ImportUsersTool/ImportUsersTool.ascx.cs:

    Copy Code
    ...
    string userRole = columns[3].Trim();      
    string userAddress = columns[4].ToString();
    MembershipUser newUser = userManager.CreateUser(userName, userPassword, userEmail);
       if (newUser != null)
       {
          ProfileBase profile = ProfileBase.Create(newUser.UserName);
          profile.SetPropertyValue("FirstName", newUser.UserName);
          profile.SetPropertyValue("Address",userAddress);
    ...

    Attached is the custom tool, and a sample CSV file. To use it just add the contents of the archive to the root directory of your website and restart the website. You can use the same pattern to add additional values if you wish. When you are creating the users you can set a profile property to check whether they should change password. First extend the profile properties in web.config:
    <profile defaultProvider="Sitefinity">
        <providers>
            <clear/>
            <add name="Sitefinity" connectionStringName="DefaultConnection" applicationName="/" type="Telerik.DataAccess.AspnetProviders.TelerikProfileProvider, Telerik.DataAccess"/>
        </providers>
        <properties>
            <add name="FirstName"/>
            <add name="LastName"/>
            <add name="Position"/>
            <add name="Photo_Hidden"/>
                <add name="ChangePassword"/>
            <add name="Photo" defaultValue="~/Sitefinity/Common/Images/defaultavatar.gif"/>
            <group name="InstantMessenger">
                <add name="IM_Type"/>
                <add name="IM_Value"/>
            </group>
            <group name="Phone">
                <add name="Value"/>
                <add name="Type"/>
            </group>
        </properties>
    </profile>

    Then just add this when creating user profiles:
    if (newUser != null)
    {
        ProfileBase profile = ProfileBase.Create(newUser.UserName);
        profile.SetPropertyValue("FirstName", newUser.UserName);
        profile.SetPropertyValue("ChangePassword", true);
        //set other profile date using the ProfileBase.SetPropertyValue(string PropertyName,string PropertyValue) as in above line
        if (!Roles.RoleExists(userRole))
            Roles.CreateRole(userRole);
        userManager.AddUserToRole(newUser.UserName, userRole);
        profile.Save();
    }

    Then you can edit the log-in control (~/Sitefinity/UserControls/Login/LoginControl.ascx.cs) to check if the password should be changed and if yes, redirect to a page with change password control:
    void Page_Load(object sender, EventArgs e)
    {
        //subscribe to the logged in event of the control
        this.Login1.LoggedIn += new EventHandler(Login1_LoggedIn);
    }
    void Login1_LoggedIn(object sender, EventArgs e)
    {
      ProfileBase profile = ProfileBase.Create(this.Login1.UserName);
      bool changePassword = profile.GetPropertyValue("ChangePassword") as bool;
      if (client)
      {
          //redirect to change password page
      }else //redirect to another poage     
    }

    Then after the password has been changed do not forget to set the proper value to the user profile.

    Greetings,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  3. Allen
    Allen avatar
    71 posts
    Registered:
    04 Aug 2007
    18 Nov 2011
    Link to this post
    In 4.2, I am getting errors for the following namespaces:

    using Telerik.CMS.Web.UI;
    using Telerik.Security;
    using Telerik.DataAccess.AspnetProviders;

    Also, this seems to be an issue:
    <sfMsg:MessageControl ID="msgStatus" runat="server"></sfMsg:MessageControl>
    (even with changing the namespace to Telerik.Sitefinity.Web.UI)

    What are the 4.2 equivalents or could you reupload a version compatible with 4.2+?
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    22 Nov 2011
    Link to this post
    Hi Allen,

    If you have installed the Sitefinity 4.3 SDK you can take a look at some sample utility methods we have created. Namely look at the Content/Common/
    Telerik.Sitefinity.Samples.Common project which installs with the SDK. It has the bellow sample method for creating users and roles:

    public static void CreateUsersAndRoles()
    {
        var userManager = UserManager.GetManager();
     
        if (!userManager.UserExists("admin"))
        {
            userManager.Provider.SuppressSecurityChecks = true;
            MembershipCreateStatus status;
            var user = userManager.CreateUser("admin", "password", "admin@sample.com", "test", "yes", true, null, out status);
            if (status != MembershipCreateStatus.Success)
            {
                throw new InvalidOperationException("User cannot be created" + status.ToString());
            }
            userManager.SaveChanges();
            userManager.Provider.SuppressSecurityChecks = false;
     
            var roleManager = RoleManager.GetManager("AppRoles");
            roleManager.Provider.SuppressSecurityChecks = true;
            Guid id;
            foreach (var a in Config.Get<SecurityConfig>().ApplicationRoles.Keys)
            {
                var info = Config.Get<SecurityConfig>().ApplicationRoles[a];
                id = info.Id;
                if (roleManager.GetRoles().Where(r => r.Id == id).FirstOrDefault() == null)
                {
                    roleManager.CreateRole(info.Id, info.Name);
                }
            }
            roleManager.SaveChanges();
     
            var adminRole = roleManager.GetRole("Administrators");
            roleManager.AddUserToRole(user, adminRole);
            roleManager.SaveChanges();
            roleManager.Provider.SuppressSecurityChecks = false;
        }
     
        SecurityManager.AuthenticateUser(null, "admin", "password", true);
    }


    Best wishes,
    Radoslav Georgiev
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  5. Allen
    Allen avatar
    71 posts
    Registered:
    04 Aug 2007
    06 Dec 2011
    Link to this post
    I have downloaded the SDK and have part of the solution for what I need.  However, I have custom providers and custom profiles that need to be populated for my user accounts.  I can get the custom provider, but for the life of me, cannot determine what API I need to follow to get and populate the custom profile properties.  When I get the profile manager via the Telerik stack (Telerik.Sitefinity.Security.UserProfileManager.GetManager().GetUserProfiles()).  I can list out the data and see a type of Telerik.Sitefinity.Security.Model.customer, which is my customer profile, but I cannot work with it.  However, my goal isn't to get an existing profile and update it.  Instead it is to populate the profile (i.e. create it) during the process that I am creating my user accounts. Any help would be appreciated.
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    08 Dec 2011
    Link to this post
    Hi Allen,

    Bellow sample shows how to work with profiles. For your custom profile instead of using the type name of the built in profile you should use the name of the custom profile:
    profileManager.Provider.SuppressSecurityChecks = true;
               var myProfile = profileManager.GetUserProfile(myUser, (typeof(SitefinityProfile)).FullName);
               if(myProfile != null)
               {
                   var favoritesField = myProfile.GetValue<String>("Favorites");
                   myProfile.SetValue("Favorites", "Movies, Magazines");
               }

    The name will be something like Telerik.Sitefinity.Security.Model.ProfileName

    Greetings,
    Radoslav Georgiev
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
6 posts, 1 answered