Example #1
0
 /**
  * @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);
 }
Example #2
0
 public function beforeSave($options = array())
 {
     if (!empty($this->data[$this->alias]['password'])) {
         App::uses('AuthComponent', 'Controller/Component');
         $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
     }
     parent::beforeSave($options);
 }
Example #3
0
 /**
  * Constructor
  *
  * @param string $id ID
  * @param string $table Table
  * @param string $ds Datasource
  */
 public function __construct($id = false, $table = null, $ds = null)
 {
     parent::__construct($id, $table, $ds);
     $this->validate = array('email' => array('isValid' => array('rule' => 'email', 'required' => true, 'message' => __d('users', 'Please enter a valid email address.', true)), 'isUnique' => array('rule' => array('isUnique', 'email'), 'message' => __d('users', 'This email is already in use.', true))), 'passwd' => array('to_short' => array('rule' => array('minLength', '4'), 'message' => __d('users', 'The password must have at least 8 characters.', true)), 'required' => array('rule' => 'notEmpty', 'message' => __d('users', 'Please enter a password.', true))), 'temppassword' => array('rule' => 'confirmPassword', 'message' => __d('users', 'The passwords are not equal, please try again.', true)), 'tos' => array('rule' => array('custom', '[1]'), 'message' => __d('users', 'You must agree to the terms of use.', true)));
     $this->validatePasswordChange = array('new_password' => $this->validate['passwd'], 'confirm_password' => array('required' => array('rule' => array('compareFields', 'new_password', 'confirm_password'), 'required' => true, 'message' => __d('users', 'The passwords are not equal.', true))), 'old_password' => array('to_short' => array('rule' => 'validateOldPassword', 'required' => true, 'message' => __d('users', 'Invalid password.', true))));
     $this->Detail->sectionSchema[$this->alias] = array('birthday' => array('type' => 'date', 'null' => null, 'default' => null, 'length' => null));
     $this->Detail->sectionValidation[$this->alias] = array('birthday' => array('validDate' => array('rule' => array('date'), 'allowEmpty' => true, 'message' => __d('users', 'Invalid date', true))));
 }
Example #4
0
 public function __construct($id = false, $table = null, $ds = null)
 {
     if (CakePlugin::loaded('Comments')) {
         $this->actsAs[] = 'Comments.Commentable';
         $this->hasMany['Comment'] = array('className' => 'Comments.Comment', 'foreignKey' => 'foreign_key', 'conditions' => array('Comment.model' => 'UserGroupWallPost'));
     }
     parent::__construct($id, $table, $ds);
 }
Example #5
0
 /**
  * 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);
 }
Example #6
0
 /**
  * Constructor
  *
  * @param string $id ID
  * @param string $table Table
  * @param string $ds Datasource
  */
 public function __construct($id = false, $table = null, $ds = null)
 {
     $userClass = Configure::read('App.UserClass');
     if (empty($userClass)) {
         $userClass = 'Users.User';
     }
     $this->belongsTo['User'] = array('className' => $userClass, 'foreignKey' => 'user_id');
     parent::__construct($id, $table, $ds);
 }
Example #7
0
 /**
  * After find callback
  */
 public function afterFind($results, $primary = false)
 {
     if ($primary) {
         for ($i = 0; $i < count($results); $i++) {
             if ($results[$i][$this->alias]['id'] == __SYSTEM_GUESTS_USER_ROLE_ID) {
                 $results[$i][$this->alias]['session_user_role_id'] = '';
             } else {
                 $results[$i][$this->alias]['session_user_role_id'] = $results[$i][$this->alias]['id'];
             }
         }
     }
     return parent::afterFind($results, $primary);
 }
Example #8
0
 /**
  * Constructor
  *
  * @param string $id ID
  * @param string $table Table
  * @param string $ds Datasource
  */
 public function __construct($id = false, $table = null, $ds = null)
 {
     $this->_setupBehaviors();
     $this->_setupValidation();
     parent::__construct($id, $table, $ds);
 }
Example #9
0
File: User.php Project: ayaou/Zuha
 /**
  * Moves ContactAddress's up to the root so that we can easily add/edit them from User::edit()
  * @todo Should this be in the afterFind? ^JB 
  *
  * @param string $type
  * @param array $query
  * @return mixed
  */
 public function find($type = 'first', $query = array())
 {
     $user = parent::find($type, $query);
     if (isset($user['Contact']['ContactAddress'][0])) {
         $user['ContactAddress'] = $user['Contact']['ContactAddress'];
     }
     return $user;
 }
