<p>You can write a <a href="https://craftcms.com/docs/plugins/introduction" rel="nofollow">plugin</a> that listens to the <a href="https://craftcms.com/docs/plugins/events-reference#users-onActivateUser" rel="nofollow">users.onActivateUser event</a>, and manually redirects the browser to your desired page.</p>

<p>Just add this code to your plugin’s primary class:</p>

<pre class="lang-php prettyprint-override"><code>public function init()
{
    craft()-&gt;on('users.activateUser', array($this, 'onActivateUser'));
}

public function onActivateUser(Event $event)
{
    /* @var UserModel $user */
    $user = $event-&gt;params['user'];

    // Are they in the default group?
    // (Indicates this was probably public registration)
    if ($user-&gt;isInGroup('myDefaultGroup'))
    {
        // Redirect them to the activateAccountSuccessPath
        $activateAccountSuccessPath = craft()-&gt;config-&gt;getLocalized('activateAccountSuccessPath');
        $url = UrlHelper::getSiteUrl($activateAccountSuccessPath);
        craft()-&gt;request-&gt;redirect($url);
    }
}
</code></pre>

CC BY-SA 3.0
2016-01-28T20:12:07.157Z
Great stuff Brandon, this is working well. Just a couple of additional questions: **1.** is there anyway to get this working in conjunction with `autoLoginAfterAccountActivation` (I'm talking of a dashboard page which uses `{% requireLogin %}`). **2.** Is there any technical or security reason why this isn't built in as a default config setting?
Rob
CC BY-SA 3.0
2016-01-28T20:21:54.473Z
@Rob This should work with autoLoginAfterAccountActivation = true. This isn’t something we would make a config setting because it’s super edge case. The expected behavior is that a user with access to the Control Panel would be directed to the Control Panel when their account has been activated.
Brandon Kelly
CC BY-SA 3.0
2016-01-28T20:39:43.723Z
Fair enough. Unfortunately, it doesn't work with that setting and just redirects to `loginPath` — it's far better than our previous solution however, and (I've [updated my post with a full config setup](http://craftcms.stackexchange.com/questions/13207/postcploginredirect-wrong-redirect-when-used-with-autologinafteraccountactivatio) for posterity)
Rob
CC BY-SA 3.0
2016-01-27T21:27:18.387Z
2016-01-27T21:33:07.467Z
2016-01-27T21:33:07.467Z
Brandon Kelly
<p>I have a site that allows public registration, and I want to be able to control where users are redirected to after activating their account. However the default user group has access to the Control Panel, so as explained in “<a href="https://craftcms.stackexchange.com/q/4106/9">activateAccountSuccessPath doesn&#39;t work as expected</a>”, users are taken to the Control Panel login page after activation, rather than the path defined by the <code>activateAccountSuccessPath</code> config setting.</p>

<p>Is there any way to change that behavior, so even users with access to the Control Panel will get redirected to the <code>activateAccountSuccessPath</code> after account activation?</p>

<users><config><activation>
How can I set the "activateAccountSuccessPath" for users with Control Panel access?
# How can I set the "activateAccountSuccessPath" for users with Control Panel access?

(Asked by: username_0 on 2016-01-27)

I have a site that allows public registration, and I want to be able to control where users are redirected to after activating their account. However the default user group has access to the Control Panel, so as explained in “[activateAccountSuccessPath doesn't work as expected](https://craftcms.stackexchange.com/q/4106/9)”, users are taken to the Control Panel login page after activation, rather than the path defined by the `activateAccountSuccessPath` config setting.

Is there any way to change that behavior, so even users with access to the Control Panel will get redirected to the `activateAccountSuccessPath` after account activation?

**Tags:** users, config, activation

---

## 1 answers

### Answer by username_0 on 2016-01-27. Score: 2 | Accepted answer

You can write a plugin that listens to the users.onActivateUser event, and manually redirects the browser to your desired page.
Just add this code to your plugin’s primary class:
public function init()
{
    craft()->on('users.activateUser', array($this, 'onActivateUser'));
}

public function onActivateUser(Event $event)
{
    /* @var UserModel $user */
    $user = $event->params['user'];

    // Are they in the default group?
    // (Indicates this was probably public registration)
    if ($user->isInGroup('myDefaultGroup'))
    {
        // Redirect them to the activateAccountSuccessPath
        $activateAccountSuccessPath = craft()->config->getLocalized('activateAccountSuccessPath');
        $url = UrlHelper::getSiteUrl($activateAccountSuccessPath);
        craft()->request->redirect($url);
    }
}

> **Comments:**
> **username_1**: Great stuff Brandon, this is working well. Just a couple of additional questions: **1.** is there anyway to get this working in conjunction with `autoLoginAfterAccountActivation` (I'm talking of a dashboard page which uses `{% requireLogin %}`). **2.** Is there any technical or security reason why this isn't built in as a default config setting?  
> **username_0**: @Rob This should work with autoLoginAfterAccountActivation = true. This isn’t something we would make a config setting because it’s super edge case. The expected behavior is that a user with access to the Control Panel would be directed to the Control Panel when their account has been activated.  
> **username_1**: Fair enough. Unfortunately, it doesn't work with that setting and just redirects to `loginPath` — it's far better than our previous solution however, and (I've [updated my post with a full config setup](http://craftcms.stackexchange.com/questions/13207/postcploginredirect-wrong-redirect-when-used-with-autologinafteraccountactivatio) for posterity)  

---

