1

I am in the process of building a website that in near future shall replace an existing web-site. The existing web-site contains aprox. 300 users which I need to "import" to the extranet-module (which I have bought) in composite.

Is there a way to batch create users to the extranet module?

lxt
  • 31,146
  • 5
  • 78
  • 83

2 Answers2

0

Yes, you can import your existing user database. You can either do this by writing a script and have that execute on your web site or by directly manipulating the underlying SQL table / XML file (depending on what you use to store Composite C1 data). You can also build a provider that links your existing user database with Composite C1 Extranet.

Importing users programmatically: For a script approach please see methods like AddNewUser described on http://docs.composite.net/Packages/Community/Extranet/CompositeCommunityExtranetDeveloperGuide/Using-Extranet-Facade-Methods

You would write this script as web service, aspx page or similar which executes on the Composite C1 website.

If you are running the Extranet in a default setup expect the providerName to be "Default".

Manipulating the physical data store directly: This depends on what data store you are running on. I suggest you add the groups you want and a test user to help you recognize data when you look at the underlying XML files / SQL tables.

  • If you are running on XML (default) you should focus on the files named Composite.Community.Extranet.DefaultProvider.DataTypes.DefaultProvider*.xml located in the folder ~/App_Data/Composite/DataStores. There are 3 sush files, one for groups, one for users and one for the relation between users and groups.

  • If you are running on SQL Server you should focus on the 3 tables named Composite.Community.Extranet.DefaultProvider.DataTypes.DefaultProvider*

In both cases you would need to add new entries to the User table/xml file and matching group relations to the GroupUser table/xml file. When you add a user you provide a unique ID and this ID you reuse to register the user in GroupUser.

When you have made your changes you can force Composite C1 to reload by using the Tools | Restart Server command in the C1 Console. If you make a backup of files/tables before you make changes you can easily revert by restoring the backup (in case you need to start over).

Writing a user/group provider: If your user data is in an external store and you would like to keep it there you could also make a bridge between this existing user store and the Composite C1 Extranet by creating a custom provider. If this is relevant see http://docs.composite.net/Packages/Community/Extranet/CompositeCommunityExtranetDeveloperGuide/Writing-Custom-Extranet-Providers

mawtex
  • 1,564
  • 1
  • 12
  • 21
0

Thank you. It now works. I imported the users programmatically. I opened the composite solution in visual studio and added a aspx page. Here is the code behind.

using System;
using System.Collections.Generic;
using System.IO;
using Composite.Community.Extranet;
using Composite.Community.Extranet.Data;

public partial class ImportUsers : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string path = Server.MapPath("UsersToImport.csv");
        StreamReader _streamReader = new StreamReader(path);

        IList<Guid> userIds = new List<Guid>();
        string line;
        while ((line = _streamReader.ReadLine()) != null)
        {
            string[] fields = line.Split(',');
            IExtranetUser extranetUser = new ExtranetUser();
            extranetUser.Name = fields[0];
            extranetUser.UserName = fields[1];
            extranetUser.Email = fields[2];
            extranetUser.IsApproved = true;

            IExtranetUser addedUser = ExtranetFacade.AddNewUser("Default", extranetUser);
            userIds.Add(addedUser.Id);

            ExtranetFacade.SetUsersForGroup("Default", new Guid("bc728100-e28e-4135-a14c-bead6e0b9b00"), userIds);
            Response.Write(string.Format("User: {0} added at {1}", addedUser.UserName, addedUser.CreationDate));
        }
    }
}