<p>You would most likely want to add a <a href="http://buildwithcraft.com/docs/plugins/controllers#how-controller-actions-fit-into-routing" rel="nofollow noreferrer">controller</a> to your custom plugin, with an 'action' method designed to handle the url request and generate a user; using 'post' or 'get' to pass parameters to the controller action.</p>

<p>In the controller action, you can access your parameters using:</p>

<pre><code>$username = craft()-&gt;request-&gt;getParam('username');
</code></pre>

<p>You can then populate a new User Model using the passed params and save the model.</p>

<pre><code>$user = new UserModel();

$user-&gt;username   = $username;
$user-&gt;email      = $email;
$user-&gt;firstName  = $firstName;
$user-&gt;lastName   = $lastName;
$user-&gt;getContent()-&gt;setAttributes([ 
    'customField' =&gt; $customFieldValue
]);

craft()-&gt;users-&gt;saveUser($user);

// We now have a user Id, so assign user to a group
craft()-&gt;userGroups-&gt;assignUserToGroups($user-&gt;id, $groupId);

// or to multiple groups
//craft()-&gt;userGroups-&gt;assignUserToGroups($user-&gt;id, [$groupId, $otherGroupId]);
</code></pre>

<p>However, by default, controller actions are only accessible to logged-in users. If you want to allow anonymous access you would need to specifically allow it using the <a href="http://buildwithcraft.com/docs/plugins/controllers#allowing-anonymous-access-to-actions" rel="nofollow noreferrer">$allowAnonymous property</a>. This definitely introduces some security issues however, so proceed with caution. For example: definitely do not just assign user group(s) blindly from passed parameters or someone might be able to give themselves admin access!</p>

CC BY-SA 3.0
2015-02-16T21:47:05.547Z
That is exactly what I was looking for, thanks! can you recommend the best way of hooking it in? The client will provide this link to be used on initial site load, so I need to hook it in before the site renders initially.
ConquestXD
CC BY-SA 3.0
2015-02-16T22:14:41.770Z
It will be enabled as soon as you activate your plugin — so create plugin; place in plugins folder; goto to plugin settings, install and activate. Check out the [plugin docs](https://buildwithcraft.com/docs/plugins/introduction) for more info on setting up, installing plugins, etc and/or start with a plugin template like the [BusinessLogic Template](https://github.com/lindseydiloreto/craft-businesslogic) plugin.
Douglas McDonald
CC BY-SA 3.0
2015-02-16T18:27:15.297Z
2017-03-16T20:31:29.870Z
2017-03-16T20:31:29.870Z
Douglas McDonald
<p>Bit of an awkward one.</p>

<p>The client wants a system where they send us a link e.g. mycraftsite.com?userid=abc123 and from there we need to populate the user table.</p>

<p>I am new to craft but I am assuming the correct way is to use a plugin, grab the header data and somehow insert it using a hook, but I don't see any available for before the site renders.</p>

<p>Can anyone help point me in the right direction?</p>

CC BY-SA 3.0
2015-02-16T18:04:01.360Z
Are the passing in the username and email through the link?  How is the password supposed to get set?
Brad Bell
<plugin-development><users>
Automatically create users from http header
# Automatically create users from http header

(Asked by: username_0 on 2015-02-16)

Bit of an awkward one.

The client wants a system where they send us a link e.g. mycraftsite.com?userid=abc123 and from there we need to populate the user table.

I am new to craft but I am assuming the correct way is to use a plugin, grab the header data and somehow insert it using a hook, but I don't see any available for before the site renders.

Can anyone help point me in the right direction?

**Tags:** plugin-development, users
> **Comments:**
> **username_1**: Are the passing in the username and email through the link?  How is the password supposed to get set?  

---

## 1 answers

### Answer by username_2 on 2015-02-16. Score: 4 | Accepted answer

You would most likely want to add a controller to your custom plugin, with an 'action' method designed to handle the url request and generate a user; using 'post' or 'get' to pass parameters to the controller action.
In the controller action, you can access your parameters using:
$username = craft()->request->getParam('username');

You can then populate a new User Model using the passed params and save the model.
$user = new UserModel();

$user->username   = $username;
$user->email      = $email;
$user->firstName  = $firstName;
$user->lastName   = $lastName;
$user->getContent()->setAttributes([ 
    'customField' => $customFieldValue
]);

craft()->users->saveUser($user);

// We now have a user Id, so assign user to a group
craft()->userGroups->assignUserToGroups($user->id, $groupId);

// or to multiple groups
//craft()->userGroups->assignUserToGroups($user->id, [$groupId, $otherGroupId]);

However, by default, controller actions are only accessible to logged-in users. If you want to allow anonymous access you would need to specifically allow it using the $allowAnonymous property. This definitely introduces some security issues however, so proceed with caution. For example: definitely do not just assign user group(s) blindly from passed parameters or someone might be able to give themselves admin access!

> **Comments:**
> **username_0**: That is exactly what I was looking for, thanks! can you recommend the best way of hooking it in? The client will provide this link to be used on initial site load, so I need to hook it in before the site renders initially.  
> **username_2**: It will be enabled as soon as you activate your plugin — so create plugin; place in plugins folder; goto to plugin settings, install and activate. Check out the [plugin docs](https://buildwithcraft.com/docs/plugins/introduction) for more info on setting up, installing plugins, etc and/or start with a plugin template like the [BusinessLogic Template](https://github.com/lindseydiloreto/craft-businesslogic) plugin.  

---

