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(); }
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);
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':
Kind Regards,
pronto
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:
(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:
Hope this helps.
what if i wanna create new member with additional propertly, like mobile number or something else?
Thanks Dan,
Very nice.. But after creating user I am not able to login.. Can you please help.
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):
pronto
is working on a reply...