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

Forums / Developing with Sitefinity / Create / Update Users via API

Create / Update Users via API

2 posts, 0 answered
  1. Jon Kramme
    Jon Kramme avatar
    15 posts
    Registered:
    20 Dec 2009
    26 Dec 2009
    Link to this post
    I am a newbie to Sitefinity but have many years of experience with ASP.NET and am working on a project that involves integrating Sitefinity's core functionality with some custom stuff involving another database (one that stores an organization's members).

    One of the tasks is to create and update Sitefinity user accounts via code in a custom user control.  For example, when a new person is added to our other database I also need to add that user to Sitefinity and assign them to a particular role.

    Another similar task would be to manage newsletter subscriber group members such that when a user updates opt-out preferences in our other database, we simultaneously add or remove that person from Sitefinity newsletter subscriber groups.

    I'm hoping someone can point me in the right direction, such as which namespaces, classes, etc. I ought to be focused on so that I can accomplish these tasks.  I can see from examining the CMS database how I could directly work with the stored procedures to accomplish much of this, but it seems more proper and reliable to use the API.

    Thanks!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    27 Dec 2009
    Link to this post
    Hello Jon Kramme,

    One of the tasks is to create and update Sitefinity user accounts via code in a custom user control.  For example, when a new person is added to our other database I also need to add that user to Sitefinity and assign them to a particular role.

    Inn the other website you have you can use standard ASP.NET methods and classes to maintain Sitefinity's user. First you need to add another membership provider ( you can also add role and profile providers) and then using MembershipUser to create a new user.

    sample code:

    // HERE YOU HAVE ALREADY CREATED A NEW USER FOR THE OTHER MEMBERSHIP PROVIDER
    // NOW YOU HAVE TO ACCESS THE SECOND PROVIDER - THIS ONE USED FOR MANAGING SITEFINITY USERS
     
    MembershipUser SitefinityUser =  Membership.Providers["SitefinityProvider"].CreateUser("username", "pwd", "someone@somedomain.com", "pq", "pa", true, providerUserKey, MembershipCreateStatus.Success)

    Another similar task would be to manage newsletter subscriber group members such that when a user updates opt-out preferences in our other database, we simultaneously add or remove that person from Sitefinity newsletter subscriber groups.

    For this task you can expose a web service and add Telerik.Notifications and Telerik.Notifications.Data assemblies to non Sitefinity based project(  you have also add Telerik.Cms.Engine.dll, telerik.Cms.Web.UI.dll, Telerik.DynamicWebServices.dll, Telerik.Framework.dll, Telerik.Personalization.dll, Telerik.Security.dll, Telerik.Web.UI.dll)

    sample code that illustrates adding/removing a given user

    DataManager dataManager = new DataManager();
    // add user to group
    IGroupSubscriber gSubscriber = dataManager.CreateGroupSubscriberRelation(GuidGroupID, subscriber.SubscriberId);
    dataManager.SaveGroupSubscribers(gSubscriber);
    // remove group subscriber relation
    IList gSubs = dataManager.GetSubscriberGroupsOfSubscriber(subscriberEmail);
    foreach (IGroupSubscriber gSub in gSubs)
    {
        dataManager.DeleteGroupSubscriberRelation(gSub);
    }

    We do not encourage directly working with the datatabse and its store procedures. The database is maintained by Nolics. So, you can use the Sitefinity's API, Nolics api or create custom tables and use LINQ -SQL. You can take a look at our developers manual for more information and samples with the API

    Regards,
    Ivan Dimitrov
    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.
2 posts, 0 answered