You are here

drupalgap_logintoboggan.module in DrupalGap 7

Same filename and directory in other branches
  1. 7.2 modules/drupalgap_logintoboggan/drupalgap_logintoboggan.module

File

modules/drupalgap_logintoboggan/drupalgap_logintoboggan.module
View source
<?php

/**
 * Implements hook_drupalgap_site_settings().
 */
function drupalgap_logintoboggan_drupalgap_site_settings($names) {
  $names[] = 'logintoboggan_login_with_email';
  $names[] = 'logintoboggan_confirm_email_at_registration';
  return $names;
}

/**
 * Implements hook_services_resources_alter().
 */
function drupalgap_logintoboggan_services_resources_alter(&$resources, &$endpoint) {

  // Override the normal user login callback.
  if (variable_get('logintoboggan_login_with_email', 0) == 1 && isset($resources['user']['actions']['login']['callback'])) {
    $resources['user']['actions']['login']['callback'] = 'drupalgap_logintoboggan_services_login';
  }
}

/**
 * Replacement callback for the Services user login resource when the
 * LoginToboggan module is enabled. Optionally use the email address to login.
 *
 * @see _user_resource_login().        
 * @see https://drupal.org/node/1431724
 */
function drupalgap_logintoboggan_services_login($username, $password) {
  if (variable_get('logintoboggan_login_with_email', 0)) {
    $result = db_query("SELECT name FROM {users} WHERE LOWER(mail) = LOWER(:username)", array(
      ':username' => $username,
    ))
      ->fetch();
    if (!empty($result->name)) {
      $username = $result->name;
    }
  }
  return _user_resource_login($username, $password);
}

Functions

Namesort descending Description
drupalgap_logintoboggan_drupalgap_site_settings Implements hook_drupalgap_site_settings().
drupalgap_logintoboggan_services_login Replacement callback for the Services user login resource when the LoginToboggan module is enabled. Optionally use the email address to login.
drupalgap_logintoboggan_services_resources_alter Implements hook_services_resources_alter().