pictcode / app / Model / User.php @ 001918d1
履歴 | 表示 | アノテート | ダウンロード (3.328 KB)
| 1 | d6c3d8de | root | <?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 | 8b8631af | hasse | 'message' => 'この項目は入力必須です'  | 
      
| 24 | d6c3d8de | root | ),  | 
      
| 25 | 04e657a7 | root | 'email' => array(  | 
      
| 26 | 8b8631af | hasse |                 array(
 | 
      
| 27 | 'rule' => array('notBlank'),  | 
      ||
| 28 | 'message' => 'メールアドレスを入力してください'  | 
      ||
| 29 | ),  | 
      ||
| 30 | 04e657a7 | root |             // メールアドレスであること。
 | 
      
| 31 | 8b8631af | hasse | 'isEmail' => array(  | 
      
| 32 | 'rule' => 'Email',  | 
      ||
| 33 | 'message' => '正しいメールアドレスを入力してください'  | 
      ||
| 34 | ),  | 
      ||
| 35 |             array(
 | 
      ||
| 36 | 'rule' => 'DuplicateEmailCheck',  | 
      ||
| 37 | 'message' => 'このメールアドレスは既に登録されています'  | 
      ||
| 38 | ),  | 
      ||
| 39 | 04e657a7 | root |             // 一意性チェック
 | 
      
| 40 |             // 'emailExists' => array( 'rule' => 'isUnique', 'message' => '既に登録されています'),
 | 
      ||
| 41 | ),  | 
      ||
| 42 | 'password' => array(  | 
      ||
| 43 | 8b8631af | hasse |             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 | 04e657a7 | root | ),  | 
      
| 62 | d6c3d8de | root | '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 | 8b8631af | hasse | 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 | 04e657a7 | root | |
| 88 | 8b8631af | hasse | public function passwordConfirm($check){  | 
      
| 89 |         //2つのパスワードフィールドが一致する事を確認する
 | 
      ||
| 90 | if($this->data['User']['password'] === $this->data['User']['password_confirm']){  | 
      ||
| 91 | 04e657a7 | root | return true;  | 
      
| 92 | 8b8631af | hasse |         }else{
 | 
      
| 93 | return false;  | 
      ||
| 94 | 04e657a7 | root | }  | 
      
| 95 | 8b8631af | hasse | |
| 96 | 04e657a7 | root | }  | 
      
| 97 | |||
| 98 | 8b8631af | hasse | |
| 99 | 04e657a7 | root | public function getActivationHash() {  | 
      
| 100 |             // ユーザIDの有無確認
 | 
      ||
| 101 | if (!isset($this->id)) {  | 
      ||
| 102 | return false;  | 
      ||
| 103 | }  | 
      ||
| 104 |             // 更新日時をハッシュ化
 | 
      ||
| 105 | return Security::hash( $this->field('updated'), 'md5', true);  | 
      ||
| 106 | }  | 
      ||
| 107 | |||
| 108 | |||
| 109 | d6c3d8de | root | public function beforeSave($options = array()) {  | 
      
| 110 | if (isset($this->data[$this->alias]['password'])) {  | 
      ||
| 111 | $passwordHasher = new BlowfishPasswordHasher();  | 
      ||
| 112 | $this->data[$this->alias]['password'] = $passwordHasher->hash(  | 
      ||
| 113 | $this->data[$this->alias]['password']  | 
      ||
| 114 | );  | 
      ||
| 115 | }  | 
      ||
| 116 | return true;  | 
      ||
| 117 | }  | 
      ||
| 118 | |||
| 119 | |||
| 120 | }  |