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

Create user from external and login

Discussion in 'XenForo Development Discussions' started by EricB, Nov 18, 2013.

  1. EricB

    EricB New Member

    Hello,

    i´am completly new to XenForo, moved from an not activated IPB license.

    I want to use thw XenForo in an Intranet-Web with its own user-database. From other AddOn´s i copy & pasted the following code (and adapted for me). But it raises an error!

    Do you have any ideas?

    Thank you,
    Eric

    PHP:
    XenForo_Autoloader::getInstance()->setupAutoloader(XF_ROOT '/library');
    XenForo_Application::initialize(XF_ROOT '/library'XF_ROOT);
    XenForo_Application::set('page_start_time'TIMENOW);
    XenForo_Application::disablePhpErrorHandler();
    XenForo_Application::setDebugMode(true);
    XenForo_Session::startPublicSession();
    $GpID  '19760';
    $visitor XenForo_Visitor::getInstance();
    $userModel XenForo_Model::create('XenForo_Model_User');
    $userExternalModel XenForo_Model::create('XenForo_Model_UserExternal');
    $UserInfo $userExternalModel->getExternalAuthAssociation('pnet'$GpID);
    if (!
    $UserInfo)
    {
      
    $data = array(
        
    'username'  => 'Demo User',
        
    'email'    => 'Demo User@domain.tdl',
        
    'location'  => 'Home',
        
    'dob_day'  => '22',
        
    'dob_month'  => '08',
        
    'dob_year'  => '1987',
        
    'timezone'  => 'Europe/Amsterdam'
      
    );
      
    $auth  XenForo_Authentication_Abstract::create('XenForo_Authentication_NoPassword');
      
    $writer  XenForo_DataWriter::create('XenForo_DataWriter_User');
      
    $options XenForo_Application::get('options');
     
      
    $writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => true));
      
    $writer->bulkSet($data);
      
    $writer->set('scheme_class'$auth->getClassName());
      
    $writer->set('data'$auth->generate(''), 'xf_user_authenticate');
      
    $writer->set('user_group_id'XenForo_Model_User::$defaultRegisteredGroupId);
      
    $writer->set('language_id'XenForo_Visitor::getInstance()->get('language_id'));
     
      
    $writer->advanceRegistrationUserState(false);
      
    $writer->save();
      
    $user $writer->getMergedData(); 
      
    $UserID $user['user_id'];
     
      
    $userExternalModel->updateExternalAuthAssociation('pnet'$GpID$UserID);
      
    XenForo_Model_Ip::log($UserID'user'$UserID'register');
     
    } else {
      
    $UserID $UserInfo['user_id'];
    }
    restore_error_handler();
    restore_exception_handler();
    $userModel->setUserRememberCookie($UserID);
    $session XenForo_Application::get('session');
    $session->changeUserId($UserID);
    XenForo_Visitor::setup($UserID);
    header("Location: index.php");

    Error raised:

    Warning: call_user_func_array(): First argument is expected to be a valid callback, 'XenForo_DataWriter_Helper_Language::verifyLanguageId' was given in /www/docs/kd.auto-partner.net/forum/library/XenForo/DataWriter.php on line 970
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    That error usually indicates that you do not have all the files uploaded correctly.
     
  3. EricB

    EricB New Member

    The files are all uploaded corectly. But i found out, that the error raises after modifying the file "library\XenForo\DataWriter\User.php".

    I commented out the code for checking unique mails ans mailadresses, because i have to have this info not unique.

    What can i do?
     
  4. Jeremy

    Jeremy XenForo Moderator Staff Member

    What changes did you actually make?
     
  5. xf_phantom

    xf_phantom Well-Known Member

    What version are you using?

    Class XenForo_DataWriter_Helper_Language doesn't exist anymore (since 1.1.2 or 1.1.3)
    The validation method is located now in XenForo_DataWriter_User
    Is your file probably deprecated?
     
    EricB likes this.
  6. EricB

    EricB New Member

    Yes, you´re right, have mixed files. Tried with an 1.1.2 version from an friend before purchasing my new license. This problem is solved, but get a new one:

    This error raised:
    An exception occurred: Mysqli statement execute error : Field 'pnet_auth_id' doesn't have a default value in /www/docs/kd.auto-partner.net/forum/library/Zend/Db/Statement/Mysqli.php on line 214
    1. Zend_Db_Statement_Mysqli->_execute() in Zend/Db/Statement.php at line 317
    2. Zend_Db_Statement->execute() in Zend/Db/Adapter/Abstract.php at line 479
    3. Zend_Db_Adapter_Abstract->query() in Zend/Db/Adapter/Abstract.php at line 574
    4. Zend_Db_Adapter_Abstract->insert() in XenForo/DataWriter.php at line 1612
    5. XenForo_DataWriter->_insert() in XenForo/DataWriter.php at line 1601
    6. XenForo_DataWriter->_save() in XenForo/DataWriter.php at line 1393
    7. XenForo_DataWriter->save() in /www/docs/xxxxx/forum/sso.php at line 49
    sso.php is the with the code i posted in my 1st thread.

    pnet_auth_id comes from my external login/create with "pnet" is the key for the provider. i have to add this field in the table "xf_user_profiles"
     
  7. EricB

    EricB New Member

    Now solved too. Had to set a "default value" in the table for the new field.
     

Share This Page