function restrict_by_ip_user_profile_validate in Restrict Login or Role Access by IP Address 8.4
Same name and namespace in other branches
- 6.3 restrict_by_ip.module \restrict_by_ip_user_profile_validate()
- 7.3 restrict_by_ip.module \restrict_by_ip_user_profile_validate()
Custom validation function for the user_profile_form page.
1 string reference to 'restrict_by_ip_user_profile_validate'
- restrict_by_ip_form_alter in ./
restrict_by_ip.module - Implements hook_form_alter().
File
- ./
restrict_by_ip.module, line 104 - Restrict logins or roles to whitelisted IP addresses.
Code
function restrict_by_ip_user_profile_validate($form, &$form_state) {
$ip_tools = \Drupal::service('restrict_by_ip.ip_tools');
$ips = $form_state
->getvalue('restrict_by_ip_address');
if (strlen($ips) > 0) {
foreach (explode(';', $ips) as $ip) {
try {
$ip_tools
->validateIP($ip);
} catch (\Drupal\restrict_by_ip\Exception\InvalidIPException $e) {
$form_state
->setErrorByName('restrict_by_ip_address', t($e
->getMessage()));
}
}
}
}