Auto Login URL

Component ID

2302495

Component name

Auto Login URL

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

13744

Component created

Component changed

Component body

Overview

Creates auto login URLs on demand and through tokens.

This is mostly a developer's module. The better use for me is to convert all links of a specific text to auto login links.

It also provides two tokens that you may use on mass emailing like simplenews.

Use case

You may get an auto login URL for a user($uid).

// Drupal 7.
$auto_login_url = auto_login_url_create($uid, $destination);
print $auto_login_url;

// Drupal 8. As above plus.
$alu_service = Drupal::service('auto_login_url.create');
$auto_login_url = $alu_service->create($uid, $destination);
print $auto_login_url;

Or convert all links of a text to auto login for a user($uid).

// Drupal 7.
$auto_login_url_text = auto_login_url_convert_text($uid, $text);
print $auto_login_url_text;

// Drupal 8. As above plus.
$alu_service = Drupal::service('auto_login_url.create');
$auto_login_url_text = $alu_service->convert_text($uid, $text);
print $auto_login_url_text;

Also there are two tokens:
['tokens']['user']['auto-login-url-token']
['tokens']['user']['auto-login-url-account-edit-token']

These may be used in mass emailing modules or anywhere user tokens are available.

If you want extra tokens you may try Auto Login URL Tokens, which is a module in development that lets you create custom auto login URLs and expose them to tokens.

You can also easily create new tokens programmatically that use Auto Login URL functions

/**
 * Implements hook_token_info().
 */
function my_module_token_info() {

  // Add new tokens.
  $info = array();

  // Link that goes to user page.
  $info['tokens']['user']['auto-login-url-account-token'] = array(
    'name' => t("Auto Login URL account view"),
    'description' => t('This an auto login for the user account page.'),
  );

  return $info;
}

/**
 * Implements hook_tokens().
 */
function my_module_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'user') {
    $user = $data['user'];

    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'auto-login-url-account-token':
          $replacements[$original] = auto_login_url_create($user->uid, drupal_get_path_alias('user/' . $user->uid), TRUE);
          break;

      }
    }
  }

  return $replacements;
}

Requirements

Token

Known problems

For my usage I haven't seen any problems.

Similar modules

A very similar module that you may want to evaluate is urllogin. The main reason I created ALU is that I wanted an easier API to create tokens and URLs on demand. On the other hand urllogin focuses very much on security concerns.

Credits

Developed by Thanos Nokas
Sponsored by Human Factor