We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34103
    • 47 Posts
    istvan.velsz Reply #11, 8 years ago
    If the user clicks on the activation link in the email he will call the page with the »confirmRegister« snippet. The redirect in the »confirmRegister« snippet doesn't work and all I'll get is a blank page. The resource of the plugin wouldn't be created.
      • 3749
      • 24,544 Posts
      As long as the alias is unique, it won't matter if the pagetitle is unless you need to search by pagetitle.

      I'd recommend against putting the user's ID in the alias if you can possibly avoid it, although you could encrypt it in some reversible way. You also need to make sure the fullname isn't empty before using it.

      You can check search by pagetitle or alias in your code to see if it's already in use.

      If the user changes the profile, the page would not be updated. You could check for changes in a plugin connected to OnDocFormSave and update the resource there, but it's somewhat tricky and links to the page outside of the site would fail.

      Another way would be to hide the fullname field in the Create/Edit User form with Form Customization so the user couldn't change it (or just keep them in the front end and leave that field out of the UpdateProfile operation).
        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
        • 34103
        • 47 Posts
        istvan.velsz Reply #13, 8 years ago
        For the moment my more important problem is the blank page the users get if they confirm the registration - with your plugin active. Any idea?

        Thanks
          • 3749
          • 24,544 Posts
          That plugin code was inside a class. It has to be modified to run on its own, Try this:

          <?php
          /* Attach to OnUserActivate System Event */
           
          $profile = $modx->getObject('modUserProfile', array('internalKey' => $user->get('id')));
          $fullName = $profile->get('fullname');
          $pagetitle = $fullName;
          $parentId = 12;  /* ID of parent container */
          $template = 5;   /* ID of page template */
           
          $fields = array(
              'parent' => $parentId,
              'pagetitle' => $pagetitle,
              'menutitle' => $fullname,
              'longtitle' => '',
              'introtext' => '',
              'published' => '1',
              'hidemenu' => '1',
              'cacheable' => '1',
              'searchable' => '0',
              'template' => $template,
          );
          /* Make sure it doesn't exist already */
          $resource = $modx->getObject('modResource', array('pagetitle' => $pagetitle));
          if (! $resource) {
              $resource = $modx->newObject('modResource');
              $resource->fromArray($fields);
              $resource->setContent($modx->getChunk('ResourceContent'));
              $resource->set('alias', $resource->cleanAlias($pagetitle));
                 if (! $resource->save()) {
                       $modx->log(modX::LOG_LEVEL_ERROR, 'Could not save resource');
                 }
          }
          $modx->reloadContext('web');
          return;
          

          [ed. note: BobRay last edited this post 8 years ago.]
            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
            • 34103
            • 47 Posts
            istvan.velsz Reply #15, 8 years ago
            No, it doesn't make any difference. But it seams this first line is the reason. If I delete all other lines I will get a blank page too. No error output in the error log. Are you sure you will get the Profile from the user which is getting activated? How can the plugin know which user will be activated? In my understanding your plugin will get the id from the currently logged on user.

            I have another idea. In my case the user first registers and activates himself. But after that he has to complete his profile. In this case he is logged on and the »onUserSave« Event will be fired - or I wrong? In this case the page could be created after editing the profile for the first time. Depending on the mode an new page could be created or would only be updated. Or it could be a post hook in the »UpdateProfile« snippet.

            Sorry but I'm not a developer just have a understanding in development principles.
              • 3749
              • 24,544 Posts
              Sorry, you're right. It's missing a final parenthesis. It should be:
              $profile = $modx->getObject('modUserProfile', array('internalKey' => $user->get('id')));


              Yes, it could be done in other ways, but I think this is the simplest.
                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
                • 34103
                • 47 Posts
                istvan.velsz Reply #17, 8 years ago
                Now it works, after finding a second missing parenthesis end of line 27:
                $resource->setContent($modx->getChunk('ResourceContent'));


                But now back to the alias problem. If I only use fullname in pagetitle and in alias an error could be possible, because the fullname is not unique. I believe it could be a solution to save fullname and id in alias only.

                And how to save the user id in the resource. Can I store it in a TV? With the stored id I could load the user profile dynamically and no reserve of the document is needed after profile update. Or ist there a short posthook to reserve the resource.
                  • 3749
                  • 24,544 Posts
                  Sorry about that. wink

                  My code editor completes parentheses automatically, so I often forget the closing one when entering code freehand.

                  I would not expose the user ID or username in the alias, but you certainly can if you're not that worried about security. A compromise would be this:

                  $alias = $resource->cleanAlias($pagetitle) . base64_encode($userId);


                  To store the user ID in the page, you could use a TV, but it would be much faster and easier if you're not using one of these resource fields: description, introtext, longtitle, or menutitle, to just put it in that unused field.

                  Remember that if you want to get a user's profile with the user ID, you have to retrieve it through the 'internalKey' field of the profile:

                  $profile = $modx->getObject('modUserProfile', array('internalKey' => $userID));


                  If it's for the current user, you can do this:

                  $profile = $modx->user->getOne('Profile');


                  If you have the user object, you can do this:

                  $profile = $user->getOne('Profile');


                  If the user has just been created, sometimes getOne() will put an annoying error in the Error Log. In that case, just use the internalKey version.
                    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
                    • 34103
                    • 47 Posts
                    Hi Bob,

                    sorry, but I have a problem, which I have overseen probably. While the registration process all extended fields, which I have created with class extender, will saved correctly. But in update profile the data of these fields were shown but wouldn't be saved. Here my call:
                    		[[!ExtUserUpdateProfile]]
                    		[[!UpdateProfile?
                    			&submitVar=`login-updprof-btn`
                    			&useExtended=`0`
                    			]]


                    I checked if there is a problem with the submitVar, but everything seams correct. The normal fields will be stored. Did I need a postHook? Or is there a other problem?
                      • 34103
                      • 47 Posts
                      Seems the I solved this problem. I renamed the value of the button. After changing the value of the submit button back to the lexicon entry, it works. All data will saved in the database.