public function MoAuthLoginSettings::submitForm in Google Authenticator / 2 Factor Authentication - 2FA 8
Same name and namespace in other branches
- 8.2 src/Form/MoAuthLoginSettings.php \Drupal\miniorange_2fa\Form\MoAuthLoginSettings::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ MoAuthLoginSettings.php, line 145 - Contains support form for miniOrange 2FA Login Module.
Class
Namespace
Drupal\miniorange_2fa\FormCode
public function submitForm(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
$two_factor = $form['mo_auth_enable_two_factor']['#value'];
$inline_registration = $form['mo_auth_enforce_inline_registration']['#value'];
$use_only_2nd_factor = $form['mo_auth_two_factor_instead_password']['#value'];
$mo_enable_whitelist_IPs = $form['mo_auth_two_factor_invoke_2fa_depending_upon_IP']['#value'];
$mo_whitelist_IPs = preg_replace('/\\s+/', '', $form['mo_auth_two_factor_whitelist_IP']['#value']);
MoAuthUtilities::check_for_valid_IPs($mo_whitelist_IPs);
$mo_enable_role_based_2fa = $form['mo_auth_two_factor_enable_role_based_2fa']['#value'];
$roles_arr = MoAuthUtilities::get_Existing_Drupal_Roles();
$mo_role_based_2fa_roles = array();
foreach ($roles_arr as $sysName => $displayName) {
if ($form['mo_auth_two_factor_role_based_2fa_roles_' . strtolower($sysName)]['#value'] == 1) {
$mo_role_based_2fa_roles[$sysName] = $form['mo_auth_two_factor_role_based_2fa_roles_' . strtolower($sysName)]['#value'];
}
}
$mo_role_based_2fa_roles_value = !empty($mo_role_based_2fa_roles) ? json_encode($mo_role_based_2fa_roles) : '';
$enforce_only_2nd_factor = $use_only_2nd_factor == 1 ? TRUE : FALSE;
$enable2Factor = $two_factor == 1 ? TRUE : FALSE;
$enforceInlineRegistration = $inline_registration == 1 || $enforce_only_2nd_factor ? TRUE : FALSE;
$mo_enable_whitelist_IPs_value = $mo_enable_whitelist_IPs == 1 && !empty(is_null($mo_whitelist_IPs) || !empty($mo_whitelist_IPs)) ? TRUE : FALSE;
$mo_enable_role_based_2fa_value = $mo_enable_role_based_2fa == 1 && !empty($mo_role_based_2fa_roles) ? TRUE : FALSE;
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->set('mo_auth_use_only_2nd_factor', $enforce_only_2nd_factor)
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->set('mo_auth_enable_two_factor', $enable2Factor)
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->set('mo_auth_enforce_inline_registration', $enforceInlineRegistration)
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->set('mo_auth_enable_whitelist_IPs', $mo_enable_whitelist_IPs_value)
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->set('mo_auth_whitelisted_IP_address', $mo_whitelist_IPs)
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->set('mo_auth_enable_role_based_2fa', $mo_enable_role_based_2fa_value)
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->set('mo_auth_role_based_2fa_roles', $mo_role_based_2fa_roles_value)
->save();
drupal_flush_all_caches();
\Drupal::messenger()
->addMessage(t("Login settings updated."), 'status');
}