We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

cp login extension

Development and Programming

jeremydouglas's avatar
jeremydouglas
292 posts
18 years ago
jeremydouglas's avatar jeremydouglas

Would it be possible to write an extension using the cp_member_login hook to redirect a specific member to a specific page?

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
18 years ago
Jamie Poitra's avatar Jamie Poitra

Hey jez,

That hook kicks in after a user has successfully sent a valid login and password and immediately after a new session has been created for them.

Immediately after the hook the following is done via the rest of the default EE login code:

// -------------------------------------------
    // 'cp_member_login' hook.
    //  - Additional processing when a member is logging into CP
    //
        $edata = $EXT->call_extension('cp_member_login', $query->row);
        if ($EXT->end_script === TRUE) return;
    //
    // -------------------------------------------
               
        /** ----------------------------------------
        /**  Log the login
        /** ----------------------------------------*/
        
        // We'll manually add the username to the Session array so
        // the LOG class can use it.
        $SESS->userdata['username']  = $IN->GBL('username', 'POST');
        
        $LOG->log_action($LANG->line('member_logged_in'));
        
        /** ----------------------------------------
        /**  Delete old password lockouts
        /** ----------------------------------------*/
        
        $SESS->delete_password_lockout();

        /** ----------------------------------------
        /**  Redirect the user to the CP home page
        /** ----------------------------------------*/

        $return_path = $REGX->decode_qstr($IN->GBL('return_path', 'POST').'?S='.$session_id);
        
        if ($IN->GBL('bm_qstr', 'POST'))
        {
            $return_path .= AMP.$IN->GBL('bm_qstr', 'POST');
        }

        $FNS->redirect($return_path);
        exit;

You would likely in your case want to replicate that in your extension and then provide alternate return_paths based on the member_id of the member logging in.

Jamie

       
jeremydouglas's avatar
jeremydouglas
292 posts
18 years ago
jeremydouglas's avatar jeremydouglas

thanks Jamie, I’ll take a look at that

       
jeremydouglas's avatar
jeremydouglas
292 posts
18 years ago
jeremydouglas's avatar jeremydouglas

finally got a chance to work on this. Thanks for the help, worked exactly as you said.

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
18 years ago
Jamie Poitra's avatar Jamie Poitra

Glad to hear it.

Jamie

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Hi Jez,

Not asking to see your code or anything as I could probably manage this myself now that I created my own first extension today!! 😊

But…

… I was wondering what kind of instances you would need this functionality for?

Best wishes,

Mark

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.