Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Sentry - Authentication Package
  • I do too, I have very complicated role structures. But from a level point of view, they are all users. I only need the admin flag to bypass role checking, any logged in user with admin = 1 has access to everything. The problem with levels is that you have to try to squeeze everything into a single number. And when you finally have managed it, you'll come across someone who needs rights you've assigned to two different level...
  • This seems to be heading somewhere really cool, but if I were you I'd hold off for now. There are some pretty big bugs and/or holes in the documentation in this project, and it really isn't usable in production code yet. For example, Sentry::user_exists() always returns true for any input (though this appears to be fixed in an as-yet-unmerged pull request):
    >>> Sentry::user_exists("what's up");
    Notice - Undefined index: id in PKGPATH/sentry/classes/sentry/user.php on line 108
    true
    >>> Sentry::user_exists(9494949494234)
    Notice - Undefined index: id in PKGPATH/sentry/classes/sentry/user.php on line 108
    true
    >>> Sentry::user_exists(false)
    true
    
    There are also a lot of weird inconsistencies, like getters that return associative arrays instead of model instances or methods that don't throw exceptions when the documentation claims they should. Anyway, I'm sure it'll all be fixed in time, but it might be worth holding off for now.
  • You're right. There are some issues and inconsistencies, most of which are obvious.
    I'm testing out as much as I can and trying to fix it. I see a lot of potential for me and others in this. Thanks EDIT:
    ====
    I just sent a pull request which should solve the issues you're talking about
  • For most issues there are pull requests waiting. Be patient, Cartalyst is closed over the holiday's, dpetrie mentioned that on IRC...
  • Harro Verton wrote on Thursday 29th of December 2011:
    For most issues there are pull requests waiting. Be patient, Cartalyst is closed over the holiday's, dpetrie mentioned that on IRC...

    Yeah, I saw (and contributed a couple myself). I figured they were closed over the holidays... lucky. Not trying to be mean or anything, just helpful :)
  • Please have a little patience, well be back in action on the 2nd and start fixing the found issues.
  • This is probably the wrong place to post this, but I can't see anywhere else to post it at present. When I try to install this package using oil, I get a database error:
    -bash-3.00$ php oil r migrate --packages=sentry
    
    Error - SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name '' with query: "CREATE TABLE IF NOT EXISTS `` (
            `id` int(11) NOT NULL AUTO_INCREMENT,
            `username` varchar(50) NOT NULL,
            ...
            `activated` tinyint NOT NULL,
            PRIMARY KEY `id` (`id`)
    ) DEFAULT CHARACTER SET utf8;" in COREPATH/classes/database/pdo/connection.php on line 137
    

    What I don't know, is whether this is a sentry problem, a core fuel problem, an oil package problem or just a local setup problem. I can see the database name is missing from the create statement, but where it goes missing is a mystery to me. Any pointers in where to look would be appreciated. -- Jason
  • Hey guys, I've been playing around with Sentry and have a question I just can't seem to anwser: Let's say I wanna list all users, and in that listing I wanna show each user's metadata (first and last name in my case), I would I go to do that? I tried to create a simple user model with a has_one relation with metadata :
    class Model_User extends \Orm\Model
    {
    
     // set table name manually
     // even tho it will magically map to 'users'
     protected static $_table_name = 'users';
    
     // set metadata relation
     protected static $_has_one = array('metadata' => array(
      'key_from' => 'id',
            'model_to' => 'Model_User_Metadata',
            'key_to' => 'user_id',
     ));
    
     // set available properties
     protected static $_properties = array(
      'id',
      'email'
     );
    
    }
    

    And then a users_metadata model:
    class Model_User_Metadata extends \Orm\Model
    {
    
     // set table name manually since we are using Sentry
     protected static $_table_name = 'users_metadata';
    
     // metadata belongs to user
     protected static $_belongs_to = array(
      'user' => array(
       'key_from' => 'user_id',
      )
     );
    
     // map metadata
     protected static $_properties = array(
      'first_name',
      'last_name'
     );
    
    }
    

    The problem is that when I try to fetch users with their related metadata, I get an SQL error because the ORM is trying to fetch an 'id' column from metadata but it doesn't have any :
    $data['members'] = Model_User::find('all', array(
       'related' => array('metadata')
      ));
    

    Am I handling this the right way? Thanks for the nice package!
  • According to Dsyme, sounds like Sentry development on the FuelPHP has stopped.
    Sentry v2.0 is only actively developed for Laravel. Sentry v1.1 only works with Fuel v1.1 From what I can tell, Fuel v1.3 does not work with Sentry v1.1
  • I wish I could help here but I have no real knowledge of how the ORM works as I have never used or plan to use it. Hopefully someone else can figure out what you have to do. I'll try to ask around in the Fuel IRC channel tomorrow. If there is no other way around it than adding an 'id' column, I will consider adding it in to support the ORM, but it may be something much simpler.
  • ORM requires an auto_increment primary key. You may call it what you like, but 'id' is preferred. You can just add it to the metadata table. As its value is auto generated, it won't bother Sentry, but it allows the ORM model to work on both tables.
  • Thanks for the prompt reply guys, I actually found the anwser which is quite simple :
    class Model_User_Metadata extends \Orm\Model
    {
    
     // set table name manually since we are using Sentry
     protected static $_table_name = 'users_metadata';
    
     // the primary key in this case is user_id
     protected static $_primary_key = array('user_id');
    
     // metadata belongs to user
     protected static $_belongs_to = array('user');
    
     // map metadata
     protected static $_properties = array(
      'user_id',
      'first_name',
      'last_name'
     );
    
    }
    

    Simply had to set primary_key as user_id and it worked as expected. As you said WanWizard the ORM find method expects a 'id' primary key, so setting it as user_id fixed it! By the way, would you recommend not using ORM with Sentry? How would you show all users with their metadata without ORM? Thanks again!
  • I think the statement was related to the database I/O within the sentry package. It needs to work wether or not you have the ORM package installed. Within your application, these are just tables that are part of your application, and there is no reason why you should not be allowed to pick your own access method...
  • Makes sense, thanks for the clarification Wiz!
  • Harro Verton wrote on Wednesday 18th of January 2012:
    ORM requires an auto_increment primary key. You may call it what you like, but 'id' is preferred. You can just add it to the metadata table. As its value is auto generated, it won't bother Sentry, but it allows the ORM model to work on both tables.

    Alright, I will add in an auto_increment field to Sentry if it is the proper way to support ORM, unless you think his above solution is fine.
  • @jasonjudge, i encountered same issue,. i fix it by, editing config and adding sentry to the always load, just like below
     'always_load'  => array(
    
      /**
       * These packages are loaded on Fuel's startup.  You can specify them in
       * the following manner:
       *
       * array('auth'); // This will assume the packages are in PKGPATH
       *
       * // Use this format to specify the path to the package explicitly
       * array(
       *     array('auth' => PKGPATH.'auth/')
       * );
       */
      'packages'  => array(
       'orm',
       'sentry',
      ),
    
    hope this will help,...
  • Rafael Hegina wrote on Wednesday 4th of January 2012:
    @jasonjudge, i encountered same issue,. i fix it by, editing config and adding sentry to the always load...

    That makes sense. This looks like an oil bug then - oil needs to load the module it is working on, before it can work on it, and is failing to do so. Thanks! -- Jason PS Works a treat, BTW. PPS Well, kind of. The migrate attempted to create the user table, found it already existed (due to the auth package having been installed) then silently skipped the table completely - no warning, no table update - nothing. Before installing, I did check that the columns already on the user table did not clash with what sentry wanted. I thought oil automatically worked out what updates need to be applied to bring existing tables up-to-date? Maybe I misunderstood how migration works - looks like it just applies updates that it knows it needs to apply to take the package from a known previous version. But no warnings - a bit misleading.
  • I don't see this to be an oil bug. The question is, why does Sentry's migrations require the package to be loaded? The answer is: it tries to load the sentry config file from the package. So, the bug is that the migration doesn't ensure that the package is loaded. This can be fixed by adding "\Package::load('sentry');" in the migrations file, in between the namespace definition and the class definition.
  • Harro Verton wrote on Wednesday 4th of January 2012:
    I don't see this to be an oil bug.

    I guess this comes down to expected functionality (dreaded documentation). If the oil developer says, "I am not going to assume that your upgrade script needs to access anything from the config file", then I guess the upgrade script needs to cover its back and load the package if it needs to. In sentry's case, it picks up the table names from its own config file.
  • So I've been migrating over to this package here are a few things i've gotten caught up on so far. 1) The register method returns the activation hash, not an array that can be referenced by $user like the docs show 2) The hash that you get back has TWO parts the login_column_value and the code seperated by a slash, its not just one string, so your activate method should have both these params. (I kept trying to just use one)
    public function action_activate($login_value = null, $code = null) {
    
            try {
              
                $activate = Sentry::activate_user($login_value,$code);
    
                if ($activate) {
                    Session::set_flash('success', 'your account is now active');
                } else {
                    Session::set_flash('error', 'there was an error activating this account');
                }
            } catch (SentryAuthException $e) {
                // issue activating the user
                // store/set and display caught exceptions such as a suspended user with limit attempts feature.
                $errors = $e->getMessage();
                Session::set_flash('error', $errors);
            }
    
            
    //        Response::redirect();
            
        }
    

    3) If you name your users table something else besides 'users' there is a sql bug whenever there is a call to update the table. I made a pull request for this
  • Yeah, I read the post on their site.
    It is possible to get the last version of the code? So we can update it to work on Fuel!
  • There is a new developer for Sentry that has taken over the Fuel version, see the repository on http://github.com/fuel-packages
  • Does the the newer Sentry 2.0 not work on Fuelphp 1.4. Everytime I try to run the oil r migrate --package=sentry I get a message of "Already on the latest migration for app:default." Even when I try using the SQL file to import the database needed for the package, and then try to use the package it doesn't know what it is. Any input. I know Above it said that Sentry 1.1 didn't work on 1.3 is that the case with 2.0?
  • --packages or -p, not --package
  • That's actually what I was using ( --packages), I just typed it wrong it the post.

Howdy, Stranger!

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

In this Discussion