We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32025
    • 305 Posts
    Dayton Web Design Reply #1, 11 years ago
    I have login installed and have the basic setup, and registration working as well. Very close to this set up(http://rtfm.modx.com/display/ADDON/Login.Request+Membership) All is working fine except one thing: We don't want people who register to get an e-mail with a confirmation link for auto approval. We want to approve them to make sure they are legitimate first. We just want them to go to the snipplet page that tells them to wait for approval, while we approve their account.

    I can figure out how to change the redirect page (after successful register) to tell them to wait for approval. And I can remove the email activation coding from the register page (&activationEmailTpl=`lgnActivateEmailTpl`) so they do not get the approval e-mail, with the confirmation link. So this by nature would stop the visitors from getting automatic approval.

    What I don't know is how to make the form notify the admin when someone signs up (so we can approve each person). And if possible when we approve each account, have an e-mail notify them they have been approved. Is this an easy fix?
      Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
      • Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 3749
        • 24,544 Posts
        The ActivationEmail extra can help with the email on approval.
          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
          • 32025
          • 305 Posts
          Dayton Web Design Reply #4, 11 years ago
          OK half my problem solved with the ActivationEmail extra. Awesome. As far as my last problem that is notifying the admin when someone signs up. I don't want to be redundant, but BobRay posted this in another post:

          The problem with your plan is that there's no way to verify the user's email address, which is the point of the Activation Email. I can think of some ways to deal with that:

          1. Modify the ConfirmRegister snippet to *not* activate the user but send an email to the admin, as described in the link above.

          2. Let the user self-activate and deactivate users you don't like.

          3. Insert the admin's email address in the emailTpl chunk (and in the from and reply-to fields) with a message to "reply to this message to request activation." Make sure the user's username is also in the message.

          Option #1 would be ideal for me, but I do not know how to go about this. Option #2 is not good, and option #3 could be a last resort if I cannot get option #1 to work. So with this:
          1. Modify the ConfirmRegister snippet to *not* activate the user but send an email to the admin, as described in the link above.

          How would I go about adding this? After follwing that post attached it seems like the person added custom PHP coding to the registration snipplet for the workaround, but did not provide the coding. It looks like the ConfirmRegister snipplet has very little code currently, but Custom PHP coding is out of my skillset. Is this added code a simple line or two? If not, is there an simpler way that maybe I can do that does not require PHP?
            Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
            • 32025
            • 305 Posts
            Dayton Web Design Reply #5, 11 years ago
            I suppose the first step would be to disable the confirmation links ability to auto approve. Then the second step would be to trigger an e-mail to admin after they click the confirmation link.

            I have it set up so when someone registers, they still get the confirmation e-mail. Then when they click the confirm link, I changed the membership confirmation handler to redirect to another that says: Wait for manual approval. The problem is the approval link still approves their account which gives them instant access. So I want to use the approval link, so the members can confirm they are real, but I do not want it to approve their account.

            In looking at: core/components/login/processors/register.php I did not find this coding (per an old post):
            $user->set('active',1);
                $user->save();


            I am thinking I need to turn something from 1 to 0 or from true to false so the confirmation link does not active the user. Basically just using the confirmation link to trigger an admin e-mail. In looking through the code of the register.php I do not know which one to change to deactivate the approval. Any suggestions?
              Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
              • 32025
              • 305 Posts
              Dayton Web Design Reply #6, 11 years ago
              For those following: I was able to turn off auto approval. Go to: core/components/login/controllers/web/ConfirmRegister.php and around line: #56 found this:
              /* activate user */
                      $this->user->set('active',1);


              changed to this:
              /* activate user */
                      $this->user->set('active',0);


              And the system still worked (that is during registration I was redirected to the wait for approval page, after I clicked the confirmation link, and I was not automatically approved. Yeah!! The only thing left is, how can I trigger an e-mail notifying the admin after a new registrar clicks this activation link? Or at the least notify admin after someone fills out the registration form?
                Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
                • 3749
                • 24,544 Posts
                Since you're already modifying the confirmRegister controller, you should be able to drop something like this in just below the change you made:


                $username = $user->get('username');
                $adminEmail = '[email protected]';
                
                $modx->getService('mail', 'mail.modPHPMailer');
                $modx->mail->set(modMail::MAIL_BODY, $username . ' has submitted the registration form');
                $modx->mail->set(modMail::MAIL_FROM, $adminEmail);
                $modx->mail->set(modMail::MAIL_FROM_NAME, $modx->getOption('site_name');
                $modx->mail->set(modMail::MAIL_SENDER, $adminEmail);
                $modx->mail->set(modMail::MAIL_SUBJECT, 'New Registration);
                $modx->mail->address('to', $to, $adminEmail);
                $modx->mail->address('reply-to', $adminEmail);
                $sent = $modx->mail->send();


                If you need more than the username in the message, you'll have to get the User Profile at the top:

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

                if ($profile) {
                $email = $profile->get('email');
                $fullname = $profile->get('fullname');
                // etc.

                }
                  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
                  • 32025
                  • 305 Posts
                  Dayton Web Design Reply #8, 11 years ago
                  Thank you for your time BobRay. I pasted the code above into my ConfirmRegister controller and I got a few syntax errors. I did not add the user profile on top, because the username and notification should be sufficient. This was the original code:
                   public function process() {
                          $this->verifyManifest();
                          $this->getUser();
                          $this->validatePassword();
                  
                          $this->onBeforeUserActivate();
                  
                          /* activate user */
                          $this->user->set('active',1);
                          $this->user->set('cachepwd','');
                          if (!$this->user->save()) {
                              $this->modx->log(modX::LOG_LEVEL_ERROR,'[Register] Could not save activated user: '.$this->user->get('username'));
                              return '';
                          }
                          
                          /* invoke OnUserActivate event */
                          $this->modx->invokeEvent('OnUserActivate',array(
                              'user' => &$this->user,
                          ));
                  
                          $this->addSessionContexts();
                  
                          $this->redirectBack();
                          return '';
                      }


                  And this is the code after I pasted the coding you supplied:
                   public function process() {
                          $this->verifyManifest();
                          $this->getUser();
                          $this->validatePassword();
                  
                          $this->onBeforeUserActivate();
                  
                          /* activate user */
                          $this->user->set('active',0);
                          $this->user->set('cachepwd','');
                          if (!$this->user->save()) {
                              $this->modx->log(modX::LOG_LEVEL_ERROR,'[Register] Could not save activated user: '.$this->user->get('username'));
                              return '';
                         	}
                  		
                  	/* send email to admin - custom coding added */
                  	$username = $user->get('username');
                          $adminEmail = '[email protected]';
                  
                          $modx->getService('mail', 'mail.modPHPMailer');
                          $modx->mail->set(modMail::MAIL_BODY, $username . ' has submitted the registration form');
                          $modx->mail->set(modMail::MAIL_FROM, $adminEmail);
                          $modx->mail->set(modMail::MAIL_FROM_NAME, $modx->getOption('site_name');
                          $modx->mail->set(modMail::MAIL_SENDER, $adminEmail);
                          $modx->mail->set(modMail::MAIL_SUBJECT, 'New Registration);
                          $modx->mail->address('to', $to, $adminEmail);
                          $modx->mail->address('reply-to', $adminEmail);
                          $sent = $modx->mail->send();
                  
                  					 
                          /* invoke OnUserActivate event */
                          $this->modx->invokeEvent('OnUserActivate',array(
                              'user' => &$this->user,
                          ));
                  
                          $this->addSessionContexts();
                  
                          $this->redirectBack();
                          return '';
                      }


                  According to Dreamweaver these lines are showing the red syntax errors:
                  $modx->mail->set(modMail::MAIL_FROM_NAME, $modx->getOption('site_name');
                  $modx->mail->address('to', $to, $adminEmail);
                  $modx->mail->address('reply-to', $adminEmail);
                  


                  The error I get is: "Dynamically-related files cannot be discovered because there is no site definition for this document". The errors flow all the way down the page. I have a suspicion I pasted in the wrong spot or a character is wrong. Any ideas?
                    Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
                    • 3749
                    • 24,544 Posts
                    Dreamweaver is not the best code editor, but there are a couple of syntax errors from my bad typing.

                    Try this:

                    $username = $user->get('username');
                    $adminEmail = '[email protected]';
                    $to = $adminEmail;    
                    
                    $modx->getService('mail', 'mail.modPHPMailer');
                    $modx->mail->set(modMail::MAIL_BODY, $username . ' has submitted the registration form');
                    $modx->mail->set(modMail::MAIL_FROM, $adminEmail);
                    $modx->mail->set(modMail::MAIL_FROM_NAME, $modx->getOption('site_name'));
                    $modx->mail->set(modMail::MAIL_SENDER, $adminEmail);
                    $modx->mail->set(modMail::MAIL_SUBJECT, 'New Registration');
                    $modx->mail->address('to', $to, $adminEmail);
                    $modx->mail->address('reply-to', $adminEmail);
                    $sent = $modx->mail->send();
                    
                      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
                      • 32025
                      • 305 Posts
                      Dayton Web Design Reply #10, 11 years ago
                      The syntax errors are gone, but there is one more issue during testing. When I test on the front end, the page membership confirmation handler page goes blank and shows this error:

                      Fatal error: Call to a member function get() on a non-object in /MYROOT/html/core/components/login/controllers/web/ConfirmRegister.php on line 64

                      Line 64 is this code supplied:
                      $username = $user->get('username');


                      Seems to be very close.

                        Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/