/** * @brief auto hash passwords when other plugins use the model with a different alias * * Auth does not auto has the pw field when the alias is not User, so we * have to do it here so that it seems auto for other plugins. * * @param array $options see parent::beforeValidate * @return parent::beforeValidate */ public function beforeValidate($options) { if (!empty($this->data[$this->alias]['confirm_password'])) { $this->data[$this->alias]['password'] = Security::hash($this->data[$this->alias]['password'], null, true); } return parent::beforeValidate($options); }
/** * Called during validation operations, before validation. Please note that custom * validation rules can be defined in $validate. * * @param array $options Options passed from Model::save(). * @return bool True if validate operation should continue, false to abort * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforevalidate * @see Model::save() */ public function beforeValidate($options = array()) { $this->validate = Hash::merge($this->validate, array('username' => array('notBlank' => array('rule' => array('notBlank'), 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('users', 'username')), 'required' => true), 'regex' => array('rule' => array('custom', '/[\\w]+/'), 'message' => sprintf(__d('net_commons', 'Only alphabets and numbers are allowed to use for %s.'), __d('users', 'username')), 'allowEmpty' => false, 'required' => true)), 'role_key' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'))))); if (isset($this->data['User']['password']) && $this->data['User']['password'] !== '' || !isset($this->data['User']['id'])) { $this->validate = Hash::merge($this->validate, array('password' => array('notBlank' => array('rule' => array('notBlank'), 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('users', 'password')), 'required' => true), 'regex' => array('rule' => array('custom', '/[\\w]+/'), 'message' => sprintf(__d('net_commons', 'Only alphabets and numbers are allowed to use for %s.'), __d('users', 'password')), 'allowEmpty' => false, 'required' => true)), 'password_again' => array('equalToField' => array('rule' => array('equalToField', 'password'), 'message' => 'Password does not match. Please try again.', 'allowEmpty' => false, 'required' => true)))); } return parent::beforeValidate($options); }
/** * Called during validation operations, before validation. Please note that custom * validation rules can be defined in $validate. * * @param array $options Options passed from Model::save(). * @return bool True if validate operation should continue, false to abort * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforevalidate * @see Model::save() */ public function beforeValidate($options = array()) { $this->validate = Hash::merge($this->validate, array('language_id' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.'), 'required' => true)), 'user_attribute_id' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.'), 'required' => true, 'on' => 'update')), 'name' => array('notBlank' => array('rule' => array('notBlank'), 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('user_attributes', 'Item choice name')), 'required' => true)), 'key' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'required' => true, 'on' => 'update')), 'weight' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.'))))); return parent::beforeValidate($options); }
/** * Called during validation operations, before validation. Please note that custom * validation rules can be defined in $validate. * * @param array $options Options passed from Model::save(). * @return bool True if validate operation should continue, false to abort * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforevalidate * @see Model::save() */ public function beforeValidate($options = array()) { $this->validate = Hash::merge($this->validate, array('user_id' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false, 'required' => false, 'on' => 'update')), 'language_id' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false, 'required' => false)))); return parent::beforeValidate($options); }
/** * バリデーションのセット * * - ログインIDとパスワードのバリデーションルールをセットする。<br> * その他のUserモデルのバリデーションルールのセットは、 * [Users.SaveUserBehavior::beforeValidate](../../Users/classes/SaveUserBehavior.html#method_beforeValidate) * で行う。<br> * また、UsersLanguageのバリデーションも実施する。 * * - 自動登録のバリデーションの初期値のセットは、 * [Auth.AutoUserRegist::validateRequest](../../Users/classes/SaveUserBehavior.html#method_validateRequest) * で行う。 * * @param array $options Model::save()のオプション * @return bool * @link http://book.cakephp.org/2.0/ja/models/callback-methods.html#beforevalidate * @see Model::save() */ public function beforeValidate($options = array()) { $this->loadModels(['UsersLanguage' => 'Users.UsersLanguage']); //ログインID $this->__setUsernameValidate(); //パスワード $this->__setPasswordValidate($options); //ログイン、パスワード以外のUserモデルのバリデーションルールのセットは、ビヘイビアで行う //(ログインとパスワードは、インストール時に使用するため) //UsersLanguageのバリデーション実行 if (isset($this->data['UsersLanguage'])) { $usersLanguage = $this->data['UsersLanguage']; if (!$this->UsersLanguage->validateMany($usersLanguage)) { $this->validationErrors = Hash::merge($this->validationErrors, $this->UsersLanguage->validationErrors); return false; } } return parent::beforeValidate($options); }
/** * Called during validation operations, before validation. Please note that custom * validation rules can be defined in $validate. * * @param array $options Options passed from Model::save(). * @return bool True if validate operation should continue, false to abort * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforevalidate * @see Model::save() */ public function beforeValidate($options = array()) { $this->validate = Hash::merge($this->validate, array('user_id' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.'))), 'select_count' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.'), 'required' => false)), 'created_user' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.'))))); return parent::beforeValidate($options); }