pictcode / app / Model / User.php @ 8b8631af
履歴 | 表示 | アノテート | ダウンロード (3.466 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 |
'rule' => array('notBlank'), |
| 23 |
'message' => 'この項目は入力必須です' |
| 24 |
), |
| 25 |
'email' => array( |
| 26 |
array(
|
| 27 |
'rule' => array('notBlank'), |
| 28 |
'message' => 'メールアドレスを入力してください' |
| 29 |
), |
| 30 |
// メールアドレスであること。
|
| 31 |
'isEmail' => array( |
| 32 |
'rule' => 'Email', |
| 33 |
'message' => '正しいメールアドレスを入力してください' |
| 34 |
), |
| 35 |
array(
|
| 36 |
'rule' => 'DuplicateEmailCheck', |
| 37 |
'message' => 'このメールアドレスは既に登録されています' |
| 38 |
), |
| 39 |
// 一意性チェック
|
| 40 |
// 'emailExists' => array( 'rule' => 'isUnique', 'message' => '既に登録されています'),
|
| 41 |
), |
| 42 |
'password' => array( |
| 43 |
array(
|
| 44 |
'rule' => array('notBlank'), |
| 45 |
'message' => 'パスワードを入力してください' |
| 46 |
), |
| 47 |
array(
|
| 48 |
'rule' => array('minLength', 8), |
| 49 |
'message' => 'パスワードは8文字以上入力してください', |
| 50 |
), |
| 51 |
array(
|
| 52 |
'rule' => 'passwordConfirm', |
| 53 |
'message' => 'パスワードが一致していません' |
| 54 |
), |
| 55 |
), |
| 56 |
'password_confirm' => array( |
| 57 |
array(
|
| 58 |
'rule' => array('notBlank'), |
| 59 |
'message' => 'パスワード(確認)を入力してください' |
| 60 |
), |
| 61 |
), |
| 62 |
'status' => array( |
| 63 |
'numeric' => array( |
| 64 |
'rule' => array('numeric'), |
| 65 |
//'message' => 'Your custom message here',
|
| 66 |
//'allowEmpty' => false,
|
| 67 |
//'required' => false,
|
| 68 |
//'last' => false, // Stop validation after this rule
|
| 69 |
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
| 70 |
), |
| 71 |
), |
| 72 |
); |
| 73 |
|
| 74 |
|
| 75 |
public function DuplicateEmailCheck(){ |
| 76 |
$query = array('conditions' => array('User.email' => $this->data['User']['email'],'User.status' => 1)); |
| 77 |
$num = $this->find('count',$query); |
| 78 |
//$this->log($recodes);
|
| 79 |
//var_dump($num);
|
| 80 |
//exit;
|
| 81 |
if($num > 0){ |
| 82 |
return false; //登録済み |
| 83 |
} else{
|
| 84 |
return true; //未登録 |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
public function passwordConfirm($check){ |
| 89 |
//2つのパスワードフィールドが一致する事を確認する
|
| 90 |
if($this->data['User']['password'] === $this->data['User']['password_confirm']){ |
| 91 |
// パスワードハッシュ化
|
| 92 |
$this->data[$this->name]['password'] = Security::hash( $password, 'sha512', true); |
| 93 |
return true; |
| 94 |
}else{
|
| 95 |
return false; |
| 96 |
} |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
public function getActivationHash() { |
| 102 |
// ユーザIDの有無確認
|
| 103 |
if (!isset($this->id)) { |
| 104 |
return false; |
| 105 |
} |
| 106 |
// 更新日時をハッシュ化
|
| 107 |
return Security::hash( $this->field('updated'), 'md5', true); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
public function beforeSave($options = array()) { |
| 112 |
if (isset($this->data[$this->alias]['password'])) { |
| 113 |
$passwordHasher = new BlowfishPasswordHasher(); |
| 114 |
$this->data[$this->alias]['password'] = $passwordHasher->hash( |
| 115 |
$this->data[$this->alias]['password'] |
| 116 |
); |
| 117 |
} |
| 118 |
return true; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
} |