'Users can create new accounts on the site' bool?

Topics: Writing modules
Mar 5, 2012 at 10:01 PM

Hi All, Is there a way I can enable 'programmatically' the "Users can create new accounts on the site" switch when I enable my custom module simultaneously, and is it possible to automatically attach my custom part to the User content type as well [I imagine through the migration file]? Thanks for your help, Cheers Dyr.

Developer
Mar 5, 2012 at 10:29 PM
Edited Mar 5, 2012 at 10:29 PM

Absolutely!

var registrationSettings = _orchardServices.WorkContext.CurrentSite.As<RegistrationSettingsPart>();
registrationSettings.UsersCanRegister = true;

 (see the AccountController of the Orchard.Users module)



You can most certainly attach your custom part to the "User" content type using a migration class. After all "User" is just a content type.

Mar 6, 2012 at 1:30 AM

Ok, huge thanks again 'sfmsskywalker' - I added:

            ContentDefinitionManager.AlterTypeDefinition("User", t => t
                .WithPart("MemberPart")
                );

to my migration, *perfect*, though was wondering the best place to add "UsersCanRegister = true"?  Is there a recommended area/event/initializer that is fired when a module is enabled that such code should be placed? Thanks in anticipation, cheers Dyr

Coordinator
Mar 6, 2012 at 2:01 AM

The Create method of a migration.

Mar 6, 2012 at 2:47 AM

Thanks bertrandleroy, so using the migration is standard 'orchard' practice for such settings etc., I had it in my head to keep it as pure data concern. Thanks again, Dyr