librelist archives

« back to archive

Kohana Auth example

Kohana Auth example

From:
Eduardo Huertas
Date:
2010-09-13 @ 12:42
Hello,

First of all I would like to thank all the people involved in
developing Kohana for their great work.

I was trying to implement the Auth module following the example at
http://kerkness.ca/wiki/doku.php

At http://kerkness.ca/wiki/doku.php?id=using_the_auth_module_in_your_controllers
I found the following...

--- snip ---

  class Controller_Layout extends Controller_Template
  {

      public $template = 'layout';

      // Controls access for the whole controller, if not set to FALSE
we will only allow user roles specified
      // Can be set to a string or an array, for example 'login' or
array('login', 'admin')
      // Note that in second(array) example, user must have both
'login' AND 'admin' roles set in database
      public $auth_required = FALSE;

      // Controls access for separate actions
      // 'adminpanel' => 'admin' will only allow users with the role
admin to access action_adminpanel
      // 'moderatorpanel' => array('login', 'moderator') will only
allow users with the roles login and moderator to access
action_moderatorpanel
      public $secure_actions = FALSE;

...
--- snip ---

But at the API, seems that the logged_in() method only takes a string
as argument.

Am I right or is there something I am missing?

Thanks in advance.
Eduardo

Re: [kohana] Kohana Auth example

From:
Nick Lamb
Date:
2010-09-13 @ 16:56
Eduardo,

I am not sure of your exact question, but I can tell you that the Auth
module method of logged_in() should be able to take an array or a string.
The array should be an array of the roles. Check out the code in
modules/auth/kohana/auth/orm.php. Line 33 should help you understand what is
happening with the $role variable passed to the logged_in() method.

Nick

On Mon, Sep 13, 2010 at 5:42 AM, Eduardo Huertas <e.huertas@gmail.com>wrote:

> Hello,
>
> First of all I would like to thank all the people involved in
> developing Kohana for their great work.
>
> I was trying to implement the Auth module following the example at
> http://kerkness.ca/wiki/doku.php
>
> At
> http://kerkness.ca/wiki/doku.php?id=using_the_auth_module_in_your_controllers
> I found the following...
>
> --- snip ---
>
>  class Controller_Layout extends Controller_Template
>  {
>
>      public $template = 'layout';
>
>      // Controls access for the whole controller, if not set to FALSE
> we will only allow user roles specified
>      // Can be set to a string or an array, for example 'login' or
> array('login', 'admin')
>      // Note that in second(array) example, user must have both
> 'login' AND 'admin' roles set in database
>      public $auth_required = FALSE;
>
>      // Controls access for separate actions
>      // 'adminpanel' => 'admin' will only allow users with the role
> admin to access action_adminpanel
>      // 'moderatorpanel' => array('login', 'moderator') will only
> allow users with the roles login and moderator to access
> action_moderatorpanel
>      public $secure_actions = FALSE;
>
> ...
> --- snip ---
>
> But at the API, seems that the logged_in() method only takes a string
> as argument.
>
> Am I right or is there something I am missing?
>
> Thanks in advance.
> Eduardo
>

Re: [kohana] Kohana Auth example

From:
Nick Lamb
Date:
2010-09-13 @ 17:04
Quick edit. Your auth file might be slightly different, so like 33 might not
be the exact one that you want. Also, I was incorrect in the file path that
I stated. In my projects, the file is actually located at modules/auth/*
classes*/kohana/auth/orm.php.

Nick

On Mon, Sep 13, 2010 at 9:56 AM, Nick Lamb <slick.user@gmail.com> wrote:

> Eduardo,
>
> I am not sure of your exact question, but I can tell you that the Auth
> module method of logged_in() should be able to take an array or a string.
> The array should be an array of the roles. Check out the code in
> modules/auth/kohana/auth/orm.php. Line 33 should help you understand what is
> happening with the $role variable passed to the logged_in() method.
>
> Nick
>
>
> On Mon, Sep 13, 2010 at 5:42 AM, Eduardo Huertas <e.huertas@gmail.com>wrote:
>
>> Hello,
>>
>> First of all I would like to thank all the people involved in
>> developing Kohana for their great work.
>>
>> I was trying to implement the Auth module following the example at
>> http://kerkness.ca/wiki/doku.php
>>
>> At
>> http://kerkness.ca/wiki/doku.php?id=using_the_auth_module_in_your_controllers
>> I found the following...
>>
>> --- snip ---
>>
>>  class Controller_Layout extends Controller_Template
>>  {
>>
>>      public $template = 'layout';
>>
>>      // Controls access for the whole controller, if not set to FALSE
>> we will only allow user roles specified
>>      // Can be set to a string or an array, for example 'login' or
>> array('login', 'admin')
>>      // Note that in second(array) example, user must have both
>> 'login' AND 'admin' roles set in database
>>      public $auth_required = FALSE;
>>
>>      // Controls access for separate actions
>>      // 'adminpanel' => 'admin' will only allow users with the role
>> admin to access action_adminpanel
>>      // 'moderatorpanel' => array('login', 'moderator') will only
>> allow users with the roles login and moderator to access
>> action_moderatorpanel
>>      public $secure_actions = FALSE;
>>
>> ...
>> --- snip ---
>>
>> But at the API, seems that the logged_in() method only takes a string
>> as argument.
>>
>> Am I right or is there something I am missing?
>>
>> Thanks in advance.
>> Eduardo
>>
>
>

Re: [kohana] Kohana Auth example

From:
Eduardo Huertas
Date:
2010-09-13 @ 17:36
2010/9/13 Nick Lamb <slick.user@gmail.com>:
> Quick edit. Your auth file might be slightly different, so like 33 might not
> be the exact one that you want. Also, I was incorrect in the file path that
> I stated. In my projects, the file is actually located at
> modules/auth/classes/kohana/auth/orm.php.
> Nick
>
> On Mon, Sep 13, 2010 at 9:56 AM, Nick Lamb <slick.user@gmail.com> wrote:
>>
>> Eduardo,
>> I am not sure of your exact question, but I can tell you that the Auth
>> module method of logged_in() should be able to take an array or a string.
>> The array should be an array of the roles. Check out the code in
>> modules/auth/kohana/auth/orm.php. Line 33 should help you understand what is
>> happening with the $role variable passed to the logged_in() method.
>> Nick


Nick,

Thanks for the quick answers.

Well the main thing is that I could not make it work when I was giving
an array as $role argument, it always returns false.
I will check the file you mention to see if I can find where is my error.

By the way, I am using Kohana 3.0.7

Best regards,
Eduardo