You are here

public static function RouteSubscriber::validateResetPasswordAllowed in Lightweight Directory Access Protocol (LDAP) 8.3

Same name and namespace in other branches
  1. 8.4 ldap_authentication/src/Routing/RouteSubscriber.php \Drupal\ldap_authentication\Routing\RouteSubscriber::validateResetPasswordAllowed()

Checks whether password reset is allowed.

Return value

\Drupal\Core\Access\AccessResultInterface Show password or not.

File

ldap_authentication/src/Routing/RouteSubscriber.php, line 33

Class

RouteSubscriber
Class RouteSubscriber.

Namespace

Drupal\ldap_authentication\Routing

Code

public static function validateResetPasswordAllowed() {
  $user = \Drupal::currentUser();
  if ($user
    ->isAnonymous()) {
    if (\Drupal::config('ldap_authentication.settings')
      ->get('authenticationMode') == LdapAuthenticationConfiguration::MODE_MIXED) {
      return AccessResult::allowed();
    }

    // Hide reset password for anonymous users if LDAP-only authentication and
    // password updates are disabled, otherwise show.
    if (\Drupal::config('ldap_authentication.settings')
      ->get('passwordOption') == LdapAuthenticationConfiguration::$passwordFieldAllow) {
      return AccessResult::allowed();
    }
    else {
      return AccessResult::forbidden();
    }
  }
  else {
    return AccessResult::forbidden();
  }
}