/** * Construct. * * Adds some validation rules. * @uses MeCms\Model\Validation\AppValidator::__construct() */ public function __construct() { parent::__construct(); //Filename $this->add('filename', ['extension' => ['message' => __d('me_cms', 'Valid extensions: {0}', 'gif, jpg, jpeg, png'), 'rule' => ['extension', ['gif', 'jpg', 'jpeg', 'png']]]])->requirePresence('filename', 'create'); //Album $this->add('album_id', ['naturalNumber' => ['message' => __d('me_cms', 'You have to select a valid option'), 'rule' => 'naturalNumber']])->requirePresence('album_id', 'create'); }
/** * Construct. * * Adds some validation rules. * @uses MeCms\Model\Validation\AppValidator::__construct() */ public function __construct() { parent::__construct(); //Title $this->requirePresence('title', 'create'); //Slug $this->requirePresence('slug', 'create'); }
/** * Construct. * * Adds some validation rules. * @uses MeCms\Model\Validation\AppValidator::__construct() */ public function __construct() { parent::__construct(); //Name $this->add('name', ['blank' => ['message' => __d('me_cms', 'Can not be changed'), 'on' => 'update', 'rule' => 'blank'], 'lengthBetween' => ['message' => __d('me_cms', 'Must be between {0} and {1} chars', 3, 100), 'rule' => ['lengthBetween', 3, 100]], 'unique' => ['message' => __d('me_cms', 'This value is already used'), 'provider' => 'table', 'rule' => 'validateUnique'], 'valid' => ['message' => sprintf('%s: %s', __d('me_cms', 'Allowed chars'), __d('me_cms', 'lowercase letters')), 'rule' => [$this, 'lowercaseLetters']]])->requirePresence('name', 'create'); //Label $this->add('label', ['lengthBetween' => ['message' => __d('me_cms', 'Must be between {0} and {1} chars', 3, 100), 'rule' => ['lengthBetween', 3, 100]], 'unique' => ['message' => __d('me_cms', 'This value is already used'), 'provider' => 'table', 'rule' => 'validateUnique']])->requirePresence('label', 'create'); return $this; }
/** * Construct. * * Adds some validation rules. * @uses MeCms\Model\Validation\AppValidator::__construct() */ public function __construct() { parent::__construct(); //Category $this->add('category_id', ['naturalNumber' => ['message' => __d('me_cms', 'You have to select a valid option'), 'rule' => 'naturalNumber']])->requirePresence('category_id', 'create'); //Title $this->requirePresence('title', 'create'); //Slug $this->requirePresence('slug', 'create'); //Text $this->requirePresence('text', 'create'); }
/** * Construct. * * Adds some validation rules. * @uses MeCms\Model\Validation\AppValidator::__construct() */ public function __construct() { parent::__construct(); //Filename $this->add('filename', ['extension' => ['message' => __d('me_cms', 'Valid extensions: {0}', 'gif, jpg, jpeg, png'), 'rule' => ['extension', ['gif', 'jpg', 'jpeg', 'png']]]])->requirePresence('filename', 'create'); //Position $this->add('position_id', ['naturalNumber' => ['message' => __d('me_cms', 'You have to select a valid option'), 'rule' => 'naturalNumber']])->requirePresence('position_id', 'create'); //Target $this->add('target', ['maxLength' => ['message' => __d('me_cms', 'Must be at most {0} chars', 255), 'rule' => ['maxLength', 255]], 'url' => ['message' => __d('me_cms', 'Must be a valid url'), 'rule' => ['url', true]]])->allowEmpty('target'); //Thumbnail $this->add('thumbnail', ['boolean' => ['message' => __d('me_cms', 'You have to select a valid option'), 'rule' => 'boolean']]); }
/** * Construct. * * Adds some validation rules. * @uses MeCms\Model\Validation\AppValidator::__construct() */ public function __construct() { parent::__construct(); //Category $this->add('category_id', ['naturalNumber' => ['message' => __d('me_cms', 'You have to select a valid option'), 'rule' => 'naturalNumber']])->requirePresence('category_id', 'create'); //User (author) $this->requirePresence('user_id', 'create'); //Title $this->requirePresence('title', 'create'); //Text $this->requirePresence('text', 'create'); //"Is spot" $this->add('is_spot', ['boolean' => ['message' => __d('me_cms', 'You have to select a valid option'), 'rule' => 'boolean']]); }
/** * Construct. * * Adds some validation rules. * @uses MeCms\Model\Validation\AppValidator::__construct() */ public function __construct() { parent::__construct(); //Category $this->add('category_id', ['naturalNumber' => ['message' => __d('me_cms', 'You have to select a valid option'), 'rule' => 'naturalNumber']])->requirePresence('category_id', 'create'); //User (author) $this->requirePresence('user_id', 'create'); //Title $this->requirePresence('title', 'create'); //Slug $this->requirePresence('slug', 'create'); //Text $this->requirePresence('text', 'create'); //Tags $this->add('tags', ['validTagsLength' => ['message' => __d('me_cms', 'Each tag must be between {0} and {1} chars', 3, 20), 'rule' => [$this, 'validTagsLength']], 'validTagsChars' => ['message' => sprintf('%s: %s', __d('me_cms', 'Allowed chars'), __d('me_cms', 'lowercase letters, numbers, dash')), 'rule' => [$this, 'validTagsChars']]])->allowEmpty('tags'); }
/** * Construct. * * Adds some validation rules. * @uses Cake\Auth\DefaultPasswordHasher::check() * @uses Cake\ORM\TableRegistry::get() * @uses MeCms\Model\Validation\AppValidator::__construct() */ public function __construct() { parent::__construct(); //Users group $this->add('group_id', ['naturalNumber' => ['message' => __d('me_cms', 'You have to select a valid option'), 'rule' => 'naturalNumber']])->requirePresence('group_id', 'create'); //Username $this->add('username', ['blank' => ['message' => __d('me_cms', 'Can not be changed'), 'on' => 'update', 'rule' => 'blank'], 'lengthBetween' => ['message' => __d('me_cms', 'Must be between {0} and {1} chars', 4, 40), 'rule' => ['lengthBetween', 4, 40]], 'slug' => ['message' => sprintf('%s: %s', __d('me_cms', 'Allowed chars'), __d('me_cms', 'lowercase letters, numbers, dash')), 'rule' => [$this, 'slug']], 'unique' => ['message' => __d('me_cms', 'This value is already used'), 'provider' => 'table', 'rule' => 'validateUnique'], 'usernameNotReserved' => ['message' => __d('me_cms', 'This value is reserved'), 'rule' => function ($value, $context) { return (bool) (!preg_match('/(admin|manager|root|supervisor|moderator)/i', $value)); }]])->requirePresence('username', 'create'); //Email $this->add('email', ['unique' => ['message' => __d('me_cms', 'This value is already used'), 'provider' => 'table', 'rule' => 'validateUnique']])->requirePresence('email', 'create'); //Email repeat $this->add('email_repeat', ['compareWith' => ['message' => __d('me_cms', 'Email addresses don\'t match'), 'rule' => ['compareWith', 'email']]]); //Password $this->add('password', ['minLength' => ['message' => __d('me_cms', 'Must be at least {0} chars', 8), 'rule' => ['minLength', 8]], 'passwordIsStrong' => ['message' => __d('me_cms', 'The password should contain letters, numbers and symbols'), 'rule' => function ($value, $context) { return (bool) (preg_match('/[a-z]+/i', $value) && preg_match('/[0-9]+/', $value) && preg_match('/[^a-z0-9]+/i', $value)); }]])->requirePresence('password', 'create'); //Password repeat $this->add('password_repeat', ['compareWith' => ['message' => __d('me_cms', 'Passwords don\'t match'), 'rule' => ['compareWith', 'password']]])->requirePresence('password_repeat', 'create'); //Old password $this->add('password_old', ['oldPasswordIsRight' => ['message' => __d('me_cms', 'The old password is wrong'), 'rule' => function ($value, $context) { //Gets the old password $password = TableRegistry::get('Users')->find()->select(['password'])->where(['id' => $context['data']['id']])->first()->toArray()['password']; if (empty($password)) { return false; } //Checks if the password matches return (new \Cake\Auth\DefaultPasswordHasher())->check($value, $password); }]]); //First name $this->requirePresence('first_name', 'create'); //Last name $this->requirePresence('last_name', 'create'); //Banned $this->add('banned', ['boolean' => ['message' => __d('me_cms', 'You have to select a valid option'), 'rule' => 'boolean']])->allowEmpty('banned'); }
/** * Construct. * * Adds some validation rules. * @uses MeCms\Model\Validation\AppValidator::__construct() */ public function __construct() { parent::__construct(); //Tag $this->add('tag', ['lengthBetween' => ['message' => __d('me_cms', 'Must be between {0} and {1} chars', 3, 30), 'rule' => ['lengthBetween', 3, 30]], 'validTag' => ['message' => sprintf('%s: %s', __d('me_cms', 'Allowed chars'), __d('me_cms', 'lowercase letters, numbers, space')), 'rule' => [$this, 'validTag']]]); }
/** * Construct. * * Adds some validation rules. * @uses MeCms\Model\Validation\AppValidator::__construct() */ public function __construct() { parent::__construct(); //Name $this->add('title', ['lengthBetween' => ['message' => __d('me_cms', 'Must be between {0} and {1} chars', 3, 100), 'rule' => ['lengthBetween', 3, 100]], 'slug' => ['message' => sprintf('%s: %s', __d('me_cms', 'Allowed chars'), __d('me_cms', 'lowercase letters, numbers, dash')), 'rule' => [$this, 'slug']], 'unique' => ['message' => __d('me_cms', 'This value is already used'), 'provider' => 'table', 'rule' => 'validateUnique']])->requirePresence('title', 'create'); }