pictcode / app / Model / User.php @ 995bd018
履歴 | 表示 | アノテート | ダウンロード (1.579 KB)
1 |
<?php
|
---|---|
2 |
App::uses('AppModel', 'Model'); |
3 |
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth'); |
4 |
|
5 |
|
6 |
/**
|
7 |
* User Model
|
8 |
*
|
9 |
* @property Login $Login
|
10 |
* @property Program $Program
|
11 |
*/
|
12 |
class User extends AppModel { |
13 |
|
14 |
|
15 |
/**
|
16 |
* Validation rules
|
17 |
*
|
18 |
* @var array
|
19 |
*/
|
20 |
public $validate = array( |
21 |
'login_id' => array( |
22 |
'notBlank' => array( |
23 |
'rule' => array('notBlank'), |
24 |
//'message' => 'Your custom message here',
|
25 |
//'allowEmpty' => false,
|
26 |
//'required' => false,
|
27 |
//'last' => false, // Stop validation after this rule
|
28 |
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
29 |
), |
30 |
), |
31 |
'password' => array( |
32 |
'notBlank' => array( |
33 |
'rule' => array('notBlank'), |
34 |
//'message' => 'Your custom message here',
|
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 |
'status' => array( |
42 |
'numeric' => array( |
43 |
'rule' => array('numeric'), |
44 |
//'message' => 'Your custom message here',
|
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 |
); |
52 |
|
53 |
|
54 |
public function beforeSave($options = array()) { |
55 |
if (isset($this->data[$this->alias]['password'])) { |
56 |
$passwordHasher = new BlowfishPasswordHasher(); |
57 |
$this->data[$this->alias]['password'] = $passwordHasher->hash( |
58 |
$this->data[$this->alias]['password'] |
59 |
); |
60 |
} |
61 |
return true; |
62 |
} |
63 |
|
64 |
|
65 |
} |