We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40024
    • 72 Posts
    Hello. I am looking for the same thing(i mean, to automatically login a web user after registration).
    I don't know much of php and webloginPE didn't work for me before, so i was wondering if anyone managed to implement it via the original weblogin which comes bundled with the modx installation.
    • Quote from: Kristoffer at Jul 06, 2011, 01:30 PM
      This solution is valid for Revo vith Login snippet (Register).

      I'm using this snippet as a postHook for Register and it works just fine for me. The code is borrowed from Login.

      Thanks for providing this guidance. It almost worked but the following tweaks made it work for me as expected (hat tip to Nikolay Lanets):

      $user = $hook->getValue('register.user');
      if ($user == null) { return false; }
      
      // get user
      $modx->user =& $user;
      
      // set session context(s) to log into
      $contexts = !empty($scriptProperties['authenticateContexts']) ? $scriptProperties['authenticateContexts'] : $modx->context->get('key');
      $contexts = explode(',',$contexts);
      foreach ($contexts as $ctx) {
          $modx->user->addSessionContext($ctx);
      }
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
      • My dad, who this auto-login-fu is for, also wanted a custom activation email reminder sent to them, too. It was a lot trickier than I expected, but here's what worked for anyone wanting something similar. This time Andrew Smith helped me not be a complete eejit.

        <?php
        $user = $hook->getValue('register.user');
        if ($user == null) { return false; }
        
        // get user
        $modx->user =& $user;
        
        // set session context(s) to log into
        $contexts = !empty($scriptProperties['authenticateContexts']) ? $scriptProperties['authenticateContexts'] : $modx->context->get('key');
        $contexts = explode(',',$contexts);
        foreach ($contexts as $ctx) {
            $modx->user->addSessionContext($ctx);
        }
        
        // email them the account creation confirmation message
        $userdata = array(
            'user' => $hook->getValue('username'),
            'pass' => $hook->getValue('password'),
            'fullname' => $hook->getValue('fullname')
        );
        $msg = $modx->getChunk('rcAutoLgnConfirmTpl',$userdata);
        $modx->user->sendEmail($msg);


        My rcAutoLgnConfirmTpl chunk:
        <p>Hi [[+fullname]],</p>
        
        <p>
        Thank you for registering as a wholesale customer at example.com. Your wholesale account has been activated, and you may immediately log in and place orders using the following username and password:
        </p>
        
        <p>
        Login at: <a href="http://www.example.com/login/">example.com</a><br />
        Username: <strong>[[+user]]</strong><br />
        Password: <strong>[[+pass]]</strong></p>
        
        <p>If you have questions or we can assist you in any way, please just reply to this email or call us at 866-555-1212.</p>
        
        <p>Sincerely,<br />
        <em>The Customer Service Team</em><br>
        214-555-1212 / 866-555-1212<br>
        <a href="mailto:[email protected]">[email protected]</a>
        </p>
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 3749
          • 24,544 Posts
          Am I missing something (I often am)? The register snippet for Revolution will send an automatic email to registrants with a registration link, and the ConfirmRegister snippet will log them in automatically when they click on it. The Subscribe package will set the whole thing up for you pretty much out-of-the-box (if you don't mind restyling it to match your site, or vice versa).
            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's exactly the way the default Snippets work. But the "client" (my dad) is working with a technically-naive user base. Sometimes the confirmation wound up in spam and they don't know how to find it. Or, they missed the activation link entirely in the email. They sometimes call and complain about not being able to log in, and then they order over the phone. I suspect a whole lot of times, they just silently walk away and just don't order anything.

            Auto-registering skips this barrier to conversion. They're instantly registered and logged into their new account, and they can purchase case-quantities and above without trouble. This is for wholesale orders-only, no account required to buy at retail.

            To achieve this, I turned off the standard confirmation email since its purpose was to verify the email address and to activate the account. But Dad still wanted them to have a record of their account being created, hence the secondary step of sending them the email in the autoLogin snippet. Here's the call:

            [[!Register?
                &submitVar=`registerbtn`
                &submittedResourceId=`14`
                &usergroups=`Registered Users` 
            
                &activation=`0`
                &activationResourceId=`15`
                &activationEmailTpl=`rcActivateEmailTpl`
                &activationEmailSubject=`Thanks for Registering!`
            
                &customValidators=`alnum`
            
                &postHooks=`autoLogin`
            ]]


            It's a subtly different workflow than one I'd recommend the majority of the time and that works by default with the Register/Login stuff. Hopefully it should significantly help people have the privilege of giving my Dad's business money. wink

            FYI, the activation email subject is still used for the email that gets sent which I found mildly curious. But we were happy that it worked as desired and didn't dig further.


            [ed. note: rethrash last edited this post 11 years, 1 month ago.]
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 3749
              • 24,544 Posts
              Ah . . . I get it now. The activation email subject is probably used because all properties of Register are passed through to any hooks.

              The ActivationEmail plugin might have sent the email for you, but what you're doing looks perfect.
                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
                • 46886
                • 1,154 Posts
                This old gem is relevant to my interests wink
                • Mark Hamstra Reply #18, 6 years ago
                  Quote from: nuan88 at Mar 27, 2018, 01:51 PM
                  This old gem is relevant to my interests wink

                  so you just revived a 5 year old topic? tongue

                  This is in the docs - add &activation=`0` and &autoLogin=`1` to your register snippet and users will be instantly verified and logged in.
                    Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                    Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                    • 46886
                    • 1,154 Posts
                    Quote from: markh at Mar 28, 2018, 10:20 AM
                    Quote from: nuan88 at Mar 27, 2018, 01:51 PM
                    This old gem is relevant to my interests wink

                    so you just revived a 5 year old topic? tongue

                    This is in the docs - add &activation=`0` and &autoLogin=`1` to your register snippet and users will be instantly verified and logged in.

                    Thanks Mark! I meant no harm smiley

                    I wanted to be sure what state the account would be in. Automatically activating the account looks like a good method to avoid user issues! I still plan to use the email confirmation though heh, make em work a bit for it.
                      • 54171
                      • 7 Posts
                      Quote from: rethrash at Feb 24, 2013, 02:17 PM
                      That's exactly the way the default Snippets work. But the "client" (my dad) is working with a technically-naive user base. Sometimes the confirmation wound up in spam and they don't know how to find it. Or, they missed the activation link entirely in the email. They sometimes call and complain about not being able to log in, and then they order over the phone. I suspect a whole lot of times, they just silently walk away and just don't order anything.

                      Auto-registering skips this barrier to conversion. They're instantly registered and logged into their new account, and they can purchase case-quantities and above without trouble. This is for wholesale orders-only, no account required to buy at retail.

                      To achieve this, I turned off the standard confirmation email since its purpose was to verify the email address and to activate the account. But Dad still wanted them to have a record of their account being created, hence the secondary step of sending them the email in the autoLogin snippet. Here's the call:

                      [[!Register?
                          &submitVar=`registerbtn`
                          &submittedResourceId=`14`
                          &usergroups=`Registered Users` 
                      
                          &activation=`0`
                          &activationResourceId=`15`
                          &activationEmailTpl=`rcActivateEmailTpl`
                          &activationEmailSubject=`Thanks for Registering!`
                      
                          &customValidators=`alnum`
                      
                          &postHooks=`autoLogin`
                      ]]


                      It's a subtly different workflow than one I'd recommend the majority of the time and that works by default with the Register/Login stuff. Hopefully it should significantly help people have the privilege of giving my Dad's business money. wink

                      FYI, the activation email subject is still used for the email that gets sent which I found mildly curious. But we were happy that it worked as desired and didn't dig further.


                      thank you for the detailed description!