pictcode / app / Model / User.php @ 304d523f
履歴 | 表示 | アノテート | ダウンロード (8.083 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 |
array(
|
| 23 |
'rule' => array('notBlank'), |
| 24 |
'message' => 'この項目は入力必須です' |
| 25 |
), |
| 26 |
array(
|
| 27 |
'rule' => 'isUnique', |
| 28 |
'message' => '既に登録されています' |
| 29 |
), |
| 30 |
array(
|
| 31 |
'rule' => array('minLength', 3), |
| 32 |
'message' => 'パスワードは3文字以上入力してください', |
| 33 |
), |
| 34 |
), |
| 35 |
'email' => array( |
| 36 |
array(
|
| 37 |
'rule' => array('notBlank'), |
| 38 |
'message' => 'メールアドレスを入力してください' |
| 39 |
), |
| 40 |
// メールアドレスであること。
|
| 41 |
'isEmail' => array( |
| 42 |
'rule' => 'Email', |
| 43 |
'message' => '正しいメールアドレスを入力してください' |
| 44 |
), |
| 45 |
array(
|
| 46 |
'rule' => 'DuplicateEmailCheck', |
| 47 |
'message' => 'このメールアドレスは既に登録されています' |
| 48 |
), |
| 49 |
// 一意性チェック
|
| 50 |
// 'emailExists' => array( 'rule' => 'isUnique', 'message' => '既に登録されています'),
|
| 51 |
), |
| 52 |
'email_confirm' => array( |
| 53 |
array(
|
| 54 |
'rule' => array('notBlank'), |
| 55 |
'message' => 'メールアドレス(確認)を入力してください' |
| 56 |
), |
| 57 |
array(
|
| 58 |
'rule' => 'emailConfirm', |
| 59 |
'message' => 'メールアドレスが一致していません' |
| 60 |
), |
| 61 |
|
| 62 |
), |
| 63 |
|
| 64 |
'password' => array( |
| 65 |
array(
|
| 66 |
'rule' => array('notBlank'), |
| 67 |
'message' => 'パスワードを入力してください' |
| 68 |
), |
| 69 |
array(
|
| 70 |
'rule' => array('minLength', 8), |
| 71 |
'message' => 'パスワードは8文字以上入力してください', |
| 72 |
), |
| 73 |
array(
|
| 74 |
'rule' => 'passwordConfirm', |
| 75 |
'message' => 'パスワードが一致していません' |
| 76 |
), |
| 77 |
), |
| 78 |
'password_confirm' => array( |
| 79 |
array(
|
| 80 |
'rule' => array('notBlank'), |
| 81 |
'message' => 'パスワード(確認)を入力してください' |
| 82 |
), |
| 83 |
), |
| 84 |
'status' => array( |
| 85 |
'numeric' => array( |
| 86 |
'rule' => array('numeric'), |
| 87 |
//'message' => 'Your custom message here',
|
| 88 |
//'allowEmpty' => false,
|
| 89 |
//'required' => false,
|
| 90 |
//'last' => false, // Stop validation after this rule
|
| 91 |
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
| 92 |
), |
| 93 |
), |
| 94 |
); |
| 95 |
|
| 96 |
public $reset_pwd_validate = array( |
| 97 |
'email' => array( |
| 98 |
array(
|
| 99 |
'rule' => array('notBlank'), |
| 100 |
'message' => 'メールアドレスを入力してください' |
| 101 |
), |
| 102 |
// メールアドレスであること。
|
| 103 |
'isEmail' => array( |
| 104 |
'rule' => 'Email', |
| 105 |
'message' => '正しいメールアドレスを入力してください' |
| 106 |
), |
| 107 |
array(
|
| 108 |
'rule' => 'emailConfirm', |
| 109 |
'message' => 'メールアドレスが一致していません' |
| 110 |
), |
| 111 |
array(
|
| 112 |
'rule' => 'NotExistEmailCheck', |
| 113 |
'message' => 'このメールアドレスは登録されていません' |
| 114 |
), |
| 115 |
|
| 116 |
), |
| 117 |
'email_confirm' => array( |
| 118 |
array(
|
| 119 |
'rule' => array('notBlank'), |
| 120 |
'message' => 'メールアドレス(確認)を入力してください' |
| 121 |
), |
| 122 |
|
| 123 |
), |
| 124 |
|
| 125 |
'password' => array( |
| 126 |
array(
|
| 127 |
'rule' => array('notBlank'), |
| 128 |
'message' => 'パスワードを入力してください' |
| 129 |
), |
| 130 |
array(
|
| 131 |
'rule' => array('minLength', 8), |
| 132 |
'message' => 'パスワードは8文字以上入力してください', |
| 133 |
), |
| 134 |
array(
|
| 135 |
'rule' => 'passwordConfirm', |
| 136 |
'message' => 'パスワードが一致していません' |
| 137 |
), |
| 138 |
), |
| 139 |
'password_confirm' => array( |
| 140 |
array(
|
| 141 |
'rule' => array('notBlank'), |
| 142 |
'message' => 'パスワード(確認)を入力してください' |
| 143 |
), |
| 144 |
), |
| 145 |
); |
| 146 |
public $new_pwd_validate = array( |
| 147 |
|
| 148 |
'password' => array( |
| 149 |
array(
|
| 150 |
'rule' => array('notBlank'), |
| 151 |
'message' => 'パスワードを入力してください' |
| 152 |
), |
| 153 |
array(
|
| 154 |
'rule' => array('minLength', 8), |
| 155 |
'message' => 'パスワードは8文字以上入力してください', |
| 156 |
), |
| 157 |
array(
|
| 158 |
'rule' => 'passwordConfirm', |
| 159 |
'message' => 'パスワードが一致していません' |
| 160 |
), |
| 161 |
), |
| 162 |
'password_confirm' => array( |
| 163 |
array(
|
| 164 |
'rule' => array('notBlank'), |
| 165 |
'message' => 'パスワード(確認)を入力してください' |
| 166 |
), |
| 167 |
), |
| 168 |
); |
| 169 |
public $reset_pwd_comp_mail_validate = array( |
| 170 |
|
| 171 |
'password' => array( |
| 172 |
array(
|
| 173 |
'rule' => array('notBlank'), |
| 174 |
'message' => 'パスワードを入力してください' |
| 175 |
), |
| 176 |
array(
|
| 177 |
'rule' => array('minLength', 8), |
| 178 |
'message' => 'パスワードは8文字以上入力してください', |
| 179 |
), |
| 180 |
), |
| 181 |
); |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
public function DuplicateEmailCheck(){ |
| 187 |
$query = array('conditions' => array('User.email' => $this->data['User']['email'],'User.status' => 1)); |
| 188 |
$num = $this->find('count',$query); |
| 189 |
if($num > 0){ |
| 190 |
return false; //登録済み |
| 191 |
} else{
|
| 192 |
return true; //未登録 |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
public function passwordConfirm($check){ |
| 197 |
//2つのパスワードフィールドが一致する事を確認する
|
| 198 |
if($this->data['User']['password'] === $this->data['User']['password_confirm']){ |
| 199 |
return true; |
| 200 |
}else{
|
| 201 |
return false; |
| 202 |
} |
| 203 |
|
| 204 |
} |
| 205 |
|
| 206 |
public function emailConfirm($check){ |
| 207 |
//2つのパスワードフィールドが一致する事を確認する
|
| 208 |
if($this->data['User']['email'] === $this->data['User']['email_confirm']){ |
| 209 |
return true; |
| 210 |
}else{
|
| 211 |
return false; |
| 212 |
} |
| 213 |
|
| 214 |
} |
| 215 |
|
| 216 |
public function activationHash() { |
| 217 |
// ユーザIDの有無確認
|
| 218 |
|
| 219 |
if (!isset($this->id)) { |
| 220 |
return false; |
| 221 |
} |
| 222 |
// 更新日時をハッシュ化
|
| 223 |
// return Security::hash( $user_id['User']['updated'], 'md5', true);
|
| 224 |
return Security::hash( $this->field('updated'), 'md5', true); |
| 225 |
} |
| 226 |
public function getActivationHash($id) { |
| 227 |
// ユーザIDの有無確認
|
| 228 |
$query = array('conditions' => array('User.id' => $id)); |
| 229 |
$user_id = $this->find('first',$query); |
| 230 |
if (!isset($user_id['User']['id'])) { |
| 231 |
// if (!isset($this->id)) {
|
| 232 |
return false; |
| 233 |
} |
| 234 |
// 更新日時をハッシュ化
|
| 235 |
return Security::hash( $user_id['User']['updated'], 'md5', true); |
| 236 |
// return Security::hash( $this->field('updated'), 'md5', true);
|
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
//メールアドレスが登録されていない、またはメールアドレスのstatusが1ではない場合、エラーを出す
|
| 241 |
public function NotExistEmailCheck(){ |
| 242 |
$query = array('conditions' => array('User.email' => $this->data['User']['email'],'User.status' => 1)); |
| 243 |
$num = $this->find('count',$query); |
| 244 |
if($num > 0){ |
| 245 |
return true; //未登録 |
| 246 |
} else{
|
| 247 |
return false; //登録済み |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
public function beforeSave($options = array()) { |
| 252 |
if (isset($this->data[$this->alias]['password'])) { |
| 253 |
$passwordHasher = new BlowfishPasswordHasher(); |
| 254 |
$this->data[$this->alias]['password'] = $passwordHasher->hash( |
| 255 |
$this->data[$this->alias]['password'] |
| 256 |
); |
| 257 |
} |
| 258 |
return true; |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
} |