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

Custom function on succesful login

Discussion in 'XenForo Development Discussions' started by Tom_, Mar 17, 2014.

  1. Tom_

    Tom_ Member

    I'm trying to create addon which allow me to execute custom function on succesfull login. I'm stuck, little bit help please.

    I have code event listener -> load_class_controller
    PHP:
    <?php

    class Dev_Listener_LoadClassController
    {
        public static function 
    extendMemberController($class, array &$extend)
        {
            if (
    $class == 'XenForo_ControllerPublic_Login')
            {
                
    $extend[] = 'Dev_ControllerPublic_Login';
            }
        }
    }
    PHP:
    <?php

    class Dev_ControllerPublic_Login extends XFCP_Dev_ControllerPublic_Login
    {
        public function 
    actionIndex()
        {
            if (
    $login) {
               
    // Just for test
               
    file_get_contents('http://www.example.com/');
            }
        }
    }
     
  2. Nobita.Kun

    Nobita.Kun Well-Known Member

    PHP:
    class Dev_ControllerPublic_Login extends XFCP_Dev_ControllerPublic_Login
    {
        public function 
    actionLogin()
        {
            
    $response parent::actionLogin();
           
            
    $visitor XenForo_Visitor::getInstance();
            if (
    $visitor['user_id'])
            {
                
    // your code here when user login success!
            
    }
        }
    }
    Maybe this helpful for you
     
    Tom_ likes this.
  3. Tom_

    Tom_ Member

    @Nobita.Kun Thanks for help!

    I get error on login:
    Code:
    Security error occurred. Please press back, refresh the page, and try again.
     
  4. Nobita.Kun

    Nobita.Kun Well-Known Member

    Its look like your code have some problem. See on Server Error Logs to get more information ;)
     
  5. Tom_

    Tom_ Member

    UNsuccesfull login i get this:
    Code:
    No controller response from XenForo_ControllerPublic_Login::actionLogin
    
        XenForo_FrontController->_handleControllerResponse() in XenForo/FrontController.php at line 355
        XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
        XenForo_FrontController->run() in /var/www/xenforo/index.php at line 13
    
    And succesfull login i get this:
    Code:
    Security error occurred. Please press back, refresh the page, and try again.
     
  6. Nobita.Kun

    Nobita.Kun Well-Known Member

    Yep! You should return $response after your code reached!
    Code:
    public function actionLogin()
        {
            $response = parent::actionLogin();
          
            $visitor = XenForo_Visitor::getInstance();
            if ($visitor['user_id'])
            {
                // your code here when user login success!
            }
    return $response;
        }
     

Share This Page