Validates the username field.

Override it as needed to change the rules for only that field.

@param \Cake\Validation\Validator $validator Validator
@return \Cake\Validation\Validator
436678
public function validationUserName(Validator $validator) {
		$validator->setProvider('userTable', $this->_table);

		$validator->add($this->_field('username'), [
			'notBlank' => [
				'rule' => 'notBlank',
				'message' => __d('user_tools', 'An username is required.')
			],
			'length' => [
				'rule' => ['lengthBetween', 3, 32],
				'message' => __d('user_tools', 'The username must be between 3 and 32 characters.')
			],
			'unique' => [
				'rule' => ['validateUnique', ['scope' => 'username']],
				'provider' => 'userTable',
				'message' => __d('user_tools', 'The username is already in use.')
			],
			'alphaNumeric' => [
				'rule' => 'alphaNumeric',
				'message' => __d('user_tools', 'The username must be alpha numeric.')
			]
		]);

		return $validator;
	}
954009
public function setValidator(Validator $validator) {
        $this->_validator = $validator;

        // Only set model events if we plan on validating
        $this->on('model', $this);

        return $this;
    }
508574
public function validationDefault(Validator $validator)
    {
        return $validator
            ->notEmpty(
                'instance_name',
                __d('wasabi_core', 'Please enter a name for your app.')
            )
            ->notEmpty(
                'instance_short_name',
                __d('wasabi_core', 'Please enter a short name for your app.')
            )
            ->notEmpty(
                'Email__email_sender',
                __d('wasabi_core', 'Please enter an email address.')
            )
            ->notEmpty(
                'Email__email_sender_name',
                __d('wasabi_core', 'Please enter a name for the email sender.')
            )
            ->add('Email__email_sender', 'validEmail', [
                'rule' => 'email',
                'message' => __d('wasabi_core', 'Please enter a valid email address.')
            ])
            ->notEmpty(
                'Login__HeartBeat__max_login_time',
                __d('wasabi_core', 'Please choose a maximum login time.')
            )
            ->add('Login__HeartBeat__max_login_time', 'valid', [
                'rule' => function ($value, $context) {
                    return in_array((int)$value, [900000, 1800000, 2700000, 3600000, 6400000]);
                },
                'message' => __d('wasabi_core', 'Please choose a valid maximum login time.')
            ])
            ->numeric(
                'Auth__max_login_attempts',
                __d('wasabi_core', 'Please enter a number above 0.')
            )
            ->greaterThan(
                'Auth__max_login_attempts',
                0,
                __d('wasabi_core', 'Please enter a number above 0.')
            )
            ->notEmpty(
                'User__has_username',
                __d('wasabi_core', 'Please choose if users have a username.')
            )
            ->notEmpty(
                'User__has_firstname_lastname',
                __d('wasabi_core', 'Please choose if users have a firstname and lastname.')
            )
            ->notEmpty(
                'User__allow_timezone_change',
                __d('wasabi_core', 'Please choose if users may change his timezone.')
            )
            ->notEmpty(
                'User__belongs_to_many_groups',
                __d('wasabi_core', 'Please choose if users may belong to multiple groups.')
            );
    }
1349258
public function validationStrictPassword(Validator $validator): Validator
    {
        $validator
            ->add('password', [
                'minLength' => [
                    'rule' => ['minLength', $this->getConfig('minPasswordLength')],
                    'last' => true,
                    'message' => __d('ck_tools', 'validation.user.password_min_length'),
                ],
            ])
            ->add('password', 'passwordFormat', [
                'rule' => function ($value, $context) {
                    return $this->validFormat($value, $context);
                },
                'message' => __d('ck_tools', 'validation.user.password_invalid_format'),
            ])
            ->add('password', 'passwordNoUserName', [
                'rule' => function ($value, $context) {
                    return $this->checkForUserName($value, $context);
                },
                'message' => __d('ck_tools', 'validation.user.password_user_name_not_allowed'),
            ])
            ->add('password', 'passwordUsedBefore', [
                'rule' => function ($value, $context) {
                    return $this->checkLastPasswords($value, $context);
                },
                'message' => __d('ck_tools', 'validation.user.password_used_before'),
            ]);

        return $validator;
    }
461643
public function validationConfirmPassword(Validator $validator) {
		$validator->setProvider('userBehavior', $this);

		$validator->add($this->_field('passwordCheck'), [
			'notBlank' => [
				'rule' => 'notBlank',
				'message' => __d('user_tools', 'A password is required.')
			],
			'minLength' => [
				'rule' => ['minLength', $this->_config['passwordMinLength']],
				'message' => __d('user_tools', 'The password must have at least 6 characters.')
			],
			'confirmPassword' => [
				'rule' => ['compareFields', 'password'],
				'message' => __d('user_tools', 'The passwords don\'t match!'),
				'provider' => 'userBehavior',
			]
		]);

		return $validator;
	}
1042024
protected function _buildValidator(Validator $validator)
    {
        $validator = new AppValidator;

        //First name
        $validator->requirePresence('first_name');

        //Last name
        $validator->requirePresence('last_name');

        //Email
        $validator->requirePresence('email');

        //Message
        $validator->add('message', [
            'lengthBetween' => [
                'message' => __d('me_cms', 'Must be between {0} and {1} chars', 10, 1000),
                'rule' => ['lengthBetween', 10, 1000],
            ],
        ])->requirePresence('message');

        return $validator;
    }
700626
protected function failedValidation(Validator $validator)
    {
        throw (new ValidationException($validator))
                    ->errorBag($this->errorBag)
                    ->redirectTo($this->getRedirectUrl());
    }
221024
public function setValidator($validator)
    {
        $this->callBeforeListeners('setValidator', [$validator]);
        $this->validator = $validator;
        $this->callAfterListeners('setValidator', [$validator]);
    }
170271
public function validate($validator)
    {
        // get the previous values (could contain comma-delimited list)

        $previous = $value = $this->Value();

        if (is_string($value) && strstr($value, ",")) {
            $value = explode(",", $value);
        }

        // set the value as an array for parent validation

        $this->setValue($value);

        $validated = parent::validate($validator);

        // restore previous value after validation

        $this->setValue($previous);

        return $validated;
    }
1368747
protected function _addValidatorProps($validator = [])
    {
        foreach ($validator as $key => $value) {
            if (!isset($value) || empty($value)) {
                continue;
            }
            if ($key === 'rule' && is_array($value) && !is_callable($value)) {
                $this->_pass = array_slice($value, 1);
                $value = array_shift($value);
            }
            if (in_array($key, ['rule', 'on', 'message', 'last', 'provider', 'pass'])) {
                $this->{"_$key"} = $value;
            }
        }
    }
117004
public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

        $validator
            ->requirePresence('label', 'create')
            ->notEmpty('label');

        $validator
            ->allowEmpty('url');

        $validator
            ->boolean('new_window')
            ->allowEmpty('new_window');

        $validator
            ->requirePresence('menu_id', 'create')
            ->notEmpty('menu_id');

        $validator
            ->allowEmpty('icon');

        $validator
            ->requirePresence('type', 'create')
            ->notEmpty('type');

        return $validator;
    }
598383
public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

        $validator
            ->requirePresence('filename', 'create')
            ->notEmpty('filename');

        $validator
            ->requirePresence('status', 'create')
            ->notEmpty('status');

        $validator
            ->requirePresence('model_name', 'create')
            ->notEmpty('model_name');

        $validator
            ->requirePresence('attempts', 'create')
            ->notEmpty('attempts');

        $validator
            ->dateTime('trashed')
            ->allowEmpty('trashed');

        $validator
            ->uuid('created_by')
            ->notEmpty('created_by');

        $validator
            ->uuid('modified_by')
            ->notEmpty('modified_by');

        return $validator;
    }
1309498
public function setValidator(Validator $validator)
    {
        if ($validator) {
            $this->validator = $validator;
            $this->validator->setForm($this);
        }
        return $this;
    }
1249350
public function validationDefault(Validator $validator)
    {
        $validator
            ->allowEmpty('id', 'create')
            ->requirePresence('filepath', 'create')
            ->notEmpty('filepath')
            ->requirePresence('filename', 'create')
            ->notEmpty('filename')
            ->requirePresence('filetype', 'create')
            ->notEmpty('filetype')
            ->add('filesize', 'valid', ['rule' => 'numeric'])
            ->requirePresence('filesize', 'create')
            ->notEmpty('filesize')
            ->requirePresence('model', 'create')
            ->notEmpty('model')
            ->requirePresence('foreign_key', 'create')
            ->notEmpty('foreign_key');

        return $validator;
    }
792014
public function validationDefault(Validator $validator) : Validator
    {
        // configurable in config/csv_migrations.php
        if (! Configure::read('CsvMigrations.tableValidation')) {
            return $validator;
        }

        return $this->validationEnabled($validator);
    }
1340806
public function addValidator(Validator\ValidatorInterface $validator) {
        $this->validators[get_class($validator)] = $validator;
        
        return $this;
    }
607967
public function validate($validator)
    {
        // Baily Early (if tags are used):
        
        if ($this->usesTags()) {
            return true;
        }
        
        // Call Parent Method (if not multiple):
        
        if (!$this->isMultiple()) {
            return parent::validate($validator);
        }
        
        // Obtain User Values:
        
        $values = $this->getValueArray();
        
        // Detect Invalid Values:
        
        $invalid = array_filter(
            $values,
            function ($userValue) {
                foreach ($this->getValidValues() as $formValue) {
                    if ($this->isSelectedValue($formValue, $userValue)) {
                        return false;
                    }
                }
                return true;
            }
        );
        
        // Answer Success (if none invalid):
        
        if (empty($invalid)) {
            return true;
        }
        
        // Define Validation Error:
        
        $validator->validationError(
            $this->getName(),
            _t(
                __CLASS__ . '.INVALIDOPTIONS',
                'Please select values within the list provided. Invalid option(s) {values} given.',
                [
                    'values' => implode(', ', $invalid)
                ]
            ),
            'validation'
        );
        
        // Answer Failure (invalid values detected):
        
        return false;
    }