<p>After following the stack trace for activating a user (with the link), I discovered that activation fails at /craft/app/services/UsersService.php:822:</p>

<pre><code>820:   public function verifyEmailForUser(UserModel $user)
821:   {
822:      if ($user-&gt;unverifiedEmail)
823:      {
</code></pre>

<p>Apparently I needed to set the unverifiedEmail property when creating "Pending" users via a plugin as opposed to only setting the 'pending' property to false.</p>

<pre><code>$user = new UserModel();
$user-&gt;email = 'pendinguser@email.com;
// ... set other properties
$user-&gt;pending = false;
$user-&gt;unverifiedEmail = '';
</code></pre>

CC BY-SA 3.0
2016-10-31T18:06:00.387Z
2016-10-31T18:06:00.387Z
Jarrett Barnett
<ul>
<li>User account is "pending"</li>
<li>verificationCode is created in database, and erases when visiting the hyperlink.</li>
<li>I'm able to successfully produce an activation email using the code below:</li>
</ul>

<p>Code:    </p>

<pre><code>$user = craft()-&gt;users-&gt;getUserByEmail($emailAddress);

if ($user-&gt;getStatus() != "active")
{
    craft()-&gt;users-&gt;sendActivationEmail($user);
</code></pre>

<ul>
<li>I'm redirected to the page set for <strong>activateAccountSuccessPath</strong> in config/general.php which an account edit page.</li>
<li>I'm "sort of" half logged in... able to see the email address for my account filled in the edit profile form, but the CMS otherwise does not recognize me as logged in.</li>
</ul>

<p>Any ideas?</p>

CC BY-SA 3.0
2016-10-31T16:53:43.593Z
This is all in the context of the front-end of the site?  If you find that user's row in the `craft_users` table, are `locked`, `suspended`, `pending` all set to 0 and is there anything in the `verificationCode`, `verificationCodeIssuedDate` and `unverifiedEmail` columns?
Brad Bell
CC BY-SA 3.0
2016-10-31T17:48:04.600Z
verificationCode and verificationCodeIssuedDate obtain a hash and the hash goes away after visiting the link. Visiting the link a second time (after the hash is deleted) results in a 404 link (which is expected).
Jarrett Barnett
CC BY-SA 3.0
2016-10-31T18:02:06.333Z
"but the CMS otherwise does not recognize me as logged in." - how are you testing that? if you give the user "Access CP" permissions, can they log into the control panel?
Brad Bell
CC BY-SA 3.0
2016-10-31T18:07:08.633Z
They would have access to their /edit/profile page on the front-end (and be able to see the data associated with their user account)... and any dynamic "login/logout" links were still showing "login" as if the user wasnt logged in... hence the "half logged in" ;)
Jarrett Barnett
<plugin-development><users><plugins><activation>
Activation Email for Pending User Doesn't Work
# Activation Email for Pending User Doesn't Work

(Asked by: username_0 on 2016-10-31)

User account is "pending"
verificationCode is created in database, and erases when visiting the hyperlink.
I'm able to successfully produce an activation email using the code below:

Code:    
$user = craft()->users->getUserByEmail($emailAddress);

if ($user->getStatus() != "active")
{
    craft()->users->sendActivationEmail($user);


I'm redirected to the page set for activateAccountSuccessPath in config/general.php which an account edit page.
I'm "sort of" half logged in... able to see the email address for my account filled in the edit profile form, but the CMS otherwise does not recognize me as logged in.

Any ideas?

**Tags:** plugin-development, users, plugins, activation

> **Comments:**
> **username_1**: This is all in the context of the front-end of the site?  If you find that user's row in the `craft_users` table, are `locked`, `suspended`, `pending` all set to 0 and is there anything in the `verificationCode`, `verificationCodeIssuedDate` and `unverifiedEmail` columns?  
> **username_0**: verificationCode and verificationCodeIssuedDate obtain a hash and the hash goes away after visiting the link. Visiting the link a second time (after the hash is deleted) results in a 404 link (which is expected).  
> **username_1**: "but the CMS otherwise does not recognize me as logged in." - how are you testing that? if you give the user "Access CP" permissions, can they log into the control panel?  
> **username_0**: They would have access to their /edit/profile page on the front-end (and be able to see the data associated with their user account)... and any dynamic "login/logout" links were still showing "login" as if the user wasnt logged in... hence the "half logged in" ;)  

---

## 1 answers

### Answer by username_0 on 2016-10-31. Score: 1

After following the stack trace for activating a user (with the link), I discovered that activation fails at /craft/app/services/UsersService.php:822:
820:   public function verifyEmailForUser(UserModel $user)
821:   {
822:      if ($user->unverifiedEmail)
823:      {

Apparently I needed to set the unverifiedEmail property when creating "Pending" users via a plugin as opposed to only setting the 'pending' property to false.
$user = new UserModel();
$user->email = 'pendinguser@email.com;
// ... set other properties
$user->pending = false;
$user->unverifiedEmail = '';


---

