Default user group

Permalink
When a user registers, can they be placed into a default group?

mrnoisy
 
kino replied on at Permalink Reply
kino
Yes.

I think you can reference the code below.

/concrete/models/userinfo.php at line 137.
$res = $db->execute($r, $v);
         if ($res) {
            $newUID = $db->Insert_ID();
            $ui = UserInfo::getByID($newUID);
            if (is_object($ui) && !in_array(self::ADD_OPTIONS_SKIP_CALLBACK,$options)) {
               // run any internal event we have for user add
               Events::fire('on_user_add', $ui);
            }
            return $ui;
         }


and

<?php  
            $uo = UserInfo::getByUserName($username);
            if (is_object($uo)) {
                if($group!=''){
                    $groups = Group::getByName($group);
                    $gIDs[]= $groups->gID;
                    $groups = new GroupList($uo,true);
                    foreach ($groups->gArray as $g){
                        if(array_search($g->gID,$gIDs)===false){
                            $gIDs[] = $g->gID;
                        }
                    }
                    $uo->updateGroups($gIDs);
                }
                $result = t('success import %s (%s)', $username,$email);
kino replied on at Permalink Reply
kino
It was a pain to make the default interface to select a group
default was set to copy the nickname of the user group.


/config/site.php add the following to
<?php define('ENABLE_APPLICATION_EVENTS', true); ?>


The following content /config/site_events.php create
<?php
Events::extend('on_user_add', 'ApplicationUser', 'setupUserJoinInfo', 'models/application_user.php');
?>


The following content /models/application_user.php create
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
define('DEFAULT_USERNAME', "default");
class ApplicationUser  {
   public function setupUserJoinInfo($ui) {
      $uo = UserInfo::getByUserName(DEFAULT_USERNAME);
      if (is_object($uo)) {
         $groups = new GroupList($uo,true);
         foreach ($groups->gArray as $g){
            $_POST['gID'][] = $g->gID;
         }
      }
   }
}
?>
cyandesigns replied on at Permalink Reply
Hi Kino

Can you give me a little more explanation on what you wrote here?

Does this put a new registrant in a single default group or can the registrant choose the group they are placed in?

Thanks!