You are here

public function UrlloginController::userList in urllogin 8

Same name and namespace in other branches
  1. 2.x src/Controller/UrlloginController.php \Drupal\urllogin\Controller\UrlloginController::userList()

Link to download of user access URL's as a csv.

A theme template file is needed of the page-urllogin-userlist.csv.tpl containing the single line: < ?php print $content; ? >.

@todo test whether profile module is installed and if fields are correct @todo look at integrating with content profile module

Return value

array Page containing user access URL's as a file of tab separated variables

1 string reference to 'UrlloginController::userList'
urllogin.routing.yml in ./urllogin.routing.yml
urllogin.routing.yml

File

src/Controller/UrlloginController.php, line 163

Class

UrlloginController
Controller routines for urllogin routes.

Namespace

Drupal\urllogin\Controller

Code

public function userList() {
  module_load_include('inc', 'urllogin', 'urllogin_security');
  $codekey = \Drupal::config('urllogin.settings')
    ->get('codekey');
  $passphrase = urllogin_passphrase();
  $thissite = \Drupal::request()
    ->getSchemeAndHttpHost();
  $destination = '/' . \Drupal::config('urllogin.settings')
    ->get('destination');
  $output = "UID, Username, Email, Login URL \n";
  $response = new Response();

  // Tell browser this is not a web page but a file to download.
  $response->headers
    ->set('Content-type', 'text/csv; charset=utf-8');
  $response->headers
    ->set('Content-Disposition', 'inline; filename="userlist.csv"');

  // Load user object for active accounts.
  $ids = \Drupal::entityQuery('user')
    ->condition('status', 1)
    ->execute();
  $users = User::loadMultiple($ids);

  // Generate each row in CSV file.
  foreach ($users as $data) {

    // Check if user has permission to login via url.
    if ($data
      ->hasPermission('login via url')) {

      // Create login url.
      $urlstr = $thissite . '/l/' . urllogin_encode($data->uid->value, $codekey, $passphrase) . $destination;
      $output .= $data->uid->value . "," . $data->name->value . "," . $data->mail->value . "," . $urlstr . "\r\n";
    }
  }
  $response
    ->setContent(render($output));
  return $response;
}