Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Extending Existing Auth Driver, Config
  • Hi,

    The docs are a little confusing on extending an auth driver. I'm not sure if the docs need to be corrected or if this is a bug.

    Bottom of the page, it says to add an additional driver as so:
    // Add it as a second driver
    'driver' => array('Simpleauth''Mydriver'),

    But if you're extending an existing driver, as I am, your driver name has to come first or fuelphp loads some methods from the first driver rather than overloading it.
    'driver' => array('Mydriver''Simpleauth'),

    e.g. I have in app/classes/auth/login/simpleauthsoft.php

    class Auth_Login_Simpleauthsoft extends \Auth\Auth_Login_Simpleauth
    //...
    protected function perform_check()
    protected function validate_user()
    //... more...
    public function reset_password() {
    $new_password = \Str::random('alnum', 16); //changed 8 to 16
    //...
    }

    As long as I had Simpleauth come before Simpleauthsoft, the perform_check() and validate_user(), etc, all seemed to work fine. But reset_password() wasn't overloading properly. No errors, it just kept running the method in Simpleauth rather than Simpleauthsoft.

    Finally I changed the order from Simpleauth, Simpleauthsoft to Simpleauthsoft, Simpleauth, and everything works as it should.
  • The Auth framework supports multiple concurrent login drivers, this is for example used if you want to use a corporate Active Directory driver first, but want local users as fallback, for example because not all users are corporate users.

    When you login (or log out), the drivers are used in turn, in order of definition, until one succeeds. Or if you have enabled multiple_logins in the Auth config, all of them are called.

    This is what that section of the docs is about, it has nothing to do with extending, so you misunderstood that part.

    Extending a class is exactly that, it doesn't work any different for Auth then for other classes in the fhe framework. So only define one driver, your "Simpleauthsoft" driver.
  • Aha! That makes way more sense. Thanks.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion