Results 1 to 6 of 6

Thread: Triggering an action on backend login

  1. #1
    New user
    Join Date
    12-10-12.
    Posts
    4

    Default Triggering an action on backend login

    I'm currently working on some synchronisation stuff. I've already created Buttons n stuff in the Backend to trigger the synchronisation method and things work just fine, but I'd need a way to trigger the synchronisation as soon as a Backend user logs in, quite like the postLogin-Hook, just for the Backend.

    I'd be glad if you could help me.
    Thanks in advance
    Chris

  2. #2
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Triggering an action on backend login

    There were some comments below the contao hooks page.

    You can do detection in your routine to determine if the login was from the FE or the BE.

    Code:
    public function postLogin($objUser)
    {
        // Front end
        if (TL_MODE == 'FE')
        {
    
        }
    	
        // Back end
        elseif (TL_MODE == 'BE')
        {
    
        }
    }

  3. #3
    New user
    Join Date
    12-10-12.
    Posts
    4

    Default Re: Triggering an action on backend login

    Ok, thank you for the quick answer and the good code example, just one more question: How is this method triggered? Thats what i was actually looking for. Because as far as I know Contao executes the postLogin-Hook only when a Frontend-User logs in (or am I wrong with that?)

    I am running Contao 2.9.2 on a Server2Go as my development-sandbox. Maybe this information can help you to help me

    Thanks in advance
    Chris

  4. #4
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Triggering an action on backend login

    It does trigger on both, however it was only added to both later, not sure at which version. Look at the Contao Hooks page:
    https://contao.org/en/hooks.html

  5. #5
    New user
    Join Date
    12-10-12.
    Posts
    4

    Default Re: Triggering an action on backend login

    Oh, I've found the Problem. In Contao 2.9.2 (the Version I'm using) the postLogin-Hook is only triggered on a frontend user's login. From Contao 2.10 and onwards it triggers on both, front- and backend login.

    Thanks a lot for your Help, thyon!

    Chris

  6. #6
    New user
    Join Date
    12-10-12.
    Posts
    4

    Default Re: Triggering an action on backend login

    Well, somehow it still doesn't work out...

    Here's some of my code. I'd be glad if somebody'd have a look at it.

    This is a part of my config.php
    Code:
    //Cron-Job und Login-Hook für synchro
    $GLOBALS['TL_HOOKS']['postLogin'][] = array('Sync', 'synchronize');
    And this is an extract of the Sync-Class:
    Code:
    class Sync extends Frontend
    {
    	function __construct()
    	{
    		parent::__construct();
    	}
    
    	public function synchronize($objUser=null)
    	{
    Am I diong this right?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •