Simple Group Assign After Registration

Hey all!

I'm kind of hoping someone might be interested in helping me out with this or atleast offering some ideas because even shooting the breeze is helpful here. I want to have users assigned to a group upon registration. The easy part is that the groups are already defined in the data base(i'll create them myself) so it woluld not have to be dynamic in that sense. I would imagine the code would go something like this:

Get group name/GUID from drop down menu at registration

Send invite from GUID to User

Accept Invite

...done

 

They would only need to be registered to one group and I want to prevent the users from registering for another group because basically I'm trying to have users register by school and have their school group be the only group they have access to.

You can see my work so far at www.youhaveihave.com

 

Thanks!!

-Ray-

 

  • Hi Ray,

    Here are some thoughts if you let the user select his school during registration:

    • The registration form is implemented by the "account/forms/register" view.  You would add your new UI elements to views/default/account/forms/register.php.
    • You need some way to carry the group selected through the registration process.
    • Note that a new user is disabled until validated; I assume that you are using the uservalidationbyemail plugin.
    • It may be confusing to the user that there's an validation e-mail and then an invite to join a group that he has already selected during registration.
    • You would need to disable the various group management actions (e.g. add to group).

    I think you may have a smoother process if you let the user select his school during validation instead.  Here's what I would try:

    • Let the group for a new user be specified by say the "school_group" parameter.
    • Register a plugin hook for the "email/confirm" action.  If "school_group" is missing, redirect the user to a page where he can select his school.  The email confirmation request is then resubmitted with school_group.  (We can talk about how to do a plugin hook for action if you are not familiar with it.)
    • If school_group is present, than upon successful validation, the plugin hook would cause the new user to be added to the group (basically a ElggGroup::join() call).

    -- Patrick

  • WOW...i just wrote a HUGE paragraph and forgot to click submit...walked away, came back an hour later, clicked submit and the error box pops up sayin the page expired and then it wouldn't let me get my comment back...UGH!

     

    anyways, so the gist is this...on the site now i have a field in registration where they can chose their school from a drop down menu but it's only a tag field...can i harness that power somehow and maybe do something like:

     

    after email confirmation

    get infofield_school

    find the group with the same name(i'd manually create the schools(i.e. groups) in the database that I want)

    Autoinvite/autoaccept

     

     

    What cha think?

     

    Thanks!

    -Ray-

     

  • The "email/confirm" action triggers an 'enable' event when the confirmation is verified, so it is simpler than I thought.  I don't know how you pass 'infofield_school' around, but something like the following would work:

    function blah_email_confirm_hook() {
      register_elgg_event_handler('enable', 'user', 'blah_user_enabled');
      return true;
    }

    function blah_user_enabled($event, $type, $user) {
      // just some sanity checks
      //
      if ($event != 'enable' || $type != 'user' || !($user instanceof ElggUser))
        return true;

      // TODO: where does school group GUID come from?  Is it a
      // parameter encoded in the e-mail confirmation URL?
      //
      $grp_guid = get_input('infofield_school');
      $usr_guid = $user->guid;

      // add user to group
      // TODO: make sure $grp_guid is a valid school group
      //
      if (!is_group_member($grp_guid, $usr_guid)) {
        if (!join_group($grp_guid, $usr_guid)) {
          // TODO: error handling
        }
      }

      return true;
    }

    // register hook for email/confirm, e.g. in a plugin's start.php
    //
    register_plugin_hook('action', 'email/confirm', 'blah_email_confirm_hook');