Under Settings > Users > Settings Tab there is an option to allow public registration
and Default User Group
with a drop down that lets you select a user group.
If you need more flexibility, you could also write a simple plugin with an init
function defined in the primary plugin class that listens to the saveUser
event, and assigns a user group based on some criteria that you define — perhaps test the value of a custom user field on users (that is a hidden field on the registration form).
*UPDATED to assign group based on checkbox field called 'groupPreference':
namespace Craft;
class BusinessLogicPlugin extends BasePlugin {
public function getName() {
return 'Business Logic';
}
public function getVersion() {
return '0.1';
}
public function getDeveloper() {
return craft()->getSiteName();
}
public function getDeveloperUrl() {
return 'http://mysite.com';
}
public function init() {
parent::init();
craft()->on('users.saveUser', function(Event $event) {
// only fire if new user
if ($event->params['isNewUser']) {
// retrieve the userModel from the event
$user = $event->params['user'];
// retrieve the groupPreference field content
$groupPreference = $user->getContent()->groupPreference;
// create an empty array to store group ids
$groups = array();
// test for values in groupPreference array
if (in_array("group1", $groupPreference)) {
$groups[] = 1;
}
if (in_array("group2", $groupPreference)) {
$groups[] = 2;
}
if (in_array("group3", $groupPreference)) {
$groups[] = 3;
}
// assign the user to the groups
$_POST['groups'] = $groups;
}
});
}
}
Haven't tested, but should be pretty close. Please comment if you see an error.
Keep in mind this event will fire, whenever this field is defined, even when saving a user through the CP. So you would have to delete the value before reassigning the user to a different group, or they will just get reassigned.