Guest User

Untitled

a guest
Jul 15th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.75 KB | None | 0 0
  1. <?php
  2. App::uses('AppModel', 'Model');
  3. App::uses('AuthComponent', 'Controller/Component');
  4. /**
  5.  * User Model
  6.  *
  7.  * @property Group $Group
  8.  */
  9. class User extends AppModel {
  10.    
  11.     public $name = 'User';
  12.     public $displayField = 'full_name';
  13.  
  14.  
  15.    
  16.     public function beforeSave() {
  17.         if (isset($this->data[$this->alias]['password'])) {
  18.             $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
  19.         }
  20.         return true;       
  21.     }
  22.  
  23.  
  24.  
  25. /**
  26.  * Validation rules
  27.  *
  28.  * @var array
  29.  */
  30.     public $validate = array(
  31.         'username' => array(
  32.             'notempty' => array(
  33.                 'rule' => array('notempty'),
  34.                 'message' => 'A username us required',
  35.                 //'allowEmpty' => false,
  36.                 //'required' => false,
  37.                 //'last' => false, // Stop validation after this rule
  38.                 //'on' => 'create', // Limit validation to 'create' or 'update' operations
  39.             ),
  40.         ),
  41.         'password' => array(
  42.             'notempty' => array(
  43.                 'rule' => array('notempty'),
  44.                 'message' => 'A password is required',
  45.                 //'allowEmpty' => false,
  46.                 //'required' => false,
  47.                 //'last' => false, // Stop validation after this rule
  48.                 //'on' => 'create', // Limit validation to 'create' or 'update' operations
  49.             ),
  50.         ),
  51.         'role' => array(
  52.             'valid' => array(
  53.                 'rule' => array('inList', array('admin', 'editor')),
  54.                 'message' => 'Please enter a valid role',
  55.                 'allowEmpty' => false              
  56.             )
  57.         ),
  58.     );
  59.  
  60.     //The Associations below have been created with all possible keys, those that are not needed can be removed
  61.  
  62. /**
  63.  * belongsTo associations
  64.  *
  65.  * @var array
  66.  */
  67.     public $belongsTo = array(
  68.         'Group' => array(
  69.             'className' => 'Group',
  70.             'foreignKey' => 'group_id',
  71.             'conditions' => '',
  72.             'fields' => '',
  73.             'order' => ''
  74.         )
  75.     ); 
  76.    
  77.    
  78.    
  79. }
Add Comment
Please, Sign In to add comment