Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I've created a user with the new UserService:
var userService = Services.UserService; var userType = "myUserType"; var createUser = userService.CreateWithIdentity(model.EmailAddress, model.EmailAddress, model.Password, userType);
How do I log-in the user immediately after creating it?
Thanks
Seems this does the trick. No idea if it's the 'right way' but it appears to work:
var userLogin = UmbracoContext.Security.PerformLogin(createUser);
@Dan, what's the userType string? I try to set it with the group alias to which I want the new user to be assigned to but it doesn't work.
Hello Christiano,
The user type is basically the member's type alias. (see https://our.umbraco.com/apidocs/csharp/api/Umbraco.Core.Services.UserService.html#UmbracoCoreServicesUserServiceSavingUser)
You'd need to create the user, then get the desired group, assign the group to the user and then persist changes.
You can have a look here on how to add groups to a user: https://our.umbraco.com/apidocs/csharp/api/Umbraco.Core.Models.Membership.IUser.html#UmbracoCoreModelsMembershipIUserAddGroupUmbracoCoreModelsMembershipIReadOnlyUserGroup_
Hope this helps,
Victor
Hi Vic, yes, I see just now that the memberType string is "Not used for users". Thanks for your tips.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Create then log in user, with UserService
Hi,
I've created a user with the new UserService:
How do I log-in the user immediately after creating it?
Thanks
Seems this does the trick. No idea if it's the 'right way' but it appears to work:
@Dan, what's the userType string? I try to set it with the group alias to which I want the new user to be assigned to but it doesn't work.
Hello Christiano,
The user type is basically the member's type alias. (see https://our.umbraco.com/apidocs/csharp/api/Umbraco.Core.Services.UserService.html#UmbracoCoreServicesUserServiceSavingUser)
You'd need to create the user, then get the desired group, assign the group to the user and then persist changes.
You can have a look here on how to add groups to a user: https://our.umbraco.com/apidocs/csharp/api/Umbraco.Core.Models.Membership.IUser.html#UmbracoCoreModelsMembershipIUserAddGroupUmbracoCoreModelsMembershipIReadOnlyUserGroup_
Hope this helps,
Victor
Hi Vic, yes, I see just now that the memberType string is "Not used for users". Thanks for your tips.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.