Copied to clipboard

Flag this post as spam?

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


  • Dan 1243 posts 3708 karma points admin c-trib
    Jul 01, 2014 @ 20:54
    Dan
    0

    Create then log in user, with UserService

    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

  • Dan 1243 posts 3708 karma points admin c-trib
    Jul 01, 2014 @ 22:07
    Dan
    100

    Seems this does the trick. No idea if it's the 'right way' but it appears to work:

    var userLogin = UmbracoContext.Security.PerformLogin(createUser);
    
  • Christian Tricarico 6 posts 86 karma points
    Sep 26, 2018 @ 05:52
    Christian Tricarico
    0

    @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.

  • Victor 13 posts 117 karma points
    Sep 26, 2018 @ 08:06
    Victor
    1

    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

  • Christian Tricarico 6 posts 86 karma points
    Sep 26, 2018 @ 08:11
    Christian Tricarico
    0

    Hi Vic, yes, I see just now that the memberType string is "Not used for users". Thanks for your tips.

Please Sign in or register to post replies

Write your reply to:

Draft