You are here

class PasswordPolicyConstraint in Password Policy 7.2

Class PasswordPolicyConstraint.

This class is to test individual policy constraints.

Hierarchy

Expanded class hierarchy of PasswordPolicyConstraint

1 string reference to 'PasswordPolicyConstraint'
password_policy_ctools_plugin_type in ./password_policy.module
Implements hook_ctools_plugin_type().

File

includes/PasswordPolicyConstraint.inc, line 13
Contains PasswordPolicyConstraint.

View source
class PasswordPolicyConstraint extends PasswordPolicyItem {
  protected $ppType = array(
    'item',
    'constraint',
  );

  /**
   * Constructs PasswordPolicyConstraint object.
   *
   * @param array $info
   *   Ctools plugin info.
   * @param object $policy
   *   Database object as returned by ctools_export_crud_load().
   */
  public function __construct(array $info, &$policy) {
    if (isset($info['default'])) {
      $info['prime value'] = $info['name'];
      $info['config'] = array(
        $info['name'] => $info['default'],
      );
    }
    parent::__construct($info, $policy);
  }

  /**
   * Gets messages for active constraint.
   *
   * @return string[]
   *   Messages.
   */
  public function messages() {
    $mes_temp = is_array($this->info['message']) ? $this->info['message'] : array(
      $this->info['message'],
    );
    $messages = array();
    foreach ($mes_temp as $id => $message) {

      // Only show messages for constraints that have been configured.
      if ($this->config != $this->info['config']) {
        $args = array();
        foreach ($this->config as $key => $value) {
          $args['@' . $key] = $value;
        }
        $messages[$id] = format_string($message, $args);
      }
    }
    return $messages;
  }

  /**
   * Gets messages indicating password failed to meet constraint.
   *
   * @param string $password
   *   Password.
   * @param object $account
   *   Account object.
   *
   * @return string[]
   *   Failure messages.
   */
  public function failMessages($password, $account) {
    return $this
      ->messages();
  }

  /**
   * Checks whether constraint is met.
   *
   * @param string $password
   *   Password.
   * @param object $account
   *   User object.
   *
   * @return bool
   *   TRUE if the constraint is met, FALSE otherwise.
   */
  public function check($password, $account) {
    $func = $this
      ->func('constraint callback');
    if ($func) {
      return $func($password, $account, $this);
    }
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PasswordPolicyConstraint::$ppType protected property Overrides PasswordPolicyItem::$ppType
PasswordPolicyConstraint::check public function Checks whether constraint is met.
PasswordPolicyConstraint::failMessages public function Gets messages indicating password failed to meet constraint.
PasswordPolicyConstraint::messages public function Gets messages for active constraint.
PasswordPolicyConstraint::__construct public function Constructs PasswordPolicyConstraint object. Overrides PasswordPolicyItem::__construct
PasswordPolicyItem::$config public property
PasswordPolicyItem::$info public property
PasswordPolicyItem::$policy public property
PasswordPolicyItem::adminForm public function Form constructor for adminForm().
PasswordPolicyItem::adminFormSubmit public function Form submission handler for adminForm().
PasswordPolicyItem::factory public static function Creates item.
PasswordPolicyItem::func protected function Gets function of item by name.
PasswordPolicyItem::isActive public function Determines whether item is active.
PasswordPolicyItem::isType public function Checks whether item is of a given type.