We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53932
    • 33 Posts
    It's getting me null output. Not sure why.
    output: string(0) ""
      • 53932
      • 33 Posts
      One more question, Is there a way to trigger an email to user as soon as user account gets blocked?
        • 3749
        • 24,544 Posts
        My bad, the processors path should end in a slash.

        There's no easy way to trigger an email.

        I would put the email code in your controller, or wherever you can figure out that the user has been blocked.

        Something like this:

        $modx->getService('mail', 'mail.modPHPMailer');
        $modx->mail->set(modMail::MAIL_BODY, 'Some message');
        $modx->mail->set(modMail::MAIL_FROM, '[email protected]');
        $modx->mail->set(modMail::MAIL_FROM_NAME, 'Your Name');
        $modx->mail->set(modMail::MAIL_SENDER, '[email protected]');
        $modx->mail->set(modMail::MAIL_SUBJECT, 'Some Subject');
        $modx->mail->address('to', '[email protected]', 'UserName');
        $modx->mail->address('reply-to', '[email protected]');
        $modx->mail->setHTML(true);
        $sent = $modx->mail->send();
        if ($sent) {
            $output = 'Mail Sent';
        } else {
            $output = 'Mail Not Sent';
        }
        return $output;
          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
          • 53932
          • 33 Posts
          In order to send an email when user got blocked, which has to happen before actual login occurs, so trying to capture user profile details as below but below are giving null results. Am I missing anything?

          [[!Profile]]
          <p>Username: [[+username]]</p>
          <p>Email: [[+email]]</p>
          <p>State: [[+state]]</p>

          [[!login.script.php? &loginTpl=`lgnLoginToMemberPageTpl` &logoutTpl=`blank` &logoutResourceId=`1` &contexts=`web`]]
          [ed. note: rajani last edited this post 8 years, 8 months ago.]
            • 3749
            • 24,544 Posts
            Yes, until they log in with the correct credentials, MODX has no idea who they are. You could try a search for users with the same username. If that works, you can get the email address, but if a hacker guesses a username, you've got a problem. It's not really practical to look for users with a similar password.

            Until a successful login, they are the (anonymous) user and that user gets blocked after too many failed login attempts, but that user has no user profile -- so no email address.

            Also, sending an email that contained a new password any time someone made a few failed login attempt would create a pretty significant security vulnerability.

            You might do what some sites do, which is to have two separate pages (with links that show up on the Login form after x number of failed logins), one for "Forgot Username" and another for "Forgot Password." On those pages, you'd have a form that let them enter what they know and check the database for matches - then send the email. It's still something of a security problem, so the more information you have on the form (state, phone, zip, email, username, etc.) the better.
              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
              • 53932
              • 33 Posts
              Yes, agreed.

              As current system is saying that when user gets blocked - user blocked by manager by admin. To avoid contacting admin for unblocking user alternatively, would want to send an activation(unblocked) link thru email in custom class instead of modifying the MODX core files (to avoid losing content during upgrades).

              1. For this, can I overwrite the language context for blocked user in a 'custom file' instead MODX lexicon file?
              2. FYI - After placing the slash at the end of processors path, it's giving "<" as output. Not sure what else i'm missing there.
                • 3749
                • 24,544 Posts
                If what the user actually sees on the final bad login is 'You have been blocked from the manager by an administrator.'

                I might work to modify the lexicon entry by going to System (gear icon) -> Lexicons, namespace: core, topic:login, and changing that message to:

                [[!SendUnblockMessage]]


                That will survive upgrades to MODX.

                Then write your own snippet to send whatever email you want. *But* how will you find the user when the credentials are wrong, and how will you make sure the user is not some hacker randomly trying usernames and emails?

                Post some of your code with the processors path.
                  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
                  • 53932
                  • 33 Posts
                  Thanks for the response Bob. I think the above idea is not impacting the MODX upgrades which is good but i don't know answers for your questions.

                  Finally, I have implemented the code in such a way that, after the controller of login processed then I'm able to get the $_POST details. From here we can get all the user profile details and sending an email to the login user with a link with random code. Once we click on the link, it unblocks the user and able to login successfully. Below is the script for it.

                  $login = new Login($modx,$scriptProperties);
                  if (!is_object($login) || !($login instanceof Login)) return '';
                  
                  $controller = $login->loadController('Login');
                  $output .= $controller->run($scriptProperties);
                  
                  //If login failed, retrieves users details and sends an email to user if blocked with too many failed attempts.
                  if(!$controller->isAuthenticated)
                  {
                      $username =  $_POST['username'] ;
                      $user = $modx->getObject('modUser', array('username' => $username,));
                      
                      if (isset($user) && ( $user->get('active') )) 
                      {
                          $uid = $user->get('id');
                          $profile = $user->getOne('Profile');
                          if (isset($profile)) 
                          {
                              $email = $profile->get('email');
                              $fullname = $profile->get('fullname');
                              $blocked = $profile->get('blocked');
                          }
                          if($blocked)
                          {
                             echo '<div><p>Your account has been blocked due to too many failed logins. An email has been sent to your account to unblock the user account.</p></div>';
                              send_user_email($modx, $email, $fullname, $uid, $username);  
                              $output = "";
                          }
                      }
                  }
                  return $output;


                  Bob - Big thanks for all the quick responses.
                    • 3749
                    • 24,544 Posts
                    You're welcome. smiley
                      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