XenForo 2.1.1 external registration script

Prudence

Member
I'm presently working on developing an add-on, but I've hit a bit of a snag. I'm trying to extend XenForo's registration service, though I'm unsure on how much of the original code I need to make it work.

What I'm trying to do is create a custom page where forum users with the appropriate permissions could create a user account (while logged in). I'm not so concerned with the spam protections that the original registration service has (if it's possible to remove them) as the users with these permissions would be verified users. I've found the original XenForo registration services at src/XF/Service/User/Registration.php and src/XF/Pub/Controller/Register.php

From my own troubleshooting I realize you can't just add a row to the database to create a user, my question now is what's the minimum that XenForo needs, and what service needs to be called, for XenForo to accept inputs and register a user?
 
You can use the User entity (\XF\Entity\User) to create a new user - have a look at the \XF\Admin\Controller\User::userSaveProcess method for more information.

Very few of the fields are actually required when creating a user (most of them have defaults defined in the entity structure).
 
The easiest way is to use the REST Api by sending a request to the endpoint.
Can you elaborate?
You can use the User entity (\XF\Entity\User) to create a new user - have a look at the \XF\Admin\Controller\User::userSaveProcess method for more information.

Very few of the fields are actually required when creating a user (most of them have defaults defined in the entity structure).
Thanks! I'll have a look at that. Do you know if XenForo's registration services are contextually smart? Meaning, if I give the inputs the right names when I pass them on, will XenForo will put it in the right column? Or do I need to put them in order?
 
Thanks! I'll have a look at that. Do you know if XenForo's registration services are contextually smart? Meaning, if I give the inputs the right names when I pass them on, will XenForo will put it in the right column? Or do I need to put them in order?

I'm not sure what you mean? The entities require you to define a field when setting a value - there's no way to set a value without specifying the field you're setting.

If you're using the magic setter, you would do $user->[I]field[/I] = [I]value[/I]. If you're using the bulkSet method, the array should be keyed with the field name, and the value should be the value to set the field to.

Liam
 
I'm not sure what you mean? The entities require you to define a field when setting a value - there's no way to set a value without specifying the field you're setting.

If you're using the magic setter, you would do $user->[I]field[/I] = [I]value[/I]. If you're using the bulkSet method, the array should be keyed with the field name, and the value should be the value to set the field to.

Liam
Sorry, to clarify I was making sure that values didn't need to be passed on in specific column order. I.e. if xf_user columns go in order: username, user_id, password then values/fields must as well.

One question, in a separate thread I found the following code used for user creation. Is there a specific reason why using the userSaveProcess would be better?

PHP:
<?php

// bootstrap framework
$dir = __DIR__;
require($dir . '/src/XF.php');

XF::start($dir);

// create user
/** @var \XF\Service\User\Registration $registration */
$registration = XF::service('XF:User\Registration');
$registration->setFromInput([
    // set values
]);
// validation, etc...
$user = $registration->save();

// log visitor in as new user
$this->session()->changeUser($user);
\XF::setVisitor($user);

/** @var \XF\ControllerPlugin\Login $loginPlugin */
$loginPlugin = $this->plugin('XF:Login');
$loginPlugin->createVisitorRememberKey();
 
I'm not sure what you mean? The entities require you to define a field when setting a value - there's no way to set a value without specifying the field you're setting.

If you're using the magic setter, you would do $user->[I]field[/I] = [I]value[/I]. If you're using the bulkSet method, the array should be keyed with the field name, and the value should be the value to set the field to.

Liam
In trying to use the User entity I'm not seeing much luck. I tried calling an extension of Admin/Controller/User in order to use the userSaveProcess, but i can't ever get it to run. It errors me with Call to undefined method (...) userSaveProcess(). Am I missing a key part of the method, or is it something else? I'm not super well versed in XF dev yet, so it's entirely possible I overlooked something.
 
Back
Top Bottom