Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nick 42 posts 155 karma points
    Jun 26, 2013 @ 09:48
    Nick
    0

    How to create members and assign to roles using API in Umbraco 6.x

    Hi,

    I need to create a web service that can dynamically create members and assign them to member roles.

    What is the best way to do this using the API?

    There is a section on the API cheatsheet ( http://our.umbraco.org/wiki/reference/api-cheatsheet/working-with-members )but it says that it is out of date and should be updated:

     

    Thanks,

    Nick

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Jun 26, 2013 @ 11:01
    David Brendel
    0

    Most of the member api is marked as outdated but can be used. So just try to use the functions you need and see if they work.

    Here's a sample on how you create a new user and set a membergroup to him:

    //Member Type

                MemberType umbJobMemberType = MemberType.GetByAlias("TMMember");

                //Umbraco Admin User (The Umbraco back office username who will create the member via the API)

                User umbUser = new User("dbrendel");

                //Model valid let's create the member

                try

                {

                    Member createMember = Member.MakeNew(model.Name, model.EmailAddress, model.EmailAddress, umbJobMemberType, umbUser);

                    //Set password on the newly created member

                    createMember.Password = model.Password;

                    //Set the verified email to false

                    createMember.getProperty("hasVerifiedEmail").Value = false;

    //Set the profile URL to be the member ID, so they have a unqie profile ID, until they go to set it

                    createMember.getProperty("profileURL").Value = createMember.Id;

                    createMember.AddGroup(MemberGroup.GetByName("TMGroup").Id);

                    //Save the changes

                    createMember.Save();

                }

                catch (Exception ex)

                {

                    //EG: Duplicate email address - already exists

                    throw;

                }

    The example comes from an Mvc controller, so the model.Property is just an object with the infos provided by the user.

    To set up the webservice in Umbraco i would recommend using UmbracoApiController if you are on Umbraco 6.1.x. But i think there should be more than one way to get somethink like a webservice up and running.

  • Nick 42 posts 155 karma points
    Jun 26, 2013 @ 12:23
    Nick
    0

    Hi David,

    thanks for the reply. I am not too familiar with MVC and am using web forms.

    Does v6 use the ASP.NET membership provider? Is there any example code for creating members and assigning them to Umbraco MemberGroup's  using this?

    thanks.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 26, 2013 @ 12:32
    Jeroen Breuer
    1

    Hello,

    The member api will get a new version, but the old api is still the best thing for now. The obsolete attributes have even been removed again in the latest version of Umbraco: https://github.com/umbraco/Umbraco-CMS/commit/7c6aee17e90d4b59a29cbcabf915475510c072c7

    New member api: http://issues.umbraco.org/issue/U4-1659

    So this documentation is still good: http://our.umbraco.org/wiki/reference/api-cheatsheet/working-with-members

    Jeroen

  • Nick 42 posts 155 karma points
    Jun 26, 2013 @ 12:34
    Nick
    0

    Thanks Jeroen.

Please Sign in or register to post replies

Write your reply to:

Draft