<![CDATA[ How to automatically login a web user after registration? - My Forums]]> https://forums.modx.com/thread/?thread=43980 <![CDATA[Re: How to automatically login a web user after registration?]]> https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=3#dis-post-558515
Quote from: markh at Mar 28, 2018, 10:20 AM

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

]]>
nuan88 May 12, 2018, 03:39 PM https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=3#dis-post-558515
<![CDATA[Re: How to automatically login a web user after registration?]]> https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-557761 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!]]>
ket3112 Apr 02, 2018, 09:33 PM https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-557761
<![CDATA[Re: How to automatically login a web user after registration?]]> https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-557708 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.]]>
nuan88 Mar 28, 2018, 07:27 PM https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-557708
<![CDATA[Re: How to automatically login a web user after registration?]]> https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-557697 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.]]>
markh Mar 28, 2018, 10:20 AM https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-557697
<![CDATA[Re: How to automatically login a web user after registration?]]> https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-557675 ]]> nuan88 Mar 27, 2018, 01:51 PM https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-557675 <![CDATA[Re: How to automatically login a web user after registration?]]> https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-456447
The ActivationEmail plugin might have sent the email for you, but what you're doing looks perfect.]]>
BobRay Feb 25, 2013, 12:04 AM https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-456447
<![CDATA[Re: How to automatically login a web user after registration?]]> https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-456397
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.


]]>
rethrash Feb 24, 2013, 02:17 PM https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-456397
<![CDATA[Re: How to automatically login a web user after registration?]]> https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-456358 BobRay Feb 23, 2013, 10:27 PM https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-456358 <![CDATA[Re: How to automatically login a web user after registration?]]> https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-456345 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>
]]>
rethrash Feb 23, 2013, 06:34 PM https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-456345
<![CDATA[Re: How to automatically login a web user after registration?]]> https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-456261 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);
}
]]>
rethrash Feb 22, 2013, 07:07 PM https://forums.modx.com/thread/43980/how-to-automatically-login-a-web-user-after-registration?page=2#dis-post-456261