We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17422
    • 225 Posts
    Hi,
    my question his :

    is it possible to create a user group and user member in front end with formit ?



    Laurent
      • 3749
      • 24,544 Posts
      Yes. It would have to be done in a FormIt custom hook.

      Do you want a separate user group for each member?
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 17422
        • 225 Posts
        yes, each member will can create a group :

        explanation: each group will be a crew sailing with a captain (the creator of the group member)

          • 3749
          • 24,544 Posts
          You’d need to create a custom hook for FormIt.

          Here’s something similar that should get you started:

          <?php
          /* Create a user group (if the group already exists you'd use getObject() instead) */
          $group = $modx->newObject('modUserGroup',array('name'=>'PhotoEditors'));
          $group ->save();
          
          /* create a user */
          $user = $modx->newObject('modUser', array('username'=>'BillSmith'));
          $profile = $modx->newObject('modUserProfile');
          $profile->set('fullname','Bill Smith');
          $profile->set('email','[email protected]');
          $user->addOne($profile);
          /* create a role (if the role already exists, you'd use getObject() instead) */
          $role = $modx->newObject('modUserGroupRole', array('name'=>'PhotoEditor','authority'=>'7'));
          
          /* add the user to the group with the role above*/
          $intersect = $modx->newObject('modUserGroupMember');
          $intersect->addOne($user);
          $intersect->addOne($group);
          $intersect->addOne($role);
          $modx->beginTransaction();
          if (! $intersect->save()) {
              $modx->rollback();
              $output .= 'An error occurred — user, role, and group not saved';
          } else {
              $modx->commit();
              $output .= 'User, role, and Group Created';
          }
          


          You’d have to replace the literal strings with variables you get from the form submission or parameters. You’d probably want to try getObject() first and create the object if it returns null.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 17422
            • 225 Posts
            thanks Bobray,

            i will start with that.

            and I need my member can create groups and other user.
            with access policies permissions :

            new_user
            new_role

            in web context

            but for new user group what is the permission ?


            thanks again for your help

            Laurent
              • 3749
              • 24,544 Posts
              Neither users nor user groups have a context. They get access to contexts through Context Access ACL entries.

              Users and groups also don’t have permissions. They acquire permissions based on policies assigned in ACL entries.

              IOW, your code can create users, groups, and roles. It can also add a user to a group with a particular role. In theory, it could create ACL entries, but it might be easier just to create these by hand.

              When a user is assigned to a group with a certain role, the user automatically gets the permissions from any policies assigned in ACL entries if the user meets the minimum role qualification.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 17422
                • 225 Posts
                Thanks a lot BobRay for this explanation.

                i understand better now the principle.

                Laurent