XF 2.0 Modifying Registration

Voltz

Member
Hello everyone,

I'm currently working on an invitation system addon for Xenforo 2 and was wondering how I would be able to modify the registration. Basically so in order to register on the forums you need to input a invitation code generated by an admin / user
 
Create a custom user field and set it to mandatory on registration. There is a verification callback for custom user fields, so you could use that to verify the invitation code.
 
Create a custom user field and set it to mandatory on registration. There is a verification callback for custom user fields, so you could use that to verify the invitation code.
@S Thomas Hey, I'm currently having a problem when I'm trying to setup the callback it keeps giving me an error

Code:
Callback Voltz\Invitation\InvitationCallback::validate is invalid (error_invalid_class).

I've tried several different things and even though it is installed it keeps saying that it is invalid.
 
Can you create a screenshot of your custom user field? Only the part with the callback is needed. And probably your file structure would be handy aswell.
 
Can you create a screenshot of your custom user field? Only the part with the callback is needed. And probably your file structure would be handy aswell.
i39tj.webp

7xe0p.webp

I've tried using the namespace like the way you would setup your controllers, do I have to use file path?


EDIT: I somehow got it to work no clue what happened but it is now working, im actually confused why it is now working, thanks for the help!
 
No, if you've done it like a controller, everything is fine. Just to make sure, Voltz is in /src/addons/, right?
Is your class within InvitationCallback also called InvitationCallback?

Edit: Nvm, you have a folder Listener, this one is missing in your path.
 
@S Thomas hey again, is there a way to prevent the callback from interfering with editing the user for example when I go to edit a user, also is there a way to create the custom user field on install I've found examples of doing it with Xenforo 1 but not 2

ecl1i.webp
 
Last edited:
Not sure, but you could check if the request controller is an admin controller and in that case skip the verification in your callback.
Creating a custom user field during installation should be fairly easy, but I don't know from memory how to do it.
 
Not sure, but you could check if the request controller is an admin controller and in that case skip the verification in your callback.
Creating a custom user field during installation should be fairly easy, but I don't know from memory how to do it.
How can I check if is from the admin controller in the callback? (Sorry just started doing stuff with XenForo)
 
Again unsure what would be the best method, but you could do sth like
PHP:
// via app
(\XF::app->container()->__get("app.defaultType") === "admin")
(\XF::app->container()->__get("app.classType") === "Admin")

//generally ignore when admin or staff
(\XF::app->visitor()->is_admin || \XF::app->visitor()->is_super_admin || \XF::app->visitor()->is_staff)
 
Again unsure what would be the best method, but you could do sth like
PHP:
// via app
(\XF::app->container()->__get("app.defaultType") === "admin")
(\XF::app->container()->__get("app.classType") === "Admin")

//generally ignore when admin or staff
(\XF::app->visitor()->is_admin || \XF::app->visitor()->is_super_admin || \XF::app->visitor()->is_staff)

PHP:
        /* Check if callback is being called from admin controller */
        if ($app->container()->__get('app.defaultType') === 'admin' || $app->container()->__get('app.classType') === 'Admin')
        {
            return true;
        }

This worked thank you for all your help you're great
 
@S Thomas sorry to bother you again, do you have any idea how to check if there was any error it seems that if you enter a valid code however if you get another error example invalid email or user name too short then it will still run the callback check i'm not too sure how I would check for an existing error before setting the invite to used
 
Would need to dig into the code. I'd do it as XF handles email verfication: On registration, put the code into "waiting for verfication" status (and the code is locked in this stage). If the registration fails, just don't add the code to your table.
On the first login, clear the status to "valid" (= used). Run a cron to clear out unverified codes after a limited time so they can be reused (and delete accounts so you only have valid accounts). Plus ask your users to log in the first time within a short time, otherwise they would get deleted.
 
Back
Top Bottom