function domain_registration_user_register_validate in Restrict Domain Registration 7
Same name and namespace in other branches
- 8 domain_registration.module \domain_registration_user_register_validate()
Custom validation function.
Checks if the domain in the email address is on a list of allowed domains.
1 string reference to 'domain_registration_user_register_validate'
- domain_registration_form_user_register_form_alter in ./
domain_registration.module - Implements hook_form_form_id_form_alter().
File
- ./
domain_registration.module, line 100 - Domain Registration module file.
Code
function domain_registration_user_register_validate(&$form, &$form_state) {
// Ignore validation if mail already has an error.
$errors = form_get_errors();
if (!empty($errors['mail'])) {
return;
}
$default_message = t('You are not allowed to register for this site.');
$mail = explode('@', $form_state['values']['mail']);
$domains = variable_get('domain_registration', array());
// Only attempt to validate if we have a list of domains.
if (!empty($domains)) {
$domains = explode("\r\n", $domains);
// Determine if we have matches.
$match = count(array_filter($domains, function ($domain) use (&$mail) {
return domain_registration_wildcard_match($domain, $mail[1]);
}));
switch (variable_get('domain_registration_method', DOMAIN_REGISTRATION_ALLOW)) {
// Allow only domains listed to register.
case 0:
if (!$match) {
form_set_error('account', variable_get('domain_registration_message', $default_message));
}
break;
// Prevent domains listed from registering.
case 1:
if ($match) {
form_set_error('account', variable_get('domain_registration_message', $default_message));
}
break;
}
}
}