ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Ion auth access rights and roles

June 22, 2011 10:53am

Subscribe [4]
  • #1 / Jun 22, 2011 10:53am

    eggzy

    30 posts

    I’m working on user access rights for some pages in admin center and I use Ion auth for my auth library.
    I’d like something like select user and assign which pages can he access. My problem is that I don’t know how to setup my mysql table. Any suggestions?

  • #2 / Jun 22, 2011 10:02pm

    Ben Edmunds

    812 posts

    Check out Ion Auth v2, it has much better permissions groups support.  Then just create another table with something like controller, method, and groups that can access it.

  • #3 / Jun 23, 2011 6:11am

    eggzy

    30 posts

    This one? I will try, seems much more lightweight, any big improvements since there’s no documentation yet?

  • #4 / Jun 23, 2011 4:49pm

    Ben Edmunds

    812 posts

    The biggest changes are that it now supports a more powerful querying syntax, multiple groups per user, and hooks.

  • #5 / Jun 23, 2011 4:53pm

    toopay

    1583 posts

    Can you be more specific with “powerful querying syntax, multiple groups per user, and hooks”?

  • #6 / Jun 23, 2011 4:59pm

    Ben Edmunds

    812 posts

    You should really read through the code to get a good feel for it until I get some documentation made.

    Just an example with the querying, before if you wanted all active users ordered by email you couldn’t do it, now you just do:

    $users = $this->ion_auth->where('active', 1)
                            ->order_by('email')
                            ->users()
                            ->result();
  • #7 / Jun 24, 2011 10:24am

    eggzy

    30 posts

    how to get current user and his info. Before it was get_user() now something like $this->ion_auth->user() but it returns

    Ion_auth_model Object
    (
        [tables] => Array
            (
                [groups] => groups
                [users] => users
                [users_groups] => users_groups
                [meta] => users_meta
            )
    
        [activation_code] => 
        [forgotten_password_code] => 
        [new_password] => 
        [identity] => 
        [_limit] => 
        [_offset] => 
        [_order_by] => 
        [_order] => 
        [_hooks:protected] => stdClass Object
            (
            )
    
        [response:protected] => CI_DB_mysql_result Object
            (
                [conn_id] => Resource id #42
                [result_id] => Resource id #63
                [result_array] => Array
                    (
                    )
    
                [result_object] => Array
                    (
                    )
    
                [custom_result_object] => Array
                    (
                    )
    
                [current_row] => 0
                [num_rows] => 0
                [row_data] => 
            )
    
        [messages:protected] => Array
            (
            )
    
        [errors:protected] => Array
            (
            )
    
        [error_start_delimiter:protected] => 
    
    [error_end_delimiter:protected] =>
    
        [columns] => Array
            (
                [0] => first_name
                [1] => last_name
                [2] => nickname
                [3] => birthday
                [4] => gender
                [5] => country
                [6] => website
                [7] => team
                [8] => about
                [9] => avatar
                [10] => signature
            )
    
        [identity_column] => email
        [store_salt] => 
        [salt_length] => 10
        [meta_join] => user_id
        [message_start_delimiter] => 
    
    [message_end_delimiter] =>
    
    )
  • #8 / Jun 24, 2011 10:27am

    Ben Edmunds

    812 posts

    Add ->result() or ->result_array() to that.

    So:

    $this->ion_auth->current()->user()->result();
  • #9 / Jun 25, 2011 7:37pm

    defectivereject

    36 posts

    I’ve just added a user group to the meta table.
    Then saved this to the db session

    Then on each view requiring certain permissions I.e Super Admin or Manager I check this value for the logged in user. If it doesn’t match said value it loads a simple “only said role can view this page”
    If($userdata == “Super Admin” || $userdata == “Manager”){
    load page code
    }else{
    load error code
    }

  • #10 / Jun 25, 2011 7:56pm

    eggzy

    30 posts

    Hmm that’s good, but what if a user is in multiple groups.
    Maybe make an array, serialize it and save it to db, and after unserialize and check with in_array function, or something…

  • #11 / Jun 25, 2011 9:02pm

    defectivereject

    36 posts

    Hmm that’s good, but what if a user is in multiple groups.
    Maybe make an array, serialize it and save it to db, and after unserialize and check with in_array function, or something…

    Nah

    They’re in depts and groups

    Why would you be a user and a super admin?
    Why would you be a manager and a publisher?
    You can however be an engineer and a manager
    Or a designer and a manager.

    That way Engineer managers can’t see Designer managers sub groups/info, uless you want them to.

    So do a dept check then a user data check

    Simplifies things a hell of a ways, keeps db simplified and queries simplified.

    I have 75 depts and 12 user levels.
    Combination of access levels and control from that are astounding. Therefore not limiting

    Works for me!! Thing with most coding, must suit you.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases