<?php
App::uses('AppModel', 'Model');
/**
* User Model
*
* @property Group $Group
*/
class User extends AppModel {
/**
* Display field
*
* @var string
*/
public $displayField = 'name';
public $order = 'User.name ASC';
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'name' => array(
'notBlank' => array(
'rule' => array('notBlank'),
'message' => 'Please enter full name'
)
),
'username' => array(
'notBlank' => array(
'rule' => array('notBlank'),
'message' => 'Please enter email.',
),
'unique' => array(
'rule' => array('isUnique'),
'message' => 'Email is already exists'
),
'email' => array(
'rule' => array('email'),
'message' => 'Please enter valid email id.',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
)
),
'password' => array(
'notBlank' => array(
'rule' => array('notBlank'),
'message' => 'Please enter password.',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'repeat_password' => array(
'notBlank' => array(
'rule' => array('notBlank'),
'message' => 'Please enter repeat password.',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
'on' => 'create', // Limit validation to 'create' or 'update' operations
),
)
);
// The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Group' => array(
'className' => 'Group',
'foreignKey' => 'group_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
public $hasOne = array(
'UserAgent' => array(
'className' => 'UserAgent',
'conditions' => '',
'dependent' => true
)
);
public $hasMany = array(
'Applicant' => array(
'className' => 'Applicant',
'foreignKey' => 'agent_user_id',
'dependent' => false,
'conditions' => array('Applicant.is_deleted' => false),
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Expenditure' => array(
'className' => 'Expenditure',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Notification' => array(
'className' => 'Notification',
'foreignKey' => 'from_user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
/*public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$passwordHasher = new BlowfishPasswordHasher();
$this->data[$this->alias]['password'] = $passwordHasher->hash(
$this->data[$this->alias]['password']
);
}
return true;
}
*/
public function beforeSave($options = array()) {
// hash our password
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
/*
// if we get a new password, hash it
if (isset($this->data[$this->alias]['password_update'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password_update']);
}
*/
// fallback to our parent
return parent::beforeSave($options);
}
}