• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Registering user with controller, possible?

#1
So not the best title but I'm trying to create a small script that enables me to register users via a minecraft server. So they would do all the stuff in minecraft and then a plugin would talk to a script on the website.

Now where I'm stuck...
I cannot find the way to add users without using the Register.php in the ControllerPublic and I'm not too experienced with OOP programming so I'm having some trouble figuring this out.

Any help is appreciated =)
 
R

ragtek

Guest
#2
this is the required code, if you want to create an new user from an external application
PHP:
$startTime = microtime(true);
 
        require($fileDir . '/library/XenForo/Autoloader.php');
        XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
        XenForo_Application::initialize($fileDir . '/library', $fileDir);
        XenForo_Application::set('page_start_time', $startTime);
 
 
            $dependencies = new XenForo_Dependencies_Public();
            $dependencies->preLoadData();
      $dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
// now set all the data
 
$dw->save();
 
#3
this is the required code, if you want to create an new user from an external application
PHP:
$startTime = microtime(true);
 
        require($fileDir . '/library/XenForo/Autoloader.php');
        XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
        XenForo_Application::initialize($fileDir . '/library', $fileDir);
        XenForo_Application::set('page_start_time', $startTime);
 
 
            $dependencies = new XenForo_Dependencies_Public();
            $dependencies->preLoadData();
      $dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
// now set all the data
 
$dw->save();
Ahh now I understand, lovely thank you =)

Hmm sorry now I got confused again, I should use the setCustonFields right? Or am I totally misunderstanding ^^
 
R

ragtek

Guest
#4
this is my method to create users:


PHP:
    public function createUser($userName, $userPw, $userMail, $otherParams = array()){
        /** @var $dw    XenForo_DataWriter_User */
        $dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
        $dw->set('username', $userName);
        $dw->set('email', $userMail);
        $dw->setPassword($userPw);
        $dw->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
        foreach ($otherParams AS $paramName => $value){
            $dw->set($paramName, $value);
        }
        $dw->save();
 
        return $dw->getMergedData();
    }


my initialization method:

PHP:
public function __construct($fileDir, $loadDependencies = true)
    {
        $startTime = microtime(true);
 
        require($fileDir . '/library/XenForo/Autoloader.php');
        XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
        XenForo_Application::initialize($fileDir . '/library', $fileDir);
        XenForo_Application::set('page_start_time', $startTime);
 
        if ($loadDependencies){
            $dependencies = new XenForo_Dependencies_Public();
            $dependencies->preLoadData();
        }
    }

so what's not working?

you only need to run








$dw->set('username', $userName);
$dw->set('email', $userMail);
$dw->setPassword($userPw);
$dw->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
$dw->save();
 
#5
this is my method to create users:


PHP:
    public function createUser($userName, $userPw, $userMail, $otherParams = array()){
        /** @var $dw    XenForo_DataWriter_User */
        $dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
        $dw->set('username', $userName);
        $dw->set('email', $userMail);
        $dw->setPassword($userPw);
        $dw->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
        foreach ($otherParams AS $paramName => $value){
            $dw->set($paramName, $value);
        }
        $dw->save();
 
        return $dw->getMergedData();
    }


my initialization method:

PHP:
public function __construct($fileDir, $loadDependencies = true)
    {
        $startTime = microtime(true);
 
        require($fileDir . '/library/XenForo/Autoloader.php');
        XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
        XenForo_Application::initialize($fileDir . '/library', $fileDir);
        XenForo_Application::set('page_start_time', $startTime);
 
        if ($loadDependencies){
            $dependencies = new XenForo_Dependencies_Public();
            $dependencies->preLoadData();
        }
    }

so what's not working?

you only need to run








$dw->set('username', $userName);
$dw->set('email', $userMail);
$dw->setPassword($userPw);
$dw->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
$dw->save();
Okay, I was thinking i had to use another function for some reason. Now i understand :)

Works perfect!
 
#6
this is my method to create users:


PHP:
    public function createUser($userName, $userPw, $userMail, $otherParams = array()){
        /** @var $dw    XenForo_DataWriter_User */
        $dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
        $dw->set('username', $userName);
        $dw->set('email', $userMail);
        $dw->setPassword($userPw);
        $dw->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
        foreach ($otherParams AS $paramName => $value){
            $dw->set($paramName, $value);
        }
        $dw->save();
 
        return $dw->getMergedData();
    }


my initialization method:

PHP:
public function __construct($fileDir, $loadDependencies = true)
    {
        $startTime = microtime(true);
 
        require($fileDir . '/library/XenForo/Autoloader.php');
        XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
        XenForo_Application::initialize($fileDir . '/library', $fileDir);
        XenForo_Application::set('page_start_time', $startTime);
 
        if ($loadDependencies){
            $dependencies = new XenForo_Dependencies_Public();
            $dependencies->preLoadData();
        }
    }

so what's not working?

you only need to run








$dw->set('username', $userName);
$dw->set('email', $userMail);
$dw->setPassword($userPw);
$dw->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
$dw->save();
This is working very well, but how does the error system work? Right now I search through the error to find the reason but there must be a better way.