Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Simpleauth - Model_User
  • Hi !
    I would like to use the Simpleauth but I don't understand everything.
    My users have some additional datas (more than just mail password and username) and relationships with other tables of my DB. I also want to use an observer.
    But there is a problem. For instance, when I want to create a user with Auth::create_user(), I can't specify relationships and additionnal datas. Moreover, the observer is not called because the method create_user() doesn't use the model.

    I'm a little bit lost. So I expect you could help me.

    Thanks !
  • Harro VertonHarro Verton
    Accepted Answer
    Simpleauth is what the name implies, a simple authentication driver. It uses a table for user data, and a config file for everything else. It does not use Orm (or Model_Crud), and there is no Orm model provided for it.

    If you want to use Orm, switch to Ormauth. It uses an EAV container for additional data (where Simpleauth uses the profile_fields array). The included models can, like all other Auth classes, be extended or overridden in app, which allows you to define additional fields or observers.
  • Ok, thanks, I thought it was possible with Simpleauth.
    So, i'm trying to understand Ormauth. I have to store encrypted data (cannot possible in varchar) and RSA keys (varchar[>100]).
    So i'm skeptic about using EAV container to store data like these. I would like to store these data as normal attribute of user.
    To do that, what do I have to overwrite ? I imagine the Auth_User (model) but what else ?
  • Harro VertonHarro Verton
    Accepted Answer
    Well, it is, in the end it's just a table. But you will have to create your own ORM model, as the one supplied with the Auth package isn't compatible with the Simpleauth users table layout. And as you mentioned you can not use create_user() anymore, unless you extend the Simpleauth login driver in your app, and replace that method.

    If you use Ormauth, and you need additional columns in the table, you have to extend the class in app. Auth classes are aliased to global, just like the Core classes, so you extend them the same way.

    Do not overwrite (i.e. change files in a Fuel package), it will become a nightmare when you need to upgrade.
  • I see. 
    And I won't be able either to use create_user() with Ormauth, Is that it ? Unless I overwrite it.
  • Harro VertonHarro Verton
    Accepted Answer
    In the current version, it hardcoded only uses the fields defined in Auth. It looks like it is out of sync with the current capabilities of the ORM (which can create metadata on the fly now).

    As a test, can you replace the foreach block at line 280 of auth/classes/auth/login/ormauth.php with:

            // load all additional data, passed as profile fields
            $user->from_array($profile_fields);

    Which this change, you should be able to pass whatever you want in the profile fields array. If the field exists in the table (i.e. defined in the model properties) it will store the value in the table. If not, it will create an EAV entry for it.

    If this works I'll commit it (I'm on the road, can't test it myself at the moment).
  • I tried to override my Auth_User model but it doesn't works. I put it in :
    app/classes/model/auth/user.php
    I did like that : 
    namespace Model;

    class Auth_User extends \Auth\Model\Auth_User
    { ... }

    What do I need to put in bootstrap.php ?  I tried a lot of things but it didn't work.

    I test your modification modifying the Auth_User of the core (I know it's bad but it was just for the test), and it works perfectly : value is put in the user table if the field exists, otherwise, the value is stored in the metadata table as an EAV data.
  • Harro VertonHarro Verton
    Accepted Answer
    Thanks for confirming it. I will push a fix to 1.8/develop later.

    What you need in your app bootstrap is:

    Autoloader::add_classes(array(
        'Model\\Auth_User' => APPPATH.'classes/model/auth/user.php',
    ));

  • Thank you ! All is working.

Howdy, Stranger!

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

In this Discussion