-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_registration_control.module
100 lines (91 loc) · 4.09 KB
/
user_registration_control.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* This module provides a simple way to provide advanced control over
* what user e-mail domains are allowed for registration.
*
* The development of this module is sponsored by Astonish Design.
*
* @author Brandon Smith <[email protected]>
*/
/**
* Implements hook_help().
* @return help documentation
*/
function user_registration_control_help($path, $arg) {
if ($path == 'admin/help#user_registration_control') {
/**
* @todo Add documentation.
*/
$output = t('<p><strong><em>User Registration Control</em> provides a simple way to implement advanced control
over what user e-mail domains are allowed for registration.</strong></p>
<p>This module functions by applying additional required validation to the e-mail field in the
form of a regular expression. It can be used for a variety of reasons, including (but not limited to)
corporate or academic internet sites, and social media networks.</p>
<p>There are currently two levels of control available:
<ul><li>Basic (single domain restriction)</li><li>Advanced (Custom Regular Expression)</li></ul></p>
<h3>Basic Options</h3>
<p>Basic settings allow registration restriction to users with a valid e-mail address for a specific
domain (or subdomain) suffix. For example, by specifying example.com in the settings, only
visitors with an @example.com e-mail address will be allowed to register. Similarly, if
subdomain.example.com is specified, only visitors with an @subdomain.example.com address can register.</p>
<h3>Advanced Options</h3>
<p>Advanced settings allow complete control over the entire address to be validated using a
custom regular expression (PCRE syntax). By using this option, the administrator has registration
control over both the prefix and suffix, as well as multiple variants, in e-mail address validation.</p>
<h3>Error Message</h3>
<p>An optional setting allows the display of a custom error message in the case of a registration attempt
with an e-mail address that is not allowed.</p>');
return $output;
}
}
/**
* Implements hook_menu().
* @return array $items
*/
function user_registration_control_menu() {
$items = array();
$items['admin/config/people/user_registration_control'] = array(
'title' => 'User Registration Control',
'description' => 'Configure e-mail restriction settings for user registration.',
'page callback' => 'drupal_get_form',
'page arguments' => array('user_registration_control_admin_settings'),
'file' => 'user_registration_control.admin.inc',
'access arguments' => array('administer site configuration'),
'weight' => 0,
);
return $items;
}
/**
* Implements hook_form_user_register_form_alter().
* @param array $form
* @param type $form_state
*/
function user_registration_control_form_user_register_form_alter(&$form, &$form_state) {
$form['#validate'][] = 'user_registration_control_user_register_validate';
}
/**
* Implements hook_user_register_validate().
* @param type $form
* @param type $form_state
*/
function user_registration_control_user_register_validate($form, &$form_state) {
$config_level = variable_get('registration_email_configuration_level');
if ($config_level == 'basic' || $config_level == 'advanced') {
if ($config_level == 'basic') {
$domain = str_replace('.', '\.', variable_get('registration_email_allowed_domain'));
$expression = '/('.$domain.')$/';
} else if ($config_level == 'advanced') {
$expression = variable_get('registration_email_advanced_expression');
}
$valid_email = false;
$submitted_email = $form_state['values']['mail'];
// Check if valid e-mail address.
if (preg_match($expression, $submitted_email)) {
$valid_email = true;
}
// If the email address is not valid, set error message.
if (!$valid_email) {
form_set_error('mail', t('The e-mail address %email is not valid for this site. %message', array('%email' => $form_state['values']['mail'], '%message' => variable_get('registration_email_error_message'))));
}
}
}