Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Ormauth
  • Hi WanWizard,

    Another quick question, not sure if I'am doing something wrong here!

    auth config driver =  'driver' => 'Ormauth',

    But now here is what happens in the oil generated admin base controller.

    // Assign current_user to the instance so controllers can use it
    if (Config::get('auth.driver', 'Simpleauth') == 'Ormauth')
    {
    //$this->current_user = Auth::check() ? Model\Auth_User::find_by_username(Auth::get_screen_name()) : null;
    $this->current_user = Auth::check() ? Model_User::find_by_username(Auth::get_screen_name()) : null;
    }
    else
    {
    //$this->current_user = Auth::check() ? Model_User::find_by_username(Auth::get_screen_name()) : null;
    $this->current_user = Auth::check() ? Model\Auth_User::find_by_username(Auth::get_screen_name()) : null;
    }

    Notice I had to swap the two models around, am I doing something wrong here? Otherwise it will not work, because it cannot find the correct model.

    Thank you


  • The base controller contains:

            // Assign current_user to the instance so controllers can use it
            if (Config::get('auth.driver', 'Simpleauth') == 'Ormauth')
            {
                $this->current_user = Auth::check() ? Model\Auth_User::find_by_username(Auth::get_screen_name()) : null;
            }
            else
            {
                $this->current_user = Auth::check() ? Model_User::find_by_username(Auth::get_screen_name()) : null;
            }

    Which looks ok? Ormauth uses Model\Auth_User, Simpleauth uses Model_user?
  • This is the Error it is throwing if I leave it the correct way!

    Fatal Error!
    ErrorException [ Fatal Error ]:
    Class 'Model_User' not found

    APPPATH/classes/controller/base.php @ line 17

    12 $this->current_user = Auth::check() ? Model\Auth_User::find_by_username(Auth::get_screen_name()) : null;
    13 //$this->current_user = Auth::check() ? Model_User::find_by_username(Auth::get_screen_name()) : null;
    14 }
    15 else
    16 {
    17 $this->current_user = Auth::check() ? Model_User::find_by_username(Auth::get_screen_name()) : null;
    18 //$this->current_user = Auth::check() ? Model\Auth_User::find_by_username(Auth::get_screen_name()) : null;
    19 }
    20
    21 // Set a global variable so views can use it
    22 View::set_global('current_user', $this->current_user);
    Backtrace

    COREPATH/bootstrap.php @ line 66
  • I' am not using Simpleauth but Ormauth, so why is it trying to find the Model_User?

    I must be doing something wrong here but I do not know what?

  • It means that

    if (Config::get('auth.driver', 'Simpleauth') == 'Ormauth')

    returns false. So what have you configured as auth driver? Not "OrmAuth" by any chance?
  • return array(
    'driver' => 'Ormauth',
    'verify_multiple_logins' => false,
    'salt' => '026914-69125-034179-72360-345729',
    'iterations' => 10000,
    );

  • Looks like that Config::get() does not return what is configured.

    Which Fuel version are you on? I'm thinking about https://github.com/fuel/auth/commit/7894eca8bebfd5b6e95be7fd40dbf8604ebec253, a fix of 6 months ago.
  • Hi WanWizard,

    I' am running the newest FuelPHP version 1.8 from GitHub, Not the ver 2.0.

  • I know you're not on 2.0, it doesn't have either ORM or Auth atm. ;-)

    I'm clueless. Guess you need to start debugging, start with checking what that Config::get() returns, and try to find out why it does that.

    It looks like it can't find the auth config file loaded, so it returns the default?

    If this is the case, you can add

    \Config::load('auth', true);

    before the if, and check if that solves it.
  • Hi WanWizard,

    I have done some testing and this is what it is doing see the else in the if statement!

    class Controller_Base extends Controller_Hybrid {

    public function before()
    {
    parent::before();

    // This is echoing Simpleauth!
    echo Config::get('auth.driver', 'Simpleauth'); //exit;

    // Assign current_user to the instance so controllers can use it
    if (Config::get('auth.driver', 'Simpleauth') == 'Ormauth')
    {
    $this->current_user = Auth::check() ? Model\Auth_User::find_by_username(Auth::get_screen_name()) : null;
    }
    else
    {
    $this->current_user = Auth::check() ? Model_User::find_by_username(Auth::get_screen_name()) : null;

    // This is echoing out Ormauth!
    echo Config::get('auth.driver', 'Simpleauth'); exit;
    }

    // Set a global variable so views can use it
    View::set_global('current_user', $this->current_user);
    }

    }

    The one above the if statement is echoing Simpleauth, the else statement is echoing out Ormauth.

    So I do not know what is going on here.


  • I think you have run into the problem that the auth config file is loaded in the Auth class init method.

    But if you get to this if() statement before you have accessed Auth at all, the config file isn't loaded. You can test this by changing

    // This is echoing Simpleauth!
    echo Config::get('auth.driver', 'Simpleauth'); //exit;

    to

    // This is echoing SomethingElse!
    echo Config::get('auth.driver', 'SomethingElse'); //exit;

    If this is the case, add this before the if():

    \Config::load('auth', true);

    If this solves it, I'll fix the oil templates.
  • Maybe a better solution:

    // do we have a user?
    $loggedin = Auth::check();

    if ($loggedin)
    {
        $this->current_user = Config::get('auth.driver', 'Simpleauth') == 'Ormauth'
            ? Model\Auth_User::find_by_username(Auth::get_screen_name())
            : Model_User::find_by_username(Auth::get_screen_name());
    }
    else
    {
        $this->current_user = null;
    }

  • Hi WanWizard,

    I reinstalled everything and had the same problem. This time this got it to work, not sure what the problem is but here is the code that is working now for the Controller_Base

    class Controller_Base extends Controller_Hybrid {

    public function before()
    {
    parent::before();

    /**
    * WanWizard had me add this so that it will work!
    *
    * This now works Thank you WanWizard.
    */
    Config::load('auth', true);

    // Assign current_user to the instance so controllers can use it
    if (Config::get('auth.driver', 'Simpleauth') == 'Ormauth')
    {
    $this->current_user = Auth::check() ? Model\Auth_User::find_by_username(Auth::get_screen_name()) : null;
    }
    else
    {
    $this->current_user = Auth::check() ? Model_User::find_by_username(Auth::get_screen_name()) : null;
    }

    // Set a global variable so views can use it
    View::set_global('current_user', $this->current_user);
    }

    }

    Thank you Sir for your time, maybe it needs some fix.

  • HarroHarro
    Accepted Answer
    The problem is as I described.

    The auth config file is loaded when you access the Auth class for the first time. This code tried to access the config before Auth was used, so the config wasn't loaded.

    Most people do an Auth::check() in their base controller before method, so I assume this is why this problem hasn't surfaced earlier.

    I'll prepare a fix for the template.
  • Thank you Harro.

Howdy, Stranger!

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

In this Discussion