Like the title says I would like an easy way to remove access to accounts that have not logged into the drupal website in a set amount of time. Is there any module that does this itself, a way for the rules module to take care of this function, or any other advice for this kind of issue? Thank you.

Comments

VM’s picture

I'd investigate the rules.module and views_bulk_operations.module

peterjlord’s picture

Something along the lines of:
1) Install rules and https://www.drupal.org/project/views_rules
2) Create a view similar to this which you can tweak slightly

$view = new view();
$view->name = 'display_users_not_logged_in';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'Display Users Not Logged In';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'administer users';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '100';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '9';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'name' => 'name',
  'login' => 'login',
  'created' => 'created',
  'access' => 'access',
  'login_1' => 'login_1',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'name' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'login' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'created' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'access' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'login_1' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
/* Field: User: Uid */
$handler->display->display_options['fields']['uid']['id'] = 'uid';
$handler->display->display_options['fields']['uid']['table'] = 'users';
$handler->display->display_options['fields']['uid']['field'] = 'uid';
$handler->display->display_options['fields']['uid']['link_to_user'] = FALSE;
/* Sort criterion: User: Created date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'users';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: User: Last access */
$handler->display->display_options['filters']['access']['id'] = 'access';
$handler->display->display_options['filters']['access']['table'] = 'users';
$handler->display->display_options['filters']['access']['field'] = 'access';
/* Filter criterion: User: Last login */
$handler->display->display_options['filters']['login']['id'] = 'login';
$handler->display->display_options['filters']['login']['table'] = 'users';
$handler->display->display_options['filters']['login']['field'] = 'login';

/* Display: Rules */
$handler = $view->new_display('views_rules', 'Rules', 'views_rules_1');
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '0';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['rules_variables'] = array(
  'name' => array(
    'enabled' => 1,
    'rendered' => 0,
    'type' => 'user',
    'label' => 'User: Name',
    'name' => 'name',
  ),
  'login' => array(
    'enabled' => 1,
    'rendered' => 0,
    'type' => 'user',
    'label' => 'Last login',
    'name' => 'login',
  ),
  'created' => array(
    'enabled' => 1,
    'rendered' => 0,
    'type' => 'date',
    'label' => 'Created date',
    'name' => 'created',
  ),
  'access' => array(
    'enabled' => 1,
    'rendered' => 0,
    'type' => 'date',
    'label' => 'Last access',
    'name' => 'access',
  ),
  'login_1' => array(
    'enabled' => 1,
    'rendered' => 0,
    'type' => 'date',
    'label' => 'Last login',
    'name' => 'login_1',
  ),
  'uid' => array(
    'enabled' => 1,
    'rendered' => 0,
    'type' => 'user',
    'label' => 'Uid',
    'name' => 'uid',
  ),
);

3) Create a rule like this (Note This deletes User Entities so don't use on production site)
This will load the view loop through users and delete on cron event

{ "rules_prune_users_that_have_not_logged_in_" : {
    "LABEL" : "Prune Users That Have Not Logged In ",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "views_rules" ],
    "ON" : { "cron" : [] },
    "DO" : [
      { "drupal_message" : { "message" : "Pruning Users at [site:current-date]" } },
      { "views_rules_collect_rows" : {
          "USING" : { "views_rules_display" : "display_users_not_logged_in:views_rules_1" },
          "PROVIDE" : {
            "name" : { "name" : "List of User: Name" },
            "uid" : { "uid" : "List of Uid" }
          }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "uid" ] },
          "ITEM" : { "list_item" : "Current list item" },
          "DO" : [
            { "drupal_message" : { "message" : "Delete [list-item:uid] [list-item:name]" } },
            { "entity_fetch" : {
                "USING" : { "type" : "user", "id" : [ "list-item:uid" ] },
                "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
              }
            },
            { "entity_delete" : { "data" : [ "entity-fetched" ] } }
          ]
        }
      }
    ]
  }
}

That should get you most of the way there