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

Help with code

Discussion in 'XenForo Development Discussions' started by Alofoxx, Aug 26, 2012.

  1. Alofoxx

    Alofoxx Member

    Im trying to extend XenForo_DataWriter_User::_verifyUsername

    So that when they signup on my site it checks the username against minecraft.net premium acct list.

    its not working but here is what i did at the end of the function.
    the goal is to add the username to the end of "http://www.minecraft.net/haspaid.jsp?user=" if its a paid acct it will return True otherwise it will be false. My name is alofoxx so it would send out http://www.minecraft.net/haspaid.jsp?user=alofoxx and returns true where as "fakename" "http://www.minecraft.net/haspaid.jsp?user=fakename" would return false and throw an error.
    hope fully someone can tell me my errors in code :)

    THANKS

    PHP:
            // compare against romanized name to help reduce confusable issues
            
    $romanized utf8_deaccent(utf8_romanize($username));
            if (
    $romanized != $username)
            {
                
    $existingUser $this->_getUserModel()->getUserByName($romanized);
                if (
    $existingUser && $existingUser['user_id'] != $this->get('user_id'))
                {
                    
    $this->error(new XenForo_Phrase('usernames_must_be_unique'), 'username');
                    return 
    false;
                }
            }
     
                  
    //Alo minecraft verification
                  /*** 2012-01-07 BEGIN AmigoJack
                    Check username: has Minecraft nick paid? ***/
                  
    try
                  {             
                        if( 
    strpos$sRes'true' )=== FALSE );
                        {
                              
    $this->error(new XenForo_Phrase('The_username_must_exist_on_Minecraft'), 'username');
                              return 
    false;
                        }
                  }
                  catch (
    Exception $e) {}
                  
    //End alo code
     
            
    return true;
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Remove the semicolon immediately after the if.
     
  3. Alofoxx

    Alofoxx Member

    what semicolon??
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Change:

    if( strpos( $sRes, 'true' )=== FALSE );

    To:

    if( strpos( $sRes, 'true' )=== FALSE )
     
  5. Alofoxx

    Alofoxx Member

    Gotcha, will test.
     
  6. Alofoxx

    Alofoxx Member

    its still not working, not throwing false if not a good minecraft acct.
     
  7. Alofoxx

    Alofoxx Member

    http://www.minecraft.net/haspaid.jsp?user=fakeFucjasd
    returns false.

    http://fsrminecraft.com/index.php?login/login
    enter the same name here and it does not show a error.

    PHP:
            }
     
                  
    //Alo minecraft verification
                  /*** 2012-01-07 BEGIN AmigoJack
                    Check username: has Minecraft nick paid? ***/
                  
    try
                  {             
                        if( 
    strpos$sRes'true' )=== FALSE )
                        {
                              
    $this->error(new XenForo_Phrase('The_username_must_exist_on_Minecraft'), 'username');
                              return 
    false;
                        }
                  }
                  catch (
    Exception $e) {}
                 
                  
    //End alo code
     
            
    return true;
     
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Can you post the full code, including where $sRes is created?
     
  9. Alofoxx

    Alofoxx Member

    oh crud. i left it out... herpderp its :

    PHP:
      $sResfile_get_contents'http://www.minecraft.net/haspaid.jsp?user='rawurlencode$data['username'] ) );
    not sure where it goes in relation to "try"
    i assumed the whole "try" catch would allow this not to be ignored if the minecraft.net is down
    so would the correct code snip be then:

    PHP:
            }
     
                  
    //Alo minecraft verification
                  /*** 2012-01-07 BEGIN AmigoJack
                    Check username: has Minecraft nick paid? ***/
                    
    $sResfile_get_contents'http://www.minecraft.net/haspaid.jsp?user='rawurlencode($username) );
                  try
                  {             
                        if( 
    strpos$sRes'true' )=== FALSE );
                        {
                              
    $this->error(new XenForo_Phrase('The_username_must_exist_on_Minecraft'), 'username');
                              return 
    false;
                        }
                  }
                  catch (
    Exception $e) {}
                  
    //End alo code
     
            
    return true;
     
  10. Alofoxx

    Alofoxx Member

    tried the above and got
    FSR Minecraft - Error
    A server error occurred. Please try again later.
     
  11. Alofoxx

    Alofoxx Member

    got
    Parse error: syntax error, unexpected T_VARIABLE, expecting '{' in*****/library/XenForo/DataWriter/User.php on line 554
    with
    PHP:
                  //Alo minecraft verification
                  /*** 2012-01-07 BEGIN AmigoJack
                    Check username: has Minecraft nick paid? ***/
                  
    try
                  
    $sResfile_get_contents'http://www.minecraft.net/haspaid.jsp?user='rawurlencode($username) );
                  {           
                        if( 
    strpos$sRes'true' )=== FALSE )
                        {
                              
    $this->error(new XenForo_Phrase('The_username_must_exist_on_Minecraft'), 'username');
                              return 
    false;
                        }
                  }
                  catch (
    Exception $e) {}
               
                  
    //End alo code
     
            
    return true;
     
  12. Alofoxx

    Alofoxx Member

    code is based off of:
    PHP:
                $cp->submit_cp_field('register'$user->get_iso_lang_id(), $cp_data$error);
     
     
     
                
    /*** 2012-01-07 BEGIN AmigoJack
                    Check username: has Minecraft nick paid? ***/
                
    $sResfile_get_contents'http://www.minecraft.net/haspaid.jsp?user='rawurlencode$user-> data['username'] ) );
                if( 
    strpos$aRes'true' )=== FALSE $error[]= 'The username must exist on Minecraft';
                
    /*** 2012-01-07 END ***/  
    source: https://www.phpbb.com/community/viewtopic.php?f=72&t=2139921
     
  13. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I don't think you need the try catch block.
     
  14. Alofoxx

    Alofoxx Member

    FSR Minecraft - Error
    A server error occurred. Please try again later.
    is what i get with a valid and non valid acct name.
    PHP:
            }
     
                  
    //Alo minecraft verification
                  /*** 2012-01-07 BEGIN AmigoJack
                    Check username: has Minecraft nick paid? ***/
     
                  
    $sResfile_get_contents'http://www.minecraft.net/haspaid.jsp?user='rawurlencode($username) );
                  {             
                        if( 
    strpos$sRes'true' )=== FALSE )
                        {
                              
    $this->error(new XenForo_Phrase('The_username_must_exist_on_Minecraft'), 'username');
                              return 
    false;
                        }
                  }
     
                 
                  
    //End alo code
     
            
    return true;
     
  15. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    What is the full error? Look in the log:

    Admin CP -> Tools -> Server Error Log
     
  16. Alofoxx

    Alofoxx Member

    Error Info
    ErrorException: file_get_contents() [<a href='function.file-get-contents'>function.file-get-contents</a>]: URL file-access is disabled in the server configuration - library/XenForo/DataWriter/User.php:554
    Generated By: Unknown Account, Today at 5:34 AM
    Stack Trace
    #0 [internal function]: XenForo_Application::handlePhpError('http://www.mine...')
    #1 ***/library/XenForo/DataWriter/User.php(554): file_get_contents('statachi', Object(WidgetFramework_Extend_DataWriter_User), 'username', Array)
    #2 [internal function]: XenForo_DataWriter_User->_verifyUsername(Array, Array)
    #3 ***/library/XenForo/DataWriter.php(965): call_user_func_array(Array, 'statachi', Array, 'username')
    #4 ***/library/XenForo/DataWriter.php(720): XenForo_DataWriter->_runVerificationCallback('username', Array, 'statachi', Array)
    #5 ***/library/XenForo/DataWriter.php(638): XenForo_DataWriter->_isFieldValueValid('username', 'statachi')
    #6 ***/library/XenForo/ControllerPublic/Register.php(63): XenForo_DataWriter->set()
    #7 ***/library/XenForo/FrontController.php(310): XenForo_ControllerPublic_Register->actionIndex(Object(XenForo_RouteMatch))
    #8 ***/library/XenForo/FrontController.php(132): XenForo_FrontController->dispatch()
    #9 ***/index.php(13): XenForo_FrontController->run()
    #10 {main}
    Request State
    array(3) {
    ["url"] => string(45) "http://fsrminecraft.com/index.php?login/login"
    ["_GET"] => array(1) {
    ["login/login"] => string(0) ""
    }
    ["_POST"] => array(5) {
    ["login"] => string(8) "statachi"
    ["register"] => string(1) "1"
    ["cookie_check"] => string(1) "1"
    ["redirect"] => string(33) "http://fsrminecraft.com/index.php"
    ["_xfToken"] => string(0) ""
    }
    }
     
  17. Alofoxx

    Alofoxx Member

    is there a setting for "URL file-access is disabled in the server configuration"
     
  18. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Make sure allow_url_fopen is enabled in your PHP configuration. You can check this in your phpinfo by visiting:

    admin.php?tools/phpinfo
     
  19. Alofoxx

    Alofoxx Member

    Works now thank you.
     
  20. chrishill

    chrishill Active Member

    Hmm how did you guys do this? I was trying to set up the same thing for my forum.
     

Share This Page