Custom function on succesful login

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/');
        }
    }
}
 

truonglv

Formerly Nobita.Kun
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
 

truonglv

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

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.
 

truonglv

Formerly Nobita.Kun
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;
    }
 
Top