Welcome Guest, Not a member yet? Register   Sign In
DX Auth 1.0.6 (Authentication library)
#21

[eluser]RHAngel[/eluser]
[quote author="dexcell" date="1228172425"][quote author="RHAngel" date="1228172055"]Also.. Why "is_admin" function query database to check user is admin or not. Maybe we can store role name in session userdata or use role id and check without additional query?

Code:
function is_admin()
    {
        // Load Models
        $this->ci->load->model('dx_auth/users', 'users');
        
        return $this->ci->users->check_admin($this->ci->session->userdata('user_id'))->num_rows() > 0;
    }

to something like

Code:
function is_admin()
    {        
        return $this->ci->session->userdata('role_id')==1?TRUE:FALSE;
    }

I don't know how are you, but I'm really don't like tons of queries to database for such simple functions.[/quote]

That's because in roles database,the admin role_id wasn't fixed, so you cannot using that way.

Maybe i should fix admin role_id into 2, so we can check that way.

Thanks for your input i'm gonna change the code and user guide to fix the admin role_id and upload it tomorrow.[/quote]

But look into your code in model Users, function check_admin. You use a fixed role name ADMIN.

In this case I'm always use role_id, role_ident and role_name. role_ident is fixed private name for roles (admin,user etc) but role_name is a public name where we can use multiple languages. In my case I have following:

role_id | role_ident | role_name
1 | admin | Администратор
2 | teacher | Учитель
3 | student | Студент

So role_ident is what I use in my code, and role_name is what I'm showing to users when I need to. Maybe you can get some ideas from it. Smile
#22

[eluser]dexcell[/eluser]
@RHAngel
Thanks you.


Your ideas about adding role_name into session user data is also good idea, that mean is_role function also doesn't need to check into database. I'm gonna implement it tomorrow.

I have to sleep now Smile bye. Thanks RHAngel.
#23

[eluser]RHAngel[/eluser]
Also some database fields can be renamed to better:

roles.id -> roles.role_id
roles.name -> roles.role_name
users.id -> users.user_id

When I wan't to use your library in big project where table 'users' have relations with other tables, 'users.id' will be a pain. So just look at all your primary keys for improvement.

Also you can benefit from it in places like this:
Code:
SELECT $u_table.*,
    $r_table.name AS role_name
->
Code:
SELECT $u_table.*,
    $r_table.role_name

About AR and UPPER in your models.
Code:
$sql = "SELECT 1 FROM ".$this->_table." WHERE UPPER('username') = UPPER(?)";
return $this->db->query($sql, array($username));
->
Code:
$this->db->select('username');
$this->db->where('LOWER(username)=',strtolower($username));
return $this->db->get($this->_table);

I use lower here, but you can use upper if you like it more. It works for me on PostgreSQL, I think should work on MySQL and other databases too.
#24

[eluser]RS71[/eluser]
Is there a way to have Roles and Groups? In the sense that Groups would be within Roles?

So user 'Joe' for example could have a general role of 'User' and belong to group 'Group_a'. So that 'Joe' only has the permissions of an 'User' role but also can only edit/view pages that belong to his 'Group_a' group.

If he tried to edit for example: http://www.site.com/item/edit/20456/ and that item didn't belong to his group, he wouldn't be able to edit it.

Err.. do you understand? heh
#25

[eluser]Milos Dakic[/eluser]
I also would like to see Groups added, but maybe it will move it away from an authentication library?
#26

[eluser]RS71[/eluser]
I don't believe it would stray from an Auth library since it would be dealing with the permissions/authentication of the user (in relation to a group) and not content, etc.
#27

[eluser]dexcell[/eluser]
[quote author="RS71" date="1228191879"]Is there a way to have Roles and Groups? In the sense that Groups would be within Roles?

So user 'Joe' for example could have a general role of 'User' and belong to group 'Group_a'. So that 'Joe' only has the permissions of an 'User' role but also can only edit/view pages that belong to his 'Group_a' group.

If he tried to edit for example: http://www.site.com/item/edit/20456/ and that item didn't belong to his group, he wouldn't be able to edit it.

Err.. do you understand? heh[/quote]

You can achieve this using role_uri table, see documentation in table anatomy about role_uri table, and see documentation about check_role_uri() function in function documentation.
#28

[eluser]dexcell[/eluser]
[quote author="RHAngel" date="1228172656"]
In this case I'm always use role_id, role_ident and role_name. role_ident is fixed private name for roles (admin,user etc) but role_name is a public name where we can use multiple languages. In my case I have following:

role_id | role_ident | role_name
1 | admin | Администратор
2 | teacher | Учитель
3 | student | Студент

So role_ident is what I use in my code, and role_name is what I'm showing to users when I need to. Maybe you can get some ideas from it. Smile[/quote]

There is a better approach to use multi language in here, and it doesn't necessarily to have indent field.

Here is the illustration.

Code:
this->lang->load('roles');

// Search role name in language file and translate it to prefered language.
echo $this->lang->line($this->dx_auth->get_role_name());
#29

[eluser]dexcell[/eluser]
[quote author="RHAngel" date="1228175100"]
About AR and UPPER in your models.
Code:
$sql = "SELECT 1 FROM ".$this->_table." WHERE UPPER('username') = UPPER(?)";
return $this->db->query($sql, array($username));
->
Code:
$this->db->select('username');
$this->db->where('LOWER(username)=',strtolower($username));
return $this->db->get($this->_table);

I use lower here, but you can use upper if you like it more. It works for me on PostgreSQL, I think should work on MySQL and other databases too.[/quote]

Thanks for your hint, i have converted all models into CI AR now, optimize DX_Auth so it won't search to database when calling is_admin(), is_role, and add some function.

I'm gonna tell in this thread if i have uploaded the new one.
#30

[eluser]dexcell[/eluser]
[quote author="RHAngel" date="1228175100"]Also some database fields can be renamed to better:

roles.id -> roles.role_id
roles.name -> roles.role_name
users.id -> users.user_id

When I wan't to use your library in big project where table 'users' have relations with other tables, 'users.id' will be a pain. So just look at all your primary keys for improvement.[/quote]

Well, one of the big reason i choose to name field like current DX Auth is because most of ORM library will require you to use fixed name 'id' as primary key, and 'some_id' as foreign key.

So if one of the DX Auth library user want to use ORM library, their application don't break.

Maybe someday in the future if CI also have native ORM library, i believe they will use this rules.




Theme © iAndrew 2016 - Forum software by © MyBB