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?
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.
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; }
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
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();
http://www.charlesafford.com/umbraco-membership-provider.aspx
Take a look at this post. This will explain it i think :). Charlie
You dont need to define the properties in the web config? :)
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:
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
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:
Ahhhh i see yes i had misunderstood, but Matt Jones looks like he has a good implimentation :). Charlie
is working on a reply...