You are here

sharedemail.module in Shared Email 5

Same filename and directory in other branches
  1. 8.2 sharedemail.module
  2. 6 sharedemail.module
  3. 7 sharedemail.module

Allows users to share an email address

File

sharedemail.module
View source
<?php

/**
 * @file
 * Allows users to share an email address
 */

/**
 * Implementation of hook_help().
 */
function sharedemail_help($section) {
  switch ($section) {
    case 'admin/help#sharedemail':
      $output = '<p>' . t('Allows users to use the same email address for multiple accounts') . '</p>';
      return $output;
  }
}

/**
 * Implementation of hook_perm().
 */
function sharedemail_perm() {
  return array(
    'administer sharedemail',
    'show warning text',
  );
}

/**
 * Implementation of hook_menu().
 */
function sharedemail_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/settings/sharedemail',
      'title' => t('Sharedemail'),
      'description' => t('Configure the message that sharedemail displays.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'sharedemail_admin_settings',
      ),
      'access' => user_access('administer sharedemail'),
      'type' => MENU_NORMAL_ITEM,
    );
  }
  return $items;
}

/**
 * Configure Sharedemail settings
 *
 * @ingroup forms
 * @see system_settings_form()
 */
function sharedemail_admin_settings() {
  $form = array();
  $msg = t('WARNING: The e-mail address you are using, has already been registered on this site by another user. ' . 'You should be aware that personal information such as password resets will be sent to this address. ' . 'We strongly recommend changing your registered address to a different e-mail address. ' . 'You can do this at any time from your account page when you login.');
  $form['sharedemail_msg'] = array(
    '#type' => 'textarea',
    '#title' => t('Sharedemail Message'),
    '#default_value' => variable_get('sharedemail_msg', $msg),
    '#rows' => 15,
    '#description' => t('The warning message to display to the user when they enter in an e-mail address already used by another user.'),
  );
  return system_settings_form($form);
}

/**
 * Implementation of hook_user().
 */
function sharedemail_user($type, &$edit, &$user, $category = NULL) {
  $mail = $edit['mail'];
  if ($type == 'validate' && !user_validate_mail($mail)) {

    // Only show warning message if more than 1 user with the same email
    if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(mail) = LOWER('%s')", $user->uid, $edit['mail'])) > 0) {
      $edit['mail'] = 'sharedemail_' . $mail;

      // Show warning text to those with the permission selected
      if (user_access('show warning text')) {
        drupal_set_message(variable_get('sharedemail_msg', ''));
      }
    }
  }
}

/**
 *  Implementation of hook_simpletest().
 */
function sharedemail_simpletest() {
  $module_name = 'Shared E-mail';
  $dir = drupal_get_path('module', 'sharedemail') . '/tests';
  $tests = file_scan_directory($dir, '\\.test$');
  return array_keys($tests);
}

Functions

Namesort descending Description
sharedemail_admin_settings Configure Sharedemail settings
sharedemail_help Implementation of hook_help().
sharedemail_menu Implementation of hook_menu().
sharedemail_perm Implementation of hook_perm().
sharedemail_simpletest Implementation of hook_simpletest().
sharedemail_user Implementation of hook_user().