Part of the EllisLab Network
   
3 of 63
3
DX Auth 1.0.6 (Authentication library)
Posted: 01 December 2008 01:10 PM   [ Ignore ]   [ # 21 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  148
Joined  10-22-2008

@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.

 Signature 

DX Auth library - User guide

Profile
 
 
Posted: 01 December 2008 01:45 PM   [ Ignore ]   [ # 22 ]  
Summer Student
Total Posts:  14
Joined  10-07-2007

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:

SELECT $u_table.*,
    
$r_table.name AS role_name 

->

SELECT $u_table.*,
    
$r_table.role_name 

About AR and UPPER in your models.

$sql "SELECT 1 FROM ".$this->_table." WHERE UPPER('username') = UPPER(?)";
return 
$this->db->query($sql, array($username)); 

->

$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.

Profile
 
 
Posted: 01 December 2008 06:24 PM   [ Ignore ]   [ # 23 ]  
Lab Assistant
RankRank
Total Posts:  158
Joined  11-21-2008

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

Profile
 
 
Posted: 01 December 2008 09:27 PM   [ Ignore ]   [ # 24 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  133
Joined  06-06-2008

I also would like to see Groups added, but maybe it will move it away from an authentication library?

 Signature 

Milos Dakic

Profile
 
 
Posted: 01 December 2008 10:11 PM   [ Ignore ]   [ # 25 ]  
Lab Assistant
RankRank
Total Posts:  158
Joined  11-21-2008

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.

Profile
 
 
Posted: 02 December 2008 12:02 AM   [ Ignore ]   [ # 26 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  148
Joined  10-22-2008
RS71 - 01 December 2008 11:24 PM

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

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.

 Signature 

DX Auth library - User guide

Profile
 
 
Posted: 02 December 2008 12:06 AM   [ Ignore ]   [ # 27 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  148
Joined  10-22-2008
RHAngel - 01 December 2008 06:04 PM

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

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

Here is the illustration.

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()); 
 Signature 

DX Auth library - User guide

Profile
 
 
Posted: 02 December 2008 12:10 AM   [ Ignore ]   [ # 28 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  148
Joined  10-22-2008
RHAngel - 01 December 2008 06:45 PM

About AR and UPPER in your models.

$sql "SELECT 1 FROM ".$this->_table." WHERE UPPER('username') = UPPER(?)";
return 
$this->db->query($sql, array($username)); 

->

$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.

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.

 Signature 

DX Auth library - User guide

Profile
 
 
Posted: 02 December 2008 12:16 AM   [ Ignore ]   [ # 29 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  148
Joined  10-22-2008
RHAngel - 01 December 2008 06:45 PM

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.

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.

 Signature 

DX Auth library - User guide

Profile
 
 
Posted: 02 December 2008 02:06 AM   [ Ignore ]   [ # 30 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  148
Joined  10-22-2008

Updated the download. see first page, there is also change log available.

If you already downloaded previous version, i encourage you to download this latest version.
There is some file i recall forgot to add in previous version.

 Signature 

DX Auth library - User guide

Profile
 
 
   
3 of 63
3