RSS
 

Leave a Reply

Tip:
If you need to post a piece of code use {code type=php}...{/code}.
Allowed types are "php", "mysql", "html", "js", "css".

Please do not escape your post (leave all ", <, > and & as they are!). If you have encoded characters and need to reverse ("decode") it, you can do that here!
 

 
  1. Matt

    January 2, 2012 at 17:19

    This is really great and something sorely missing from the core Cake distro. My only suggestion is that you do not assume the reader has so much in place already. I suspect most people who are looking for something like this are doing so because they could not get the complicated aro/aco stuff working easily and would love a step-by-step of getting tinyAuth up and running.

    Also, the examples and tutorials in the cookbook 2.0 have users/groups tables instead of users/roles. You might want to specify the schema your plugin expects since it is different from those.

     
  2. Matt

    January 2, 2012 at 17:24

    There is one thing I am having trouble with. When an action is not allowed, the site just hangs and returns nothing. Any suggestions on how to have it return some kind of page, or return back to where it came from with a flash error message?

    Here is what I have in my AppController beforeFilter()

    //Configure AuthComponent
    $this->Auth->authorize = array('Tools.Tiny');
    $this->set('authUser', $this->Auth->user());
    //$this->Auth->authenticate = array('Form');
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
    $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
    $this->Auth->loginRedirect = array('controller' => 'contacts', 'action' => 'index');
     
  3. Mark

    January 2, 2012 at 22:40

    Good points. I will have to refine it.

    Ok, so roles in 1.3 have changed to groups in 2.0 then? But they still seem to be 1:N only (multiple roles/groups per user not possible). The documentation doesn't reveal much.

    About your problem:
    Your Auth component is responsable for that. The Tiny (or any other Auth for that matter) can only return true/false or the right to access this page. It used to redirect to /. But I opened a ticket (http://cakephp.lighthouseapp.com/projects/42648/tickets/2390-auth-component-should-not-redirect-to-index-if-loginredirect-is-set) because it doesnt make any sense if you are a logged in user (you would want to be redirected to $this->Auth->loginRedirect).
    And thats exactly what the core Auth component does:

    $this->flash($this->authError);
    $controller->redirect($controller->referer('/'), null, true);
     
  4. Matt

    January 3, 2012 at 04:07

    OK, I think I figured out part of the hanging issue. When a page is not authorized, it is trying to redirect to /, but that is also not authorized. I have not figured out how to specify / in the acl.ini file. It is probably obvious, but I'm still a cake newbie.

     
  5. Mark

    January 3, 2012 at 11:30

    Well, that is a misconfiguration :) Your homepage (/) should always be public. Use $this->Auth->allow() in your controller for this action.

     
  6. Forbin

    January 7, 2012 at 15:37

    Does this work in 1.3?

     
  7. jetwes

    January 9, 2012 at 12:24

    I always get a failure after login:

    Notice (8): Undefined index: role_id [APP/Plugin/Tools/Controller/Component/Auth/TinyAuthorize.php, line 69]

    Mein Model ist so definiert:

    class User extends AppModel{
                public $name = 'User';
                public $belongsTo = array(
                    'Group' => array(
                        'className' => 'Group',
                        'foreignKey' => 'group_id',
                    )
                );
     
                public $hasAndBelongsToMany = array(
                    'Role' => array(
                        'className'                 => 'Role',
                        'joinTable'                 => 'roles_users',
                        'foreignKey'                => 'user_id',
                        'assosciationForeignKey'    => 'role_id',
                        'unique'                    => true,
                    ),
                    'Shop' => array(
                        'className'                 => 'Shop',
                        'joinTable'                 => 'shops_users',
                        'foreignKey'                => 'shop_user_id',
                        'assosciationForeignKey'    => 'shop_id',
                        'unique'                    => true,
                    )
                );

    Any Hints?
    Good work – keep on!

     
  8. Mark

    January 9, 2012 at 12:32

    You need to make sure the session contains the role information after logging the user in:

    HABTM (multiple roles per user):
    User.Role.id1,id2,…,idx,

    BT (one role per user):
    User.role_id

     
  9. jetwes

    January 9, 2012 at 17:32

    got it, thanks again for the quick support! Is there a easy way to build a dynamic menu with the acls? (It depends on the role if a user can see the menu item)
    Keep up the good work!

     
  10. Mark

    January 11, 2012 at 01:54

    I updated the class to allow other parent model relations besides "User<–>Role". It should be closer to the cookbook now, where they use "Groups".

    @jetwes
    There sure is a way to do that. I would like to use sth like that very much, as well.
    Basically we would need a helper to display certain "navigation" blocks and hide the ones you don't have access to. With caching this should be not too resource-eating…

     
  11. Nitish

    January 24, 2012 at 11:31

    Hey Mark,

    Thanks for the good work.

    I am saying its good, because it looks like that &amp; you won't claim it being the fastest &amp; easiest..

    I am a newbie in Cake, I have setup cake2.0 &amp; I tried to follow your instructions but like "Matt" said, you can still make the tutorial more clear &amp; to the point &amp; step by step. I got confused at points like -

    "If you don’t want this, use Configure to store your keys like so:"

    I took some time to figure out that I need to do this in bootstrap file using Configure::write.. I am still not sure if this is the right way..

    Basically, steps starting from we downloading cake &amp; till the point where we are ready with a basic setup will be something that will help this a lot

    Thanks &amp; Hoping you help me out

     
  12. Nitish

    January 24, 2012 at 11:45