function _cas_user_login_validate in CAS 2.x
Same name and namespace in other branches
- 8 cas.module \_cas_user_login_validate()
Custom validation function added to user login form.
1 string reference to '_cas_user_login_validate'
- cas_form_user_login_form_alter in ./
cas.module - Implements hook_form_FORM_ID_alter().
File
- ./
cas.module, line 248 - Provides CAS authentication for Drupal.
Code
function _cas_user_login_validate(&$form, FormStateInterface $form_state) {
// If the user attempting to log in is a CAS user, prevent log in if
// configured to do so. This forces users to log in using CAS even if
// they somehow know their Drupal account password.
// The UID of the user attempting to log in is set from an earlier validate
// function from the main UserLoginForm.
$uid = $form_state
->get('uid');
$config = Drupal::config('cas.settings');
if ($config
->get('user_accounts.prevent_normal_login') && !empty($uid)) {
$cas_user_manager = \Drupal::service('cas.user_manager');
if ($cas_user_manager
->getCasUsernameForAccount($uid)) {
$form_state
->setErrorByName('name', \Drupal::service('cas.helper')
->getMessage('error_handling.message_prevent_normal_login'));
}
}
}