We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Thanks Bob, yes it does work in terms of putting a line in Managers Log.

    I’ve never written a snippet, but I’ll give it a go and let you now how I get on!

    Users should be created through front-end, so from what you say they are existing users awaiting activation. Obviously it would be useful to have that extra bit of code if required for another user as I’m sure I can’t be the only one looking for a way of notifying users that they are active.

    I guess this could also be used to block a user and let them know that their account has been suspended too by changing activate_user to block_user ?

    Appreciate the help. smiley
      Helen Warner
      Number one pixel!
      Proud to be linked with MODX at Crimson Pixel
      • 3749
      • 24,544 Posts
      You’re right about blocking.

      I’m working on a Transport Package that will do what you want, but it may be a while before it’s available. In the meantime, here’s a simplified version of the email code. Put it in a snippet first until you get it the way you want it, then paste it into the plugin.

      <?php
          $name = $user->get('username');
          $msg = "<p>Dear " . $name . ", Thank you for registering at " . $modx->getOption('site_name',null,'My Site') . ".</p>";
          $msg .= "<p>You have been activated and can now access all restricted pages.</p>";
          $subject = 'Activation';
      
      
          $modx->getService('mail', 'mail.modPHPMailer');
          $modx->mail->set(modMail::MAIL_BODY, $msg);
          $modx->mail->set(modMail::MAIL_FROM, $modx->getOption('emailsender'));
          $modx->mail->set(modMail::MAIL_FROM_NAME, $modx->getOption('site_name'));
          $modx->mail->set(modMail::MAIL_SENDER, $modx->getOption('emailsender'));
          $modx->mail->set(modMail::MAIL_SUBJECT, $subject);
          $modx->mail->address('to', $email, $name);
          $modx->mail->address('reply-to', $modx->getOption('emailsender'));
          $modx->mail->setHTML(true);
          $sent = $modx->mail->send();
          $modx->mail->reset();
      
        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
      • That was quick - I’ve just been reading your pages re snippets trying to get a better understanding of how that side of Modx works.

        I will eventually get there because as someone rightly states in one of the many wiki / websites / addon pages etc that I’ve scanned, read and downloaded today once you get past the scary bit of diving in to creating snippets, it will only add to your arsenal for creating bespoke websites.

        I’ll let you know how I get on with the code you’ve added today. grin
          Helen Warner
          Number one pixel!
          Proud to be linked with MODX at Crimson Pixel
        • Bob you are brilliant! I couldn’t quite get the code to work as a snippet, so decided to go ahead and plonk it straight into the plugin and SUCCESS! I can now email newly activated users.

          As you may have guessed this site isn’t quite live, it is due to launch early Jan 2010 and getting the restricted area right is essential - client is a Police Association group!

          I have got a couple of other issues with Login which I’ve posted separately but I’m now so much closer to getting things working the way this client would like.

          Thank you for your time. grin

          Sorry just one more thing - how would I go about adding a url to the msg body - I have tried a variety of options but can’t seem to get the right string.
            Helen Warner
            Number one pixel!
            Proud to be linked with MODX at Crimson Pixel
            • 3749
            • 24,544 Posts
            This worked fine for me:

            $msg = ’This is the message. Here is the URL: <a href="http//bobsguides.com">Bobs Guides</a>’;

            Be sure to use single quotes on the outside and double quotes on the inside (only one pair of each). setHTML must be true. If that doesn’t do it, just post the code here that you’re having trouble with.
              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
              • 14877
              • 110 Posts
              OK, so what are you guys doing to make this work?

              I went to the end solution and made some changes (essentially templated the plugin e-mail message) and... nothing.

              After a lot of mucking around, including adding "$modx->log(modX::LOG_LEVEL_ERROR,’OnBeforeUserFormSave Debug(1): For...", I came to the conclusion the plugin wasn’t being run. Thinking I might have made some stupid coding error, I copy-and-pasted Bob’s code into my plugin (the code that only logs a manager action and has a comment instead of sending an e-mail message).

              Guess what? there are absolutely no "activate_user" messages in my manager log. I’ve got the plugin tied to the OnBeforeUserFormSave event (I know how to do this as I have a previously developed plugin running just fine).

              So, what am I missing?
                __________________
                JRG
                • 3749
                • 24,544 Posts
                Plugins are notoriously hard to debug unless you have a debugger that will let you set breakpoints in the plugin and launch the manager.

                Try implementing it as a snippet first that’s triggered with a snippet tag on a regular page. Set the necessary variables in parameters or at the top of the snippet. Once it’s working, paste it to your plugin.

                If you’re not sure about your email capabilities, download the new QuickEmail snippet to test them.
                  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
                  • 14877
                  • 110 Posts
                  Quote from: BobRay at Jan 10, 2011, 02:18 AM

                  Plugins are notoriously hard to debug unless you have a debugger that will let you set breakpoints in the plugin and launch the manager.

                  Try implementing it as a snippet first that’s triggered with a snippet tag on a regular page. Set the necessary variables in parameters or at the top of the snippet. Once it’s working, paste it to your plugin.

                  If you’re not sure about your email capabilities, download the new QuickEmail snippet to test them.

                  The other plugin I mentioned gets user info and sends an e-mail message just fine. A copy-and-paste of your working example, doesn’t work for me. That’s what is bothering me!
                    __________________
                    JRG
                    • 3749
                    • 24,544 Posts
                    Did you notice that there are two parts to the plugin? This part:

                    <?php
                    if ($mode == modSystemEvent::MODE_UPD) {
                        if ( ! $user->get('active') && $_POST['active'] ) { 
                            $modx->logManagerAction('activate_user','modUser',$user->get('id'));
                            $email = $_POST['email']; 
                            /* Code to Send email goes here */
                        }
                    }


                    And the part that sends the email (which gets pasted exactly where the comment is)? I pasted both from working code, although It’s possible that something has changed in newer releases of 2.x.
                      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
                    • I am still aiming to put together a guideline on my experience with Login and using this plugin, just been super busy of late.
                      In the meantime below is some of my experience using Login (currenly on release 1.5.2)

                      I have followed all the instructions regarding setting up a registration page except as I didn’t want people to register automatically, so firstly I changed the response email to my own chunk. I used the following call on my registration page:

                      [[!Register? &submitVar=`registerbtn` &activationEmailTpl=`myRegistrationEmail` &activationEmailSubject=`Registration Submitted` &submittedResourceId=`17` &usergroups=`PrivateUserGroup` &postHooks=`hookNotifyAdminEmail` ]]

                      The custom chunk is myRegistrationEmail as follows:

                      <p>Hi, [[+username]],</p>

                      <p>Thanks for registering! Your application will be reviewed. On acceptance you will receive a confirmation email with details of where to login.</p>
                      <p>The password you registered was <strong>[[+password]]</strong> and your username is <strong>[[+username]]</strong>. Please keep these safe as you will require them when you are approved for login.</p>

                      <p>Kind regards,

                      <em>Site Administrator</em></p>

                      Instructions on the &postHooks=`hookNotifyAdminEmail` can be found in the Login documentation under Post Hooks. This allows notification to the Site Administrator that someone has registered on to site.

                      I then made use of the plugin the Bob provided using the following code:

                      <?php
                      if ($mode == modSystemEvent::MODE_UPD) {
                      if ( ! $user->get(’active’) && $_POST[’active’] ) {
                      $modx->logManagerAction(’activate_user’,’modUser’,$user->get(’id’));
                      $email = $_POST[’email’];
                      $name = $user->get(’username’);
                      $msg = "<p>Dear " . $name . ",</p>
                      <p>Thank you for registering at " . $modx->getOption(’site_name’,null,’My Site’) . ".</p>
                      <p>Your registration has been approved and you now access the Members area, please login <a href=’http://www.mywebsite.co.uk/login’>here</a>.</p>";
                      $msg .= "<p>Kind Regards,
                      Site Administrator</p>";
                      $subject = ’Registration Approved’;


                      $modx->getService(’mail’, ’mail.modPHPMailer’);
                      $modx->mail->set(modMail::MAIL_BODY, $msg);
                      $modx->mail->set(modMail::MAIL_FROM, $modx->getOption(’emailsender’));
                      $modx->mail->set(modMail::MAIL_FROM_NAME, $modx->getOption(’site_name’));
                      $modx->mail->set(modMail::MAIL_SENDER, $modx->getOption(’emailsender’));
                      $modx->mail->set(modMail::MAIL_SUBJECT, $subject);
                      $modx->mail->address(’to’, $email, $name);
                      $modx->mail->address(’no-reply-to’,’’);
                      $modx->mail->setHTML(true);
                      $sent = $modx->mail->send();
                      $modx->mail->reset();
                      }
                      }

                      I also selected under System Events onBeforeUserFormSave and everything works fine.

                      I am currently using Rev 2.0.4 as this site is being developed and will hopefully move this week to its own domain with Rev 2.0.6. I will test the manual activation again at that point and let you know if I experience any problems.

                      TIP: One thing I did find a little frustrating at first when using Login was that if I modified the chunks that came with the snippet any updates would overwrite my changes, so now I have created my own templates to prevent this from happening.

                        Helen Warner
                        Number one pixel!
                        Proud to be linked with MODX at Crimson Pixel