Copied to clipboard

Flag this post as spam?

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


  • nickornotto 403 posts 907 karma points
    May 30, 2013 @ 12:08
    nickornotto
    0

    create member profiles programatically

    I'm trying to create new member programaticaly. Exactly I need to build a function to import members from a spreadsheet.

    I built a Member class which inherits ProfileBase and can create one member programaticaly when he registers but that requires he logs in to update full profile. So a member registers, his membership is created, I log him in, create his profile and log him out. This is not visible for the user but works well in the background.

    Now I need to to import members through a feature in the umbraco back office. I am able to create members but I am unable to update their profiles which use custom properties set up in web.config, umbraco and my Member class. I just get empty profile in my database.

    Any idea what I can do in this case? How I can update a member profile without logging the member in?

    Thank you

  • Matt Jones 30 posts 141 karma points
    Jun 12, 2013 @ 12:17
    Matt Jones
    0

    Hi

    If you have access to the User's username you should be able to create a Membership and Member class object and call the update methods.

     

    memberToEdit = Membership.GetUser("username");

    memberToEdit.Email = "[email protected]";

    Membership.UpdateUser(memberToEdit)

    //BasicProfile is the equivilant of your class which inherits from Profilebase

    profileToEdit = BasicProfile.GetUserProfile("username");

    profileToEdit.propertyName = "newvalue";

    profileToEdit.Save();

  • Charles Afford 1163 posts 1709 karma points
    Jun 16, 2013 @ 19:04
    Charles Afford
    0

    http://www.charlesafford.com/umbraco-membership-provider.aspx

    Take a look at this post.  This will explain it i think :).  Charlie

  • Charles Afford 1163 posts 1709 karma points
    Jun 16, 2013 @ 19:05
    Charles Afford
    0

    You dont need to define the properties in the web config? :)

  • nickornotto 403 posts 907 karma points
    Aug 14, 2013 @ 12:23
    nickornotto
    0

    Thanks CHARLES, I'm not sure you understood what I asked for though - I have my web.config & umbraco set up with profile class & membership provider which I use with no problem.

    I just didn't know how to create new profiles programatically without the need to log them in first.

     

    MATT, thanks, it looks like this may do the job.

    Your solution looks pretty obvious and I think I tried to do the same.

    I don't see ProfileBase has a method GetUserProfile() available so I used my own:

    public static Member UserById(int id)
            {
                try
                {
                    return (Member)ProfileBase.Create(Membership.GetUser(id).UserName);
                }
                catch (Exception ex)
                {
                    return null;
                }
            }

     

    I don't think it worked for me though using ProfileBase.Create() method. Will check it later and come back here.

    For now - as it was one-off job I used deprecated umbraco Member class to update profiles.

     

    Thanks

  • Matt Jones 30 posts 141 karma points
    Aug 14, 2013 @ 12:48
    Matt Jones
    0

    Hi Eva

    sorry, this is the GetUserProfile method I use, overloaded so one can get by username, the other by the currently logged on user, again my class that inherits from ProfileBase is called BasicProfile:

     

           public static BasicProfile GetUserProfile(string username)
            {
                return Create(username) as BasicProfile;
            }

            public static BasicProfile GetUserProfile()
            {
                return Create(Membership.GetUser().UserName) as BasicProfile;
            }
  • Charles Afford 1163 posts 1709 karma points
    Aug 14, 2013 @ 20:31
    Charles Afford
    0

    Ahhhh i see yes i had misunderstood, but Matt Jones looks like he has a good implimentation :).  Charlie

Please Sign in or register to post replies

Write your reply to:

Draft