Posted by peterx on October 5, 2011 at 10:16pm
3 followers
Jump to:
| Project: | IP Login |
| Version: | 7.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed (maintainer needs more info) |
Issue Summary
We need a standard role for all users logged in by IP. I added the following function to get the role.
function ip_login_get_role_for_ip_login($role_name = 'IP login')
{
$role = db_select('role', 'r')
->fields('r', array('rid', 'name'))
->condition('name', $role_name)
->execute()->fetch();
return array($role->rid => $role->name);
}I found spots to add the role and remember the role. In this example, $new_roles has some roles added in by other code. The actual locations are lost in a number of other code modifications.
define('IP_LOGIN_ROLE', 'ip_login_role'); // Extra role for users logged in purely by IP Login.
if (!isset($_SESSION[IP_LOGIN_ROLE]))
{
$_SESSION[IP_LOGIN_ROLE] = ip_login_get_role_for_ip_login();
}
if (!empty($_SESSION[IP_LOGIN_ROLE]))
{
$new_roles = $_SESSION[IP_LOGIN_ROLE];
}
foreach($new_roles as $role_id => $role_name)
{
if(!isset($user->roles[$role_id]))
{
$user->roles[$role_id] = $role_name;
}
}
Comments
#1
I think adding a standard role to a user might a good idea. If this feature is added, it should be possible to change the role depending on IP-range.
BTW. isn't this functionality not implemented already by another module? I think so..
BTW2 It could be one of the actions as mentioned in #1288728: Restrict by IP-address
#2
Sounds sensible, however I'm very aware that this issue, #1271976: Subnet matching and #1252994: ip_match should be a multiple value field, possible changes to schema for better performance should be tackled together because this is a requires fundamental change to the schema or way the IP data is stored.
I would expect this might be possible right now with Rules though... Anyone?