pictcode / app / Model / User.php @ ceb21f43
履歴 | 表示 | アノテート | ダウンロード (2.747 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 |
'email' => array( |
32 |
// メールアドレスであること。
|
33 |
'validEmail' => array( 'rule' => array( 'email', true), 'message' => 'アドレスを入力して下さい'), |
34 |
// 一意性チェック
|
35 |
// 'emailExists' => array( 'rule' => 'isUnique', 'message' => '既に登録されています'),
|
36 |
), |
37 |
'password' => array( |
38 |
// パスワード・確認用パスワードの一致
|
39 |
'match' => array( 'rule' => array( 'confirmPassword', 'password_confirm'), 'message' => '一致しません'), |
40 |
), |
41 |
// 'password' => array(
|
42 |
// 'notBlank' => array(
|
43 |
// 'rule' => array('notBlank'),
|
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 |
'status' => array( |
52 |
'numeric' => array( |
53 |
'rule' => array('numeric'), |
54 |
//'message' => 'Your custom message here',
|
55 |
//'allowEmpty' => false,
|
56 |
//'required' => false,
|
57 |
//'last' => false, // Stop validation after this rule
|
58 |
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
59 |
), |
60 |
), |
61 |
); |
62 |
|
63 |
|
64 |
|
65 |
public function confirmPassword( $field, $password_confirm) { |
66 |
if ($field['password'] === $this->data[$this->name][$password_confirm]) { |
67 |
// パスワードハッシュ化
|
68 |
$this->data[$this->name]['password'] = Security::hash( $plain, 'sha512', true); |
69 |
return true; |
70 |
} |
71 |
} |
72 |
|
73 |
public function getActivationHash() { |
74 |
// ユーザIDの有無確認
|
75 |
if (!isset($this->id)) { |
76 |
return false; |
77 |
} |
78 |
// 更新日時をハッシュ化
|
79 |
return Security::hash( $this->field('updated'), 'md5', true); |
80 |
} |
81 |
|
82 |
|
83 |
public function beforeSave($options = array()) { |
84 |
if (isset($this->data[$this->alias]['password'])) { |
85 |
$passwordHasher = new BlowfishPasswordHasher(); |
86 |
$this->data[$this->alias]['password'] = $passwordHasher->hash( |
87 |
$this->data[$this->alias]['password'] |
88 |
); |
89 |
} |
90 |
return true; |
91 |
} |
92 |
|
93 |
|
94 |
} |