October CMS resources and help articles

Simple and to the point. Optimized by the community.

Override default backend sign in behavior

4
by larryb, last modified on February 11th, 2020

Often times we need to tie into the signin flow for the Backend. This is common when trying to support SSO, or authenticating with LDAP/AD mechanisms.

This trick shows you how to do this by overriding the Backend Controller's sign in method. The Trick "Re-use and migrate WordPress password hashes in October" shows you an alternative approach by overriding October's AuthManager class (see steps 3 and 4 of the Trick).

You can override the default signin behavior for the backend with a fairly simple addition to your plugin's boot() method:

/*
 * Override default sign in behavior
 */
Event::listen('backend.page.beforeDisplay', function ($controller, $action) {
    if(!$controller instanceof \Backend\Classes\Controller) {
        return;
    }
    if ($action == 'signin') {
        try {
            if (post('postback')) {
                return $this->signin_onSubmit();
            }
        } catch (Exception $ex) {
            Flash::error($ex->getMessage());
        }
    }
});

That's pretty much all there is to it. Obviously the logic for the sign in behavior will need to be implemeneted per your requirements, but the possibilities are limitless.

Discussion

2 comments

0
douggough
Post on September 27th, 2019 3:09 PM

Nice clear explanation. Can I suggest you provide a real world example of how you would solve a specific problem with this technique? I think it would be helpful to people who are still on the fence about building a site with October.

1
larryb
Post on October 1st, 2019 12:29 PM

hi @douggough, thanks for the reply! I'll be blogging soon about how I use these tricks to develop custom october apps, stay tuned! You can also follow me on twitter @thegreatbarker for my latest announcements.

We use cookies to measure the performance of this website. Do you want to accept these cookies?