email_verify.module in Email Verify 8.2
Same filename and directory in other branches
Verifies thoroughly that email addresses are correctly entered.
File
email_verify.moduleView source
<?php
/**
* @file
* Verifies thoroughly that email addresses are correctly entered.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Component\Utility\Unicode;
/**
* Implements hook_help().
*/
function email_verify_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.email_verify':
return '<p>' . t('This module verifies that email addresses are valid during account registration or edit.') . '</p>';
}
}
/**
* Implements hook_menu().
*/
// function email_verify_menu() {
// $items['admin/config/system/email_verify'] = array(
// 'title' => 'Email Verify',
// 'page callback' => 'drupal_get_form',
// 'page arguments' => array('email_verify_admin_settings'),
// 'access arguments' => array('administer site configuration'),
// 'description' => "Configure the Email Verify module's administrative settings.",
// 'file' => 'email_verify.admin.inc',
// );
// return $items;
// }
//
/**
* Access callback for the page at admin/people/email_verify.
*/
// function email_verify_access_people_email_verify() {
// if (\Drupal::config('email_verify.settings')->get('active') && \Drupal::currentUser()->hasPermission('administer users')) {
// return TRUE;
// }
// return FALSE;
// }
/**
* Implements hook_form_alter().
*/
function email_verify_form_alter(&$form, $form_state, $form_id) {
if (\Drupal::config('email_verify.settings')
->get('active')) {
$form['#validate'][] = 'email_verify_form_validate';
}
}
/**
* Additional validation for forms.
*
* @param array $form
* The form definition.
* @param array $form_state
* The form values which you may perform validation on.
*/
function email_verify_form_validate($form, &$form_state) {
if (!\Drupal::currentUser()
->hasPermission('bypass email verification') && $form_state
->getValue('op')
->getUntranslatedString() != 'Cancel account') {
$email = $form_state
->getValue('mail');
$host = Unicode::substr(strstr($email, '@'), 1);
$manager = \Drupal::getContainer()
->get('email_verify.manager');
$manager
->checkHost($host);
// Only check full emails if the host can connect out on port 25.
if (\Drupal::config('email_verify.settings')
->get('active')) {
$manager
->checkEmail($email);
}
if ($errors = $manager
->getErrors()) {
foreach ($errors as $error) {
$form_state
->setErrorByName('mail', $error);
}
}
}
}
Functions
Name![]() |
Description |
---|---|
email_verify_form_alter | Implements hook_form_alter(). |
email_verify_form_validate | Additional validation for forms. |
email_verify_help | Implements hook_help(). |