Copied to clipboard

Flag this post as spam?

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


  • pronto 61 posts 172 karma points
    Jul 08, 2014 @ 17:41
    pronto
    0

    Create a new Umbraco User in Umbraco 7.1

    Hi All,

    I'm trying to create a new User (not a Member) from a signup form in Umbraco 7.1.4 and after trying to get my old code to work, it does not work now (as a Partial View or legacy macroScript).

    I know there is now example code for a Member sign up in the latest Umbraco version, can I use this as a base for a User signup or is it entirely different? I can't find any documentation yet on how to do this in Umbraco 7.1+ but is there anything out there that can help me?

    Pre-Umbraco 7 I would use similar code to the documentation example, which now generates the error  'System.Security.Principal.IPrincipal' does not contain a definition for 'MakeNew' and no extension method 'MakeNew':

    @using umbraco.BusinessLogic;
    
    @{
    UserType ut = UserType.GetUserType(0);
    User.MakeNew("John Smith", "johnsmith", "secrectPass", ut);
    User u = new User("johnsmith");
    u.Email = "[email protected]";
    u.addApplication("settings");
    u.Save();
    }


    Kind Regards,
    pronto

  • Dan 1288 posts 3921 karma points c-trib
    Jul 08, 2014 @ 17:53
    Dan
    101

    Hi Pronto,

    The UserService isn't documented yet, so it's a bit of a struggle to find info on it!

    To register a new user though, try something like this:

    var userService = Services.UserService;
    var userType = "myUserType";
    var createUser = userService.CreateWithIdentity(model.EmailAddress, model.EmailAddress, model.Password, userType);

    (This is part of a wider MVC implementation, hence the model. syntax - hopefully you get the gist though.)

    To log-in a user after creating it, would be something like this:

    var userLogin = UmbracoContext.Security.PerformLogin(createUser);

    Hope this helps.

     

  • aleksandar 14 posts 74 karma points
    Jul 24, 2015 @ 11:37
    aleksandar
    0

    what if i wanna create new member with additional propertly, like mobile number or something else?

  • suraj 2 posts 72 karma points
    Mar 02, 2017 @ 06:12
    suraj
    0

    Thanks Dan,

    Very nice.. But after creating user I am not able to login.. Can you please help.

  • pronto 61 posts 172 karma points
    Jul 08, 2014 @ 18:40
    pronto
    1

    Hi Dan,

    Thanks for your reply, it helped out a lot!

    For anyone else needing the same thing, this code worked for me (a very, very simple example):

    var userService = ApplicationContext.Current.Services.UserService;
    var createUser = userService.CreateWithIdentity("Username", "[email protected]", "password", "writer"); 


    pronto

Please Sign in or register to post replies

Write your reply to:

Draft