Example #10
0
 public function __construct($id = false, $table = null, $ds = null)
 {
     parent::__construct($id, $table, $ds);
     $this->validate = array('name' => array('notEmpty' => array('rule' => 'notEmpty', 'message' => __('Please enter a name for this group')), 'isUnique' => array('rule' => 'isUnique', 'message' => __('There is alread a group with this name'))));
 }
Example #11
0
 /**
  * Overriding this method to inject the active section schema
  *
  * @param mixed $field Set to true to reload schema, or a string to return a specific field
  * @return array Array of table metadata
  */
 public function schema($field = false)
 {
     if (isset($this->activeSectionSchema) && !empty($this->sectionSchema[$this->activeSectionSchema])) {
         return $this->sectionSchema[$this->activeSectionSchema];
     }
     return parent::schema($field);
 }
Example #12
0
 /**
  * バリデーションのセット
  *
  * - ログイン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);
 }
Example #13
0
 /**
  * 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);
 }
Example #14
0
File: Used.php Project: ayaou/Zuha
 /**
  * Constructor
  *
  * @return void
  */
 public function __construct($id = false, $table = null, $ds = null)
 {
     parent::__construct($id, $table, $ds);
     $this->validate = array();
 }
Example #15
0
 /**
  * Constructor. Configures the order property.
  *
  * @param bool|int|string|array $id Set this ID for this model on startup,
  * can also be an array of options, see above.
  * @param string $table Name of database table to use.
  * @param string $ds DataSource connection name.
  */
 public function __construct($id = false, $table = null, $ds = null)
 {
     parent::__construct($id, $table, $ds);
     $this->order = $this->alias . '.name ASC';
 }
Example #16
0
 /**
  * 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);
 }
 /**
  * Called before each save operation, after validation. Return a non-true result
  * to halt the save.
  *
  * @param array $options Options passed from Model::save().
  * @return bool True if the operation should continue, false if it should abort
  * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforesave
  * @see Model::save()
  */
 public function beforeSave($options = array())
 {
     if (isset($this->data[$this->alias]['key']) && isset($this->data[$this->alias]['code']) && !$this->data[$this->alias]['code']) {
         $this->data[$this->alias]['code'] = $this->data[$this->alias]['key'];
     }
     return parent::beforeSave($options);
 }
Example #18
0
 /**
  * Constructor
  *
  * @param string $id ID
  * @param string $table Table
  * @param string $ds Datasource
  */
 public function __construct($id = false, $table = null, $ds = null)
 {
     parent::__construct($id, $table, $ds);
     $this->validate = array('username' => array('required' => array('rule' => array('notEmpty'), 'required' => true, 'allowEmpty' => false, 'message' => __d('users', 'Please enter a username', true)), 'alpha' => array('rule' => array('alphaNumeric'), 'message' => __d('users', 'The username must be alphanumeric', true)), 'unique_username' => array('rule' => array('isUnique', 'username'), 'message' => __d('users', 'This username is already in use.', true)), 'username_min' => array('rule' => array('minLength', '3'), 'message' => __d('users', 'The username must have at least 3 characters.', true))), 'email' => array('isValid' => array('rule' => 'email', 'required' => true, 'message' => __d('users', 'Please enter a valid email address.', true)), 'isUnique' => array('rule' => array('isUnique', 'email'), 'message' => __d('users', 'This email is already in use.', true))), 'passwd' => array('to_short' => array('rule' => array('minLength', '6'), 'message' => __d('users', 'The password must have at least 6 characters.', true)), 'required' => array('rule' => 'notEmpty', 'message' => __d('users', 'Please enter a password.', true))), 'temppassword' => array('rule' => 'confirmPassword', 'message' => __d('users', 'The passwords are not equal, please try again.', true)), 'tos' => array('rule' => array('custom', '[1]'), 'message' => __d('users', 'You must agree to the terms of use.', true)));
     $this->validatePasswordChange = array('new_password' => $this->validate['passwd'], 'confirm_password' => array('required' => array('rule' => array('compareFields', 'new_password', 'confirm_password'), 'required' => true, 'message' => __d('users', 'The passwords are not equal.', true))), 'old_password' => array('to_short' => array('rule' => 'validateOldPassword', 'required' => true, 'message' => __d('users', 'Invalid password.', true))));
 }