Love Fuel?    Donate

FuelPHP Forums

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

    I've been trying to set up OrmAuth but it is just refusing to work. I've copied over the auth.php and ormauth.php files over to my app/config directory and edited them accordingly but when I go into Terminal and execute the "oil refine migrate --packages=auth" command, it sets up the migrations table in the my database but nothing else. I have no idea why it's not working but I've obviously gone wrong somewhere but for the life of me I don't know where...

    I'm using version 1.6 on OS X 10.8 with MAMP.
  • It creates the migrations table, so we can assume the database connection is ok, and oil can connect to the database.

    Which PHP version are you using? We've been getting reports that the glob() statement we use to enumerate all migrations is buggy in some PHP versions and won't find the migration files...

    Assuming you don't have unfinished migrations lying around, what does

    "oil refine migrate --all"

    do?

    And you have defined the driver as "ormauth" in the auth.php file?
  • yep, i've done that in the auth.php config file. PHP version is 5.4.10

    That Oil command generates this message:

    Already on the latest migration for app:default.
    Already on the latest migration for package:auth
  • Ok, so you've already run all migrations. This should be visible in the migrations table and config file.

    Perhaps you ran the migrations before configuring Auth? Then it will run them, and decide no tables needed to be created because you didn't have auth configured.

    If this is the case, change the driver in auth.php to "xyz" (or something), then revert the migrations using:

    oil refine migrate:down --packages=auth

    and repeat that until there is no more to revert. Then change your auth.php driver back to "ormauth" and run the migrations again.
  • Tried that but it is still not working, it still just populates the migrations table and does nothing else
  • HarroHarro
    Accepted Answer
    Just checked the migration code, it expects "Ormauth" as driver name (class names are case sensitive in Fuel). So perhaps that is the issue?
  • Bingo! That does the trick! Thank you very much Harro
  • Actually I may have spoken too soon... Having had all the tables set up correctly, I used Oil to generate an admin panel "oil generate something blah:string....." but when I go to the admin log in page and try to log in, I get an error saying "Class 'Model_User' not found"

    Do the models not get generated automatically or is there a separate command that I need to run?
  • I don't know what oil generates, and what you exactly generated.

    What exact commands did you type?
  • From the beginning:

    oil refine migrate --packages=auth
    Performed migrations for package:auth:
    001_auth_create_usertables
    002_auth_create_grouptables
    003_auth_create_roletables
    004_auth_create_permissiontables
    005_auth_create_authdefaults
    006_auth_add_authactions
    007_auth_add_permissionsfilter

    oil generate admin pages title:string slug:string summary:text body:text publisher:int
    Creating controller: /Applications/MAMP/htdocs/cms/fuel/app/classes/controller/base.php
    Creating controller: /Applications/MAMP/htdocs/cms/fuel/app/classes/controller/admin.php
    Creating views: /Applications/MAMP/htdocs/cms/fuel/app/views/admin/template.php
    Creating views: /Applications/MAMP/htdocs/cms/fuel/app/views/admin/dashboard.php
    Creating views: /Applications/MAMP/htdocs/cms/fuel/app/views/admin/login.php
    Creating migration: /Applications/MAMP/htdocs/cms/fuel/app/migrations/001_create_pages.php
    Creating model: /Applications/MAMP/htdocs/cms/fuel/app/classes/model/page.php
    Creating controller: /Applications/MAMP/htdocs/cms/fuel/app/classes/controller/admin/pages.php
    Creating view: /Applications/MAMP/htdocs/cms/fuel/app/views/admin/pages/index.php
    Creating view: /Applications/MAMP/htdocs/cms/fuel/app/views/admin/pages/view.php
    Creating view: /Applications/MAMP/htdocs/cms/fuel/app/views/admin/pages/create.php
    Creating view: /Applications/MAMP/htdocs/cms/fuel/app/views/admin/pages/edit.php
    Creating view: /Applications/MAMP/htdocs/cms/fuel/app/views/admin/pages/_form.php
    Creating view: /Applications/MAMP/htdocs/cms/fuel/app/views/template.php

    oil refine migrate
    Performed migrations for app:default:
    001_create_pages
  • I looked into the generated code, but I can't find any reference to Model_User. What exactly generates that error?

    There is a user model in Auth, but that is called \Model\User (it's namespaced).
  • The error is coming from here: APPPATH/classes/controller/admin.php @ line 50

    Line 50: $current_user Model_User::find_by_username(Auth::get_screen_name());

    I'm assuming this error is occurring because there isn't a 'user.php' file being generated in 'app/classes/model' like there is if you use SimpleAuth.

  • It only generates that model if you generate the admin backend for the users table, which is required for Simpleauth (as that doesn't have a model), but not for Ormauth, which brings it's own model.

    Someone has to look into the code and see how to fix this, for the time being, you can manually change it to

    $current_user = \Model\Auth_User::find_by_username(Auth::get_screen_name());

    to make it work with Ormauth.

    Can you create an issue for this at https://github.com/fuel/oil/issues so it can be looked at?
  • I changed that line to what you suggested (as well as doing the same for line 10 in base.php) but now it's throwing up a notice error

    Fuel\Core\PhpErrorException [ Notice ]: Object of class Auth\Model\Auth_Group could not be converted to int

    PKGPATH/auth/classes/auth/group/ormgroup.php @ line 90

    Line 90: return in_array(array($this->id$group), $groups);

    I'll put this on GitHub
  • HarroHarro
    Accepted Answer
    Hmm...

    Without looking at the admin code, my guess is it checks for membership of group '100', which in Simpleauth is the "admin" group. Ormauth doesn't have fixed group id's, as the id is an auto-increment value in your table.

    Since Ormauth supports permissions, it would be better to have it check that, but that doesn't help you now. Probably the quickest thing to do is to check in your group table what the 'id' is of your admin group, and change the admin controller (or login controller?) to check that value instead of 100...
  • Magic! That's fixed it. Thank you very much!

Howdy, Stranger!

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

In this Discussion