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.
…
$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); }
<?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);
<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>
[[!Register? &submitVar=`registerbtn` &submittedResourceId=`14` &usergroups=`Registered Users` &activation=`0` &activationResourceId=`15` &activationEmailTpl=`rcActivateEmailTpl` &activationEmailSubject=`Thanks for Registering!` &customValidators=`alnum` &postHooks=`autoLogin` ]]
This old gem is relevant to my interests
Quote from: nuan88 at Mar 27, 2018, 01:51 PMThis old gem is relevant to my interests
so you just revived a 5 year old topic?
This is in the docs - add &activation=`0` and &autoLogin=`1` to your register snippet and users will be instantly verified and logged in.
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.thank you for the detailed description!
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.
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.