<p>You already answered your own question, but I thought I would post an example. In the plugin's class definition file create an <code>init</code> method with the following:</p>

<pre><code>public function init()
{
    parent::init();

    craft()-&gt;on('users.saveUser', function(Event $event) 
    {
        $user = $event-&gt;params['user'];
        $isNewUser = $event-&gt;params['isNewUser'];

        if ($isNewUser &amp;&amp; !$currentUser) {

            // do your thing, whatever it is

        }
    });
}
</code></pre>

<p>This should only target 'new user registrations' by users who are 'not already logged in' (i.e. public registrations through the front-end). By the time the Users Service has raised the event, it should have already passed all the other checks, regarding whether to <code>allowPublicRegistration</code>, etc.</p>

CC BY-SA 3.0
2014-10-21T22:08:49.137Z
2014-10-21T22:08:49.137Z
Douglas McDonald
<p>I would like to be able to perform actions on those users that register through the front end and skip ones who are created in the CP... is there are way of checking or a parameter accessible in the onBeforeSaveUser or onSaveUser events?</p>

<p>I assume there must be something hidden in there as users registered on the front end can be assigned to a certain user group which isn't applied to a CP registration.</p>

CC BY-SA 3.0
2014-10-21T14:08:33.590Z
Just did a bit more digging and found the variable $thisIsPublicRegistration floating around the actionSaveUser method, should have been looking in the controller not the service duoh! This is set by checking of there is a current logged in user, is this the best way to do this in the onBeforeSaveUser and onSaveUser events too?
Neal Hulme
CC BY-SA 3.0
2014-10-21T14:24:14.313Z
You should be able to check the same way in the `onBeforeSaveUser` but not necessarily in the `onSaveUser`. It may depend on the auto-login settings and when that gets fired. What are you trying to ultimately accomplish?
Douglas McDonald
CC BY-SA 3.0
2014-10-21T14:38:25.400Z
Update: It looks like the `impersonate($user->$id)` on line 822 of UsersController executes after the onSaveUser event fires, so should be a safe check there also.
Douglas McDonald
<users>
Is it possible to tell if a user was registered through the front end or CP?
# Is it possible to tell if a user was registered through the front end or CP?

(Asked by: username_0 on 2014-10-21)

I would like to be able to perform actions on those users that register through the front end and skip ones who are created in the CP... is there are way of checking or a parameter accessible in the onBeforeSaveUser or onSaveUser events?

I assume there must be something hidden in there as users registered on the front end can be assigned to a certain user group which isn't applied to a CP registration.

**Tags:** users
> **Comments:**
> **username_0**: Just did a bit more digging and found the variable $thisIsPublicRegistration floating around the actionSaveUser method, should have been looking in the controller not the service duoh! This is set by checking of there is a current logged in user, is this the best way to do this in the onBeforeSaveUser and onSaveUser events too?  
> **username_1**: You should be able to check the same way in the `onBeforeSaveUser` but not necessarily in the `onSaveUser`. It may depend on the auto-login settings and when that gets fired. What are you trying to ultimately accomplish?  
> **username_1**: Update: It looks like the `impersonate($user->$id)` on line 822 of UsersController executes after the onSaveUser event fires, so should be a safe check there also.  

---

## 1 answers

### Answer by username_1 on 2014-10-21. Score: 2 | Accepted answer

You already answered your own question, but I thought I would post an example. In the plugin's class definition file create an init method with the following:
public function init()
{
    parent::init();

    craft()->on('users.saveUser', function(Event $event) 
    {
        $user = $event->params['user'];
        $isNewUser = $event->params['isNewUser'];

        if ($isNewUser && !$currentUser) {

            // do your thing, whatever it is

        }
    });
}

This should only target 'new user registrations' by users who are 'not already logged in' (i.e. public registrations through the front-end). By the time the Users Service has raised the event, it should have already passed all the other checks, regarding whether to allowPublicRegistration, etc.


---